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);
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);
407 return *y_data_size + *u_data_size + *v_data_size;
412 const int abits = 16;
414 const int dsize = 1 << dbits - 1;
415 int diff = cur - prev;
418 if (
diff >= (1 << abits) - dsize)
420 if (diff < -dsize || diff > dsize || !
diff) {
444 unsigned mb_count, uint8_t *buf,
unsigned data_size,
unsigned* a_data_size)
446 const int abits = 16;
447 const int mask = (1 << abits) - 1;
448 const int num_coeffs = mb_count * 256;
449 int prev =
mask, cur;
452 int16_t * blocks = (int16_t *)src_a;
469 }
while (idx < num_coeffs);
476 "Underestimated required buffer size.\n");
485 unsigned dst_width,
unsigned dst_height,
int is_alpha_plane,
486 int is_interlaced,
int is_top_field)
489 int i, j, src_stride, box_height;
490 uint16_t last_pix, *last_line;
492 if (!is_interlaced) {
494 src += y * src_stride + x;
498 src += y * src_stride + x;
504 for (
i = 0;
i < box_height; ++
i) {
505 for (j = 0; j < box_width; ++j) {
506 if (!is_alpha_plane) {
512 if (!is_alpha_plane) {
513 last_pix =
dst[j - 1];
515 last_pix =
dst[j - 1] << 6;
517 for (; j < dst_width; j++)
522 last_line =
dst - dst_width;
523 for (;
i < dst_height;
i++) {
524 for (j = 0; j < dst_width; ++j) {
525 dst[j] = last_line[j];
533 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
535 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 0, is_interlaced, is_top_field);
541 unsigned dst_width,
unsigned dst_height,
int is_interlaced,
int is_top_field)
543 subimage_with_fill_template(
src, x, y,
stride,
width,
height,
dst, dst_width, dst_height, 1, is_interlaced, is_top_field);
547 int mb_y,
unsigned mb_count, uint8_t *buf,
unsigned data_size,
548 int unsafe,
int *qp,
int is_interlaced,
int is_top_field)
550 int luma_stride, chroma_stride, alpha_stride = 0;
552 int hdr_size = 6 + (
ctx->need_alpha * 2);
553 int ret = 0, slice_size;
554 const uint8_t *dest_y, *dest_u, *dest_v;
555 unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0, a_data_size = 0;
558 int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3;
559 int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
571 if (!is_interlaced) {
572 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
573 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
574 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride + (mb_x << (5 -
ctx->is_422));
576 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride * 2 + (mb_x << 5);
577 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
578 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 -
ctx->is_422));
580 dest_y += luma_stride;
581 dest_u += chroma_stride;
582 dest_v += chroma_stride;
589 (uint16_t *)
ctx->fill_y, mb_count << 4, 16, is_interlaced, is_top_field);
592 (uint16_t *)
ctx->fill_u, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
595 (uint16_t *)
ctx->fill_v, mb_count << (4 -
ctx->is_422), 16, is_interlaced, is_top_field);
603 mb_count, buf + hdr_size, data_size - hdr_size,
604 &y_data_size, &u_data_size, &v_data_size,
607 if (!is_interlaced) {
608 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride, mb_count, 0, 0);
612 calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride * 2, mb_count, 0, 0);
613 calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride * 2, mb_count, 1,
ctx->is_422);
614 calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride * 2, mb_count, 1,
ctx->is_422);
618 mb_count, buf + hdr_size, data_size - hdr_size,
619 &y_data_size, &u_data_size, &v_data_size,
626 mb_count, buf + hdr_size, data_size - hdr_size,
627 &y_data_size, &u_data_size, &v_data_size,
630 }
else if (slice_size < low_bytes && *qp
635 mb_count, buf + hdr_size, data_size - hdr_size,
636 &y_data_size, &u_data_size, &v_data_size,
642 buf[0] = hdr_size << 3;
647 if (
ctx->need_alpha) {
652 (uint16_t *)
ctx->fill_a, mb_count << 4, 16, is_interlaced, is_top_field);
654 buf + hdr_size + slice_size,
655 data_size - hdr_size - slice_size, &a_data_size);
661 return hdr_size + y_data_size + u_data_size + v_data_size + a_data_size;
665 uint8_t *buf,
const int buf_size,
const int picture_index,
const int is_top_field)
668 int mb_width = (avctx->
width + 15) >> 4;
669 int hdr_size, sl_size,
i;
670 int mb_y, sl_data_size, qp, mb_height, picture_height, unsafe_mb_height_limit;
671 int unsafe_bot, unsafe_right;
672 uint8_t *sl_data, *sl_data_sizes;
673 int slice_per_line = 0, rem = mb_width;
675 if (!
ctx->is_interlaced) {
676 mb_height = (avctx->
height + 15) >> 4;
677 unsafe_mb_height_limit = mb_height;
680 picture_height = (avctx->
height + 1) / 2;
682 picture_height = avctx->
height / 2;
684 mb_height = (picture_height + 15) >> 4;
685 unsafe_mb_height_limit = mb_height;
689 slice_per_line += rem >>
i;
694 hdr_size = 8; sl_data_size = buf_size - hdr_size;
695 sl_data_sizes = buf + hdr_size;
696 sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
697 for (mb_y = 0; mb_y < mb_height; mb_y++) {
700 while (mb_x < mb_width) {
701 while (mb_width - mb_x < slice_mb_count)
702 slice_mb_count >>= 1;
704 unsafe_bot = (avctx->
height & 0xf) && (mb_y == unsafe_mb_height_limit - 1);
705 unsafe_right = (avctx->
width & 0xf) && (mb_x + slice_mb_count == mb_width);
707 sl_size =
encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
708 sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp,
ctx->is_interlaced, is_top_field);
713 bytestream_put_be16(&sl_data_sizes, sl_size);
715 sl_data_size -= sl_size;
716 mb_x += slice_mb_count;
720 buf[0] = hdr_size << 3;
721 AV_WB32(buf + 1, sl_data - buf);
722 AV_WB16(buf + 5, slice_per_line * mb_height);
725 return sl_data - buf;
729 const AVFrame *pict,
int *got_packet)
732 int header_size = 148;
734 int compress_frame_size, pic_size,
ret, is_top_field_first = 0;
743 compress_frame_size = 8 + header_size;
745 bytestream_put_be32(&buf, compress_frame_size);
746 bytestream_put_be32(&buf,
FRAME_ID);
748 bytestream_put_be16(&buf, header_size);
751 bytestream_put_be16(&buf, avctx->
width);
752 bytestream_put_be16(&buf, avctx->
height);
756 if (
ctx->is_interlaced) {
761 is_top_field_first = 1;
769 *buf++ = frame_flags;
778 *buf++ =
ctx->need_alpha ? 0x2 : 0;
786 pkt->
size - compress_frame_size, 0, is_top_field_first);
790 compress_frame_size += pic_size;
792 if (
ctx->is_interlaced) {
794 pkt->
size - compress_frame_size, 1, !is_top_field_first);
798 compress_frame_size += pic_size;
802 pkt->
size = compress_frame_size;
811 for (
i = 0;
i < 64;
i++)
823 if (
ctx->is_interlaced) {
829 if (avctx->
width & 0x1) {
831 "frame width needs to be multiple of 2\n");
835 if (avctx->
width > 65534 || avctx->
height > 65535) {
837 "The maximum dimensions are 65534x65535\n");
841 if (strlen(
ctx->vendor) != 4) {
851 "encoding with ProRes standard (apcn) profile\n");
856 "encoding with ProRes 4444 (ap4h) profile\n");
861 "encoding with ProRes 4444+ (ap4h) profile\n");
871 "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch, 4 - ap4h, 5 - ap4x]\n",
876 "encoding with ProRes 444/Xq (ap4h/ap4x) profile, need YUV444P10 input\n");
881 "encoding with ProRes Proxy/LT/422/422 HQ (apco, apcs, apcn, ap4h) profile, need YUV422P10 input\n");
918 for (
i = 1;
i <= 16;
i++) {
935 #define OFFSET(x) offsetof(ProresContext, x)
936 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
956 .
p.
name =
"prores_aw",