43 #define DEFAULT_SLICE_MB_WIDTH 8
57 static const int bitrate_table[] = { 1000, 2100, 3500, 5400, 7000, 10000};
68 4, 7, 9, 11, 13, 14, 15, 63,
69 7, 7, 11, 12, 14, 15, 63, 63,
70 9, 11, 13, 14, 15, 63, 63, 63,
71 11, 11, 13, 14, 63, 63, 63, 63,
72 11, 13, 14, 63, 63, 63, 63, 63,
73 13, 14, 63, 63, 63, 63, 63, 63,
74 13, 63, 63, 63, 63, 63, 63, 63,
75 63, 63, 63, 63, 63, 63, 63, 63
77 4, 5, 6, 7, 9, 11, 13, 15,
78 5, 5, 7, 8, 11, 13, 15, 17,
79 6, 7, 9, 11, 13, 15, 15, 17,
80 7, 7, 9, 11, 13, 15, 17, 19,
81 7, 9, 11, 13, 14, 16, 19, 23,
82 9, 11, 13, 14, 16, 19, 23, 29,
83 9, 11, 13, 15, 17, 21, 28, 35,
84 11, 13, 16, 17, 21, 28, 35, 41
86 4, 4, 5, 5, 6, 7, 7, 9,
87 4, 4, 5, 6, 7, 7, 9, 9,
88 5, 5, 6, 7, 7, 9, 9, 10,
89 5, 5, 6, 7, 7, 9, 9, 10,
90 5, 6, 7, 7, 8, 9, 10, 12,
91 6, 7, 7, 8, 9, 10, 12, 15,
92 6, 7, 7, 9, 10, 11, 14, 17,
93 7, 7, 9, 10, 11, 14, 17, 21
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, 4,
98 4, 4, 4, 4, 4, 4, 4, 5,
99 4, 4, 4, 4, 4, 4, 5, 5,
100 4, 4, 4, 4, 4, 5, 5, 6,
101 4, 4, 4, 4, 5, 5, 6, 7,
102 4, 4, 4, 4, 5, 6, 7, 7
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, 4,
107 4, 4, 4, 4, 4, 4, 4, 5,
108 4, 4, 4, 4, 4, 4, 5, 5,
109 4, 4, 4, 4, 4, 5, 5, 6,
110 4, 4, 4, 4, 5, 5, 6, 7,
111 4, 4, 4, 4, 5, 6, 7, 7
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, 2,
116 2, 2, 2, 2, 2, 2, 2, 3,
117 2, 2, 2, 2, 2, 2, 3, 3,
118 2, 2, 2, 2, 2, 3, 3, 3,
119 2, 2, 2, 2, 3, 3, 3, 4,
120 2, 2, 2, 2, 3, 3, 4, 4,
126 4, 7, 9, 11, 13, 14, 63, 63,
127 7, 7, 11, 12, 14, 63, 63, 63,
128 9, 11, 13, 14, 63, 63, 63, 63,
129 11, 11, 13, 14, 63, 63, 63, 63,
130 11, 13, 14, 63, 63, 63, 63, 63,
131 13, 14, 63, 63, 63, 63, 63, 63,
132 13, 63, 63, 63, 63, 63, 63, 63,
133 63, 63, 63, 63, 63, 63, 63, 63
135 4, 5, 6, 7, 9, 11, 13, 15,
136 5, 5, 7, 8, 11, 13, 15, 17,
137 6, 7, 9, 11, 13, 15, 15, 17,
138 7, 7, 9, 11, 13, 15, 17, 19,
139 7, 9, 11, 13, 14, 16, 19, 23,
140 9, 11, 13, 14, 16, 19, 23, 29,
141 9, 11, 13, 15, 17, 21, 28, 35,
142 11, 13, 16, 17, 21, 28, 35, 41
144 4, 4, 5, 5, 6, 7, 7, 9,
145 4, 4, 5, 6, 7, 7, 9, 9,
146 5, 5, 6, 7, 7, 9, 9, 10,
147 5, 5, 6, 7, 7, 9, 9, 10,
148 5, 6, 7, 7, 8, 9, 10, 12,
149 6, 7, 7, 8, 9, 10, 12, 15,
150 6, 7, 7, 9, 10, 11, 14, 17,
151 7, 7, 9, 10, 11, 14, 17, 21
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, 4,
156 4, 4, 4, 4, 4, 4, 4, 5,
157 4, 4, 4, 4, 4, 4, 5, 5,
158 4, 4, 4, 4, 4, 5, 5, 6,
159 4, 4, 4, 4, 5, 5, 6, 7,
160 4, 4, 4, 4, 5, 6, 7, 7
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, 4,
165 4, 4, 4, 4, 4, 4, 4, 5,
166 4, 4, 4, 4, 4, 4, 5, 5,
167 4, 4, 4, 4, 4, 5, 5, 6,
168 4, 4, 4, 4, 5, 5, 6, 7,
169 4, 4, 4, 4, 5, 6, 7, 7
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, 4,
174 4, 4, 4, 4, 4, 4, 4, 5,
175 4, 4, 4, 4, 4, 4, 5, 5,
176 4, 4, 4, 4, 4, 5, 5, 6,
177 4, 4, 4, 4, 5, 5, 6, 7,
178 4, 4, 4, 4, 5, 6, 7, 7
191 int qmat_luma[16][64];
192 int qmat_chroma[16][64];
212 const int *array_valid_values,
int default_value)
217 int ref_val = array_valid_values[
i];
218 if (ref_val == INT_MAX)
226 "%s %d are not supported. Set to default value : %d\n",
227 val_name,
val, default_value);
228 return default_value;
233 unsigned int rice_order, exp_order, switch_bits, switch_val;
241 switch_val = switch_bits << rice_order;
243 if (
val >= switch_val) {
244 val -= switch_val - (1 << exp_order);
247 put_bits(pb, exponent - exp_order + switch_bits, 0);
250 exponent =
val >> rice_order;
260 #define GET_SIGN(x) ((x) >> 31)
261 #define MAKE_CODE(x) (((x) * 2) ^ GET_SIGN(x))
264 int blocks_per_slice,
int scale)
269 prev_dc = (blocks[0] - 0x4000) /
scale;
274 for (
i = 1;
i < blocks_per_slice;
i++, blocks += 64) {
275 dc = (blocks[0] - 0x4000) /
scale;
288 int blocks_per_slice,
289 int *qmat,
const uint8_t *scan)
295 int max_coeffs, abs_level;
297 max_coeffs = blocks_per_slice << 6;
299 for (
i = 1;
i < 64;
i++) {
300 for (idx = scan[
i]; idx < max_coeffs; idx += 64) {
301 level = blocks[idx] / qmat[scan[
i]];
309 prev_level =
FFMIN(abs_level, 9);
322 for (
i = 0;
i < 8;
i++) {
344 for (
i = 0;
i < mb_count;
i++) {
353 }
else if (
chroma && is_422){
354 for (
i = 0;
i < mb_count;
i++) {
361 for (
i = 0;
i < mb_count;
i++) {
373 static int encode_slice_plane(int16_t *blocks,
int mb_count, uint8_t *buf,
unsigned buf_size,
int *qmat,
int sub_sample_chroma,
376 int blocks_per_slice;
379 blocks_per_slice = mb_count << (2 - sub_sample_chroma);
382 encode_dcs(&pb, blocks, blocks_per_slice, qmat[0]);
383 encode_acs(&pb, blocks, blocks_per_slice, qmat, scan);
390 int16_t * blocks_y, int16_t * blocks_u, int16_t * blocks_v,
391 unsigned mb_count, uint8_t *buf,
unsigned data_size,
392 unsigned* y_data_size,
unsigned* u_data_size,
unsigned* v_data_size,
398 buf, data_size,
ctx->qmat_luma[qp - 1], 0,
ctx->scantable);
401 *u_data_size =
encode_slice_plane(blocks_u, mb_count, buf + *y_data_size, data_size - *y_data_size,
402 ctx->qmat_chroma[qp - 1],
ctx->is_422,
ctx->scantable);
404 *v_data_size =
encode_slice_plane(blocks_v, mb_count, buf + *y_data_size + *u_data_size,
405 data_size - *y_data_size - *u_data_size,
406 ctx->qmat_chroma[qp - 1],
ctx->is_422,
ctx->scantable);
409 return *y_data_size + *u_data_size + *v_data_size;
414 const int abits = 16;
416 const int dsize = 1 << dbits - 1;
417 int diff = cur - prev;
420 if (
diff >= (1 << abits) - dsize)
422 if (diff < -dsize || diff > dsize || !
diff) {
446 unsigned mb_count, uint8_t *buf,
unsigned data_size,
unsigned* a_data_size)
448 const int abits = 16;
449 const int mask = (1 << abits) - 1;
450 const int num_coeffs = mb_count * 256;
451 int prev =
mask, cur;
454 int16_t * blocks = (int16_t *)src_a;
471 }
while (idx < num_coeffs);
478 "Underestimated required buffer size.\n");
487 unsigned dst_width,
unsigned dst_height,
int is_alpha_plane,
488 int is_interlaced,
int is_top_field)
491 int i, j, src_stride, box_height;
492 uint16_t last_pix, *last_line;
494 if (!is_interlaced) {
496 src += y * src_stride + x;
500 src += y * src_stride + x;
506 for (
i = 0;
i < box_height; ++
i) {
507 for (j = 0; j < box_width; ++j) {
508 if (!is_alpha_plane) {
514 if (!is_alpha_plane) {
515 last_pix =
dst[j - 1];
517 last_pix =
dst[j - 1] << 6;
519 for (; j < dst_width; j++)
524 last_line =
dst - dst_width;
525 for (;
i < dst_height;
i++) {
526 for (j = 0; j < dst_width; ++j) {
527 dst[j] = last_line[j];
535 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
537 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 0, is_interlaced, is_top_field);
543 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
545 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 1, is_interlaced, is_top_field);
549 int mb_y,
unsigned mb_count, uint8_t *buf,
unsigned data_size,
550 int unsafe,
int *qp,
int is_interlaced,
int is_top_field)
552 int luma_stride, chroma_stride, alpha_stride = 0;
554 int hdr_size = 6 + (
ctx->need_alpha * 2);
555 int ret = 0, slice_size;
556 const uint8_t *dest_y, *dest_u, *dest_v;
557 unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0, a_data_size = 0;
560 int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3;
561 int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
573 if (!is_interlaced) {
574 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
575 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
576 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
578 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride * 2 + (mb_x << 5);
579 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
580 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
582 dest_y += luma_stride;
583 dest_u += chroma_stride;
584 dest_v += chroma_stride;
591 (uint16_t *)
ctx->fill_y, mb_count << 4, 16, is_interlaced, is_top_field);
594 (uint16_t *)
ctx->fill_u, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
597 (uint16_t *)
ctx->fill_v, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
605 mb_count, buf + hdr_size, data_size - hdr_size,
606 &y_data_size, &u_data_size, &v_data_size,
609 if (!is_interlaced) {
610 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride, mb_count, 0, 0);
614 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride * 2, mb_count, 0, 0);
615 calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride * 2, mb_count, 1,
ctx->is_422);
616 calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride * 2, mb_count, 1,
ctx->is_422);
620 mb_count, buf + hdr_size, data_size - hdr_size,
621 &y_data_size, &u_data_size, &v_data_size,
628 mb_count, buf + hdr_size, data_size - hdr_size,
629 &y_data_size, &u_data_size, &v_data_size,
632 }
else if (slice_size < low_bytes && *qp
637 mb_count, buf + hdr_size, data_size - hdr_size,
638 &y_data_size, &u_data_size, &v_data_size,
644 buf[0] = hdr_size << 3;
649 if (
ctx->need_alpha) {
654 (uint16_t *)
ctx->fill_a, mb_count << 4, 16, is_interlaced, is_top_field);
656 buf + hdr_size + slice_size,
657 data_size - hdr_size - slice_size, &a_data_size);
663 return hdr_size + y_data_size + u_data_size + v_data_size + a_data_size;
667 uint8_t *buf,
const int buf_size,
const int picture_index,
const int is_top_field)
670 int mb_width = (avctx->
width + 15) >> 4;
671 int hdr_size, sl_size,
i;
672 int mb_y, sl_data_size, qp, mb_height, picture_height, unsafe_mb_height_limit;
673 int unsafe_bot, unsafe_right;
674 uint8_t *sl_data, *sl_data_sizes;
675 int slice_per_line = 0, rem = mb_width;
677 if (!
ctx->is_interlaced) {
678 mb_height = (avctx->
height + 15) >> 4;
679 unsafe_mb_height_limit = mb_height;
682 picture_height = (avctx->
height + 1) / 2;
684 picture_height = avctx->
height / 2;
686 mb_height = (picture_height + 15) >> 4;
687 unsafe_mb_height_limit = mb_height;
691 slice_per_line += rem >>
i;
696 hdr_size = 8; sl_data_size = buf_size - hdr_size;
697 sl_data_sizes = buf + hdr_size;
698 sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
699 for (mb_y = 0; mb_y < mb_height; mb_y++) {
702 while (mb_x < mb_width) {
703 while (mb_width - mb_x < slice_mb_count)
704 slice_mb_count >>= 1;
706 unsafe_bot = (avctx->
height & 0xf) && (mb_y == unsafe_mb_height_limit - 1);
707 unsafe_right = (avctx->
width & 0xf) && (mb_x + slice_mb_count == mb_width);
709 sl_size =
encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
710 sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp,
ctx->is_interlaced, is_top_field);
715 bytestream_put_be16(&sl_data_sizes, sl_size);
717 sl_data_size -= sl_size;
718 mb_x += slice_mb_count;
722 buf[0] = hdr_size << 3;
723 AV_WB32(buf + 1, sl_data - buf);
724 AV_WB16(buf + 5, slice_per_line * mb_height);
727 return sl_data - buf;
731 const AVFrame *pict,
int *got_packet)
734 int header_size = 148;
736 int compress_frame_size, pic_size,
ret, is_top_field_first = 0;
745 compress_frame_size = 8 + header_size;
747 bytestream_put_be32(&buf, compress_frame_size);
748 bytestream_put_be32(&buf,
FRAME_ID);
750 bytestream_put_be16(&buf, header_size);
753 bytestream_put_be16(&buf, avctx->
width);
754 bytestream_put_be16(&buf, avctx->
height);
758 if (
ctx->is_interlaced) {
763 is_top_field_first = 1;
771 *buf++ = frame_flags;
780 *buf++ =
ctx->need_alpha ? 0x2 : 0;
788 pkt->
size - compress_frame_size, 0, is_top_field_first);
792 compress_frame_size += pic_size;
794 if (
ctx->is_interlaced) {
796 pkt->
size - compress_frame_size, 1, !is_top_field_first);
800 compress_frame_size += pic_size;
804 pkt->
size = compress_frame_size;
813 for (
i = 0;
i < 64;
i++)
825 if (
ctx->is_interlaced) {
831 if (avctx->
width & 0x1) {
833 "frame width needs to be multiple of 2\n");
837 if (avctx->
width > 65534 || avctx->
height > 65535) {
839 "The maximum dimensions are 65534x65535\n");
843 if (strlen(
ctx->vendor) != 4) {
853 "encoding with ProRes standard (apcn) profile\n");
858 "encoding with ProRes 4444 (ap4h) profile\n");
863 "encoding with ProRes 4444+ (ap4h) profile\n");
873 "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch, 4 - ap4h, 5 - ap4x]\n",
878 "encoding with ProRes 444/Xq (ap4h/ap4x) profile, need YUV444P10 input\n");
883 "encoding with ProRes Proxy/LT/422/422 HQ (apco, apcs, apcn, ap4h) profile, need YUV422P10 input\n");
920 for (
i = 1;
i <= 16;
i++) {
937 #define OFFSET(x) offsetof(ProresContext, x)
938 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
958 .
p.
name =
"prores_aw",