42 #define DEFAULT_SLICE_MB_WIDTH 8
56 static const int bitrate_table[] = { 1000, 2100, 3500, 5400, 7000, 10000};
67 4, 7, 9, 11, 13, 14, 15, 63,
68 7, 7, 11, 12, 14, 15, 63, 63,
69 9, 11, 13, 14, 15, 63, 63, 63,
70 11, 11, 13, 14, 63, 63, 63, 63,
71 11, 13, 14, 63, 63, 63, 63, 63,
72 13, 14, 63, 63, 63, 63, 63, 63,
73 13, 63, 63, 63, 63, 63, 63, 63,
74 63, 63, 63, 63, 63, 63, 63, 63
76 4, 5, 6, 7, 9, 11, 13, 15,
77 5, 5, 7, 8, 11, 13, 15, 17,
78 6, 7, 9, 11, 13, 15, 15, 17,
79 7, 7, 9, 11, 13, 15, 17, 19,
80 7, 9, 11, 13, 14, 16, 19, 23,
81 9, 11, 13, 14, 16, 19, 23, 29,
82 9, 11, 13, 15, 17, 21, 28, 35,
83 11, 13, 16, 17, 21, 28, 35, 41
85 4, 4, 5, 5, 6, 7, 7, 9,
86 4, 4, 5, 6, 7, 7, 9, 9,
87 5, 5, 6, 7, 7, 9, 9, 10,
88 5, 5, 6, 7, 7, 9, 9, 10,
89 5, 6, 7, 7, 8, 9, 10, 12,
90 6, 7, 7, 8, 9, 10, 12, 15,
91 6, 7, 7, 9, 10, 11, 14, 17,
92 7, 7, 9, 10, 11, 14, 17, 21
94 4, 4, 4, 4, 4, 4, 4, 4,
95 4, 4, 4, 4, 4, 4, 4, 4,
96 4, 4, 4, 4, 4, 4, 4, 4,
97 4, 4, 4, 4, 4, 4, 4, 5,
98 4, 4, 4, 4, 4, 4, 5, 5,
99 4, 4, 4, 4, 4, 5, 5, 6,
100 4, 4, 4, 4, 5, 5, 6, 7,
101 4, 4, 4, 4, 5, 6, 7, 7
103 4, 4, 4, 4, 4, 4, 4, 4,
104 4, 4, 4, 4, 4, 4, 4, 4,
105 4, 4, 4, 4, 4, 4, 4, 4,
106 4, 4, 4, 4, 4, 4, 4, 5,
107 4, 4, 4, 4, 4, 4, 5, 5,
108 4, 4, 4, 4, 4, 5, 5, 6,
109 4, 4, 4, 4, 5, 5, 6, 7,
110 4, 4, 4, 4, 5, 6, 7, 7
112 2, 2, 2, 2, 2, 2, 2, 2,
113 2, 2, 2, 2, 2, 2, 2, 2,
114 2, 2, 2, 2, 2, 2, 2, 2,
115 2, 2, 2, 2, 2, 2, 2, 3,
116 2, 2, 2, 2, 2, 2, 3, 3,
117 2, 2, 2, 2, 2, 3, 3, 3,
118 2, 2, 2, 2, 3, 3, 3, 4,
119 2, 2, 2, 2, 3, 3, 4, 4,
125 4, 7, 9, 11, 13, 14, 63, 63,
126 7, 7, 11, 12, 14, 63, 63, 63,
127 9, 11, 13, 14, 63, 63, 63, 63,
128 11, 11, 13, 14, 63, 63, 63, 63,
129 11, 13, 14, 63, 63, 63, 63, 63,
130 13, 14, 63, 63, 63, 63, 63, 63,
131 13, 63, 63, 63, 63, 63, 63, 63,
132 63, 63, 63, 63, 63, 63, 63, 63
134 4, 5, 6, 7, 9, 11, 13, 15,
135 5, 5, 7, 8, 11, 13, 15, 17,
136 6, 7, 9, 11, 13, 15, 15, 17,
137 7, 7, 9, 11, 13, 15, 17, 19,
138 7, 9, 11, 13, 14, 16, 19, 23,
139 9, 11, 13, 14, 16, 19, 23, 29,
140 9, 11, 13, 15, 17, 21, 28, 35,
141 11, 13, 16, 17, 21, 28, 35, 41
143 4, 4, 5, 5, 6, 7, 7, 9,
144 4, 4, 5, 6, 7, 7, 9, 9,
145 5, 5, 6, 7, 7, 9, 9, 10,
146 5, 5, 6, 7, 7, 9, 9, 10,
147 5, 6, 7, 7, 8, 9, 10, 12,
148 6, 7, 7, 8, 9, 10, 12, 15,
149 6, 7, 7, 9, 10, 11, 14, 17,
150 7, 7, 9, 10, 11, 14, 17, 21
152 4, 4, 4, 4, 4, 4, 4, 4,
153 4, 4, 4, 4, 4, 4, 4, 4,
154 4, 4, 4, 4, 4, 4, 4, 4,
155 4, 4, 4, 4, 4, 4, 4, 5,
156 4, 4, 4, 4, 4, 4, 5, 5,
157 4, 4, 4, 4, 4, 5, 5, 6,
158 4, 4, 4, 4, 5, 5, 6, 7,
159 4, 4, 4, 4, 5, 6, 7, 7
161 4, 4, 4, 4, 4, 4, 4, 4,
162 4, 4, 4, 4, 4, 4, 4, 4,
163 4, 4, 4, 4, 4, 4, 4, 4,
164 4, 4, 4, 4, 4, 4, 4, 5,
165 4, 4, 4, 4, 4, 4, 5, 5,
166 4, 4, 4, 4, 4, 5, 5, 6,
167 4, 4, 4, 4, 5, 5, 6, 7,
168 4, 4, 4, 4, 5, 6, 7, 7
170 4, 4, 4, 4, 4, 4, 4, 4,
171 4, 4, 4, 4, 4, 4, 4, 4,
172 4, 4, 4, 4, 4, 4, 4, 4,
173 4, 4, 4, 4, 4, 4, 4, 5,
174 4, 4, 4, 4, 4, 4, 5, 5,
175 4, 4, 4, 4, 4, 5, 5, 6,
176 4, 4, 4, 4, 5, 5, 6, 7,
177 4, 4, 4, 4, 5, 6, 7, 7
190 int qmat_luma[16][64];
191 int qmat_chroma[16][64];
211 const int *array_valid_values,
int default_value)
216 int ref_val = array_valid_values[
i];
217 if (ref_val == INT_MAX)
225 "%s %d are not supported. Set to default value : %d\n",
226 val_name,
val, default_value);
227 return default_value;
232 unsigned int rice_order, exp_order, switch_bits, switch_val;
240 switch_val = switch_bits << rice_order;
242 if (
val >= switch_val) {
243 val -= switch_val - (1 << exp_order);
246 put_bits(pb, exponent - exp_order + switch_bits, 0);
249 exponent =
val >> rice_order;
259 #define GET_SIGN(x) ((x) >> 31)
260 #define MAKE_CODE(x) (((x) * 2) ^ GET_SIGN(x))
263 int blocks_per_slice,
int scale)
268 prev_dc = (blocks[0] - 0x4000) /
scale;
273 for (
i = 1;
i < blocks_per_slice;
i++, blocks += 64) {
274 dc = (blocks[0] - 0x4000) /
scale;
287 int blocks_per_slice,
288 int *qmat,
const uint8_t *scan)
294 int max_coeffs, abs_level;
296 max_coeffs = blocks_per_slice << 6;
298 for (
i = 1;
i < 64;
i++) {
299 for (idx = scan[
i]; idx < max_coeffs; idx += 64) {
300 level = blocks[idx] / qmat[scan[
i]];
308 prev_level =
FFMIN(abs_level, 9);
321 for (
i = 0;
i < 8;
i++) {
343 for (
i = 0;
i < mb_count;
i++) {
352 }
else if (
chroma && is_422){
353 for (
i = 0;
i < mb_count;
i++) {
360 for (
i = 0;
i < mb_count;
i++) {
372 static int encode_slice_plane(int16_t *blocks,
int mb_count, uint8_t *buf,
unsigned buf_size,
int *qmat,
int sub_sample_chroma,
375 int blocks_per_slice;
378 blocks_per_slice = mb_count << (2 - sub_sample_chroma);
381 encode_dcs(&pb, blocks, blocks_per_slice, qmat[0]);
382 encode_acs(&pb, blocks, blocks_per_slice, qmat, scan);
389 int16_t * blocks_y, int16_t * blocks_u, int16_t * blocks_v,
390 unsigned mb_count, uint8_t *buf,
unsigned data_size,
391 unsigned* y_data_size,
unsigned* u_data_size,
unsigned* v_data_size,
397 buf, data_size,
ctx->qmat_luma[qp - 1], 0,
ctx->scantable);
400 *u_data_size =
encode_slice_plane(blocks_u, mb_count, buf + *y_data_size, data_size - *y_data_size,
401 ctx->qmat_chroma[qp - 1],
ctx->is_422,
ctx->scantable);
403 *v_data_size =
encode_slice_plane(blocks_v, mb_count, buf + *y_data_size + *u_data_size,
404 data_size - *y_data_size - *u_data_size,
405 ctx->qmat_chroma[qp - 1],
ctx->is_422,
ctx->scantable);
408 return *y_data_size + *u_data_size + *v_data_size;
413 const int abits = 16;
415 const int dsize = 1 << dbits - 1;
416 int diff = cur - prev;
419 if (
diff >= (1 << abits) - dsize)
421 if (diff < -dsize || diff > dsize || !
diff) {
445 unsigned mb_count, uint8_t *buf,
unsigned data_size,
unsigned* a_data_size)
447 const int abits = 16;
448 const int mask = (1 << abits) - 1;
449 const int num_coeffs = mb_count * 256;
450 int prev =
mask, cur;
453 int16_t * blocks = (int16_t *)src_a;
470 }
while (idx < num_coeffs);
477 "Underestimated required buffer size.\n");
486 unsigned dst_width,
unsigned dst_height,
int is_alpha_plane,
487 int is_interlaced,
int is_top_field)
490 int i, j, src_stride, box_height;
491 uint16_t last_pix, *last_line;
493 if (!is_interlaced) {
495 src += y * src_stride + x;
499 src += y * src_stride + x;
505 for (
i = 0;
i < box_height; ++
i) {
506 for (j = 0; j < box_width; ++j) {
507 if (!is_alpha_plane) {
513 if (!is_alpha_plane) {
514 last_pix =
dst[j - 1];
516 last_pix =
dst[j - 1] << 6;
518 for (; j < dst_width; j++)
523 last_line =
dst - dst_width;
524 for (;
i < dst_height;
i++) {
525 for (j = 0; j < dst_width; ++j) {
526 dst[j] = last_line[j];
534 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
536 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 0, is_interlaced, is_top_field);
542 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
544 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 1, is_interlaced, is_top_field);
548 int mb_y,
unsigned mb_count, uint8_t *buf,
unsigned data_size,
549 int unsafe,
int *qp,
int is_interlaced,
int is_top_field)
551 int luma_stride, chroma_stride, alpha_stride = 0;
553 int hdr_size = 6 + (
ctx->need_alpha * 2);
554 int ret = 0, slice_size;
555 const uint8_t *dest_y, *dest_u, *dest_v;
556 unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0, a_data_size = 0;
559 int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3;
560 int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
572 if (!is_interlaced) {
573 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
574 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
575 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
577 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride * 2 + (mb_x << 5);
578 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
579 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
581 dest_y += luma_stride;
582 dest_u += chroma_stride;
583 dest_v += chroma_stride;
590 (uint16_t *)
ctx->fill_y, mb_count << 4, 16, is_interlaced, is_top_field);
593 (uint16_t *)
ctx->fill_u, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
596 (uint16_t *)
ctx->fill_v, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
604 mb_count, buf + hdr_size, data_size - hdr_size,
605 &y_data_size, &u_data_size, &v_data_size,
608 if (!is_interlaced) {
609 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride, mb_count, 0, 0);
613 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride * 2, mb_count, 0, 0);
614 calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride * 2, mb_count, 1,
ctx->is_422);
615 calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride * 2, mb_count, 1,
ctx->is_422);
619 mb_count, buf + hdr_size, data_size - hdr_size,
620 &y_data_size, &u_data_size, &v_data_size,
627 mb_count, buf + hdr_size, data_size - hdr_size,
628 &y_data_size, &u_data_size, &v_data_size,
631 }
else if (slice_size < low_bytes && *qp
636 mb_count, buf + hdr_size, data_size - hdr_size,
637 &y_data_size, &u_data_size, &v_data_size,
643 buf[0] = hdr_size << 3;
648 if (
ctx->need_alpha) {
653 (uint16_t *)
ctx->fill_a, mb_count << 4, 16, is_interlaced, is_top_field);
655 buf + hdr_size + slice_size,
656 data_size - hdr_size - slice_size, &a_data_size);
662 return hdr_size + y_data_size + u_data_size + v_data_size + a_data_size;
666 uint8_t *buf,
const int buf_size,
const int picture_index,
const int is_top_field)
669 int mb_width = (avctx->
width + 15) >> 4;
670 int hdr_size, sl_size,
i;
671 int mb_y, sl_data_size, qp, mb_height, picture_height, unsafe_mb_height_limit;
672 int unsafe_bot, unsafe_right;
673 uint8_t *sl_data, *sl_data_sizes;
674 int slice_per_line = 0, rem = mb_width;
676 if (!
ctx->is_interlaced) {
677 mb_height = (avctx->
height + 15) >> 4;
678 unsafe_mb_height_limit = mb_height;
681 picture_height = (avctx->
height + 1) / 2;
683 picture_height = avctx->
height / 2;
685 mb_height = (picture_height + 15) >> 4;
686 unsafe_mb_height_limit = mb_height;
690 slice_per_line += rem >>
i;
695 hdr_size = 8; sl_data_size = buf_size - hdr_size;
696 sl_data_sizes = buf + hdr_size;
697 sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
698 for (mb_y = 0; mb_y < mb_height; mb_y++) {
701 while (mb_x < mb_width) {
702 while (mb_width - mb_x < slice_mb_count)
703 slice_mb_count >>= 1;
705 unsafe_bot = (avctx->
height & 0xf) && (mb_y == unsafe_mb_height_limit - 1);
706 unsafe_right = (avctx->
width & 0xf) && (mb_x + slice_mb_count == mb_width);
708 sl_size =
encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
709 sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp,
ctx->is_interlaced, is_top_field);
714 bytestream_put_be16(&sl_data_sizes, sl_size);
716 sl_data_size -= sl_size;
717 mb_x += slice_mb_count;
721 buf[0] = hdr_size << 3;
722 AV_WB32(buf + 1, sl_data - buf);
723 AV_WB16(buf + 5, slice_per_line * mb_height);
726 return sl_data - buf;
730 const AVFrame *pict,
int *got_packet)
733 int header_size = 148;
735 int compress_frame_size, pic_size,
ret, is_top_field_first = 0;
744 compress_frame_size = 8 + header_size;
746 bytestream_put_be32(&buf, compress_frame_size);
747 bytestream_put_be32(&buf,
FRAME_ID);
749 bytestream_put_be16(&buf, header_size);
752 bytestream_put_be16(&buf, avctx->
width);
753 bytestream_put_be16(&buf, avctx->
height);
757 if (
ctx->is_interlaced) {
762 is_top_field_first = 1;
770 *buf++ = frame_flags;
779 *buf++ =
ctx->need_alpha ? 0x2 : 0;
787 pkt->
size - compress_frame_size, 0, is_top_field_first);
791 compress_frame_size += pic_size;
793 if (
ctx->is_interlaced) {
795 pkt->
size - compress_frame_size, 1, !is_top_field_first);
799 compress_frame_size += pic_size;
803 pkt->
size = compress_frame_size;
812 for (
i = 0;
i < 64;
i++)
824 if (
ctx->is_interlaced) {
830 if (avctx->
width & 0x1) {
832 "frame width needs to be multiple of 2\n");
836 if (avctx->
width > 65534 || avctx->
height > 65535) {
838 "The maximum dimensions are 65534x65535\n");
842 if (strlen(
ctx->vendor) != 4) {
851 "encoding with ProRes standard (apcn) profile\n");
855 "encoding with ProRes 4444 (ap4h) profile\n");
859 "encoding with ProRes 4444+ (ap4h) profile\n");
867 "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch, 4 - ap4h, 5 - ap4x]\n",
872 "encoding with ProRes 444/Xq (ap4h/ap4x) profile, need YUV444P10 input\n");
877 "encoding with ProRes Proxy/LT/422/422 HQ (apco, apcs, apcn, ap4h) profile, need YUV422P10 input\n");
914 for (
i = 1;
i <= 16;
i++) {
931 #define OFFSET(x) offsetof(ProresContext, x)
932 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
952 .
p.
name =
"prores_aw",