35 #define DEFAULT_SLICE_MB_WIDTH 8
37 #define FF_PROFILE_PRORES_PROXY 0
38 #define FF_PROFILE_PRORES_LT 1
39 #define FF_PROFILE_PRORES_STANDARD 2
40 #define FF_PROFILE_PRORES_HQ 3
55 0, 1, 8, 9, 2, 3, 10, 11,
56 16, 17, 24, 25, 18, 19, 26, 27,
57 4, 5, 12, 20, 13, 6, 7, 14,
58 21, 28, 29, 22, 15, 23, 30, 31,
59 32, 33, 40, 48, 41, 34, 35, 42,
60 49, 56, 57, 50, 43, 36, 37, 44,
61 51, 58, 59, 52, 45, 38, 39, 46,
62 53, 60, 61, 54, 47, 55, 62, 63
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
107 4, 7, 9, 11, 13, 14, 63, 63,
108 7, 7, 11, 12, 14, 63, 63, 63,
109 9, 11, 13, 14, 63, 63, 63, 63,
110 11, 11, 13, 14, 63, 63, 63, 63,
111 11, 13, 14, 63, 63, 63, 63, 63,
112 13, 14, 63, 63, 63, 63, 63, 63,
113 13, 63, 63, 63, 63, 63, 63, 63,
114 63, 63, 63, 63, 63, 63, 63, 63
116 4, 5, 6, 7, 9, 11, 13, 15,
117 5, 5, 7, 8, 11, 13, 15, 17,
118 6, 7, 9, 11, 13, 15, 15, 17,
119 7, 7, 9, 11, 13, 15, 17, 19,
120 7, 9, 11, 13, 14, 16, 19, 23,
121 9, 11, 13, 14, 16, 19, 23, 29,
122 9, 11, 13, 15, 17, 21, 28, 35,
123 11, 13, 16, 17, 21, 28, 35, 41
125 4, 4, 5, 5, 6, 7, 7, 9,
126 4, 4, 5, 6, 7, 7, 9, 9,
127 5, 5, 6, 7, 7, 9, 9, 10,
128 5, 5, 6, 7, 7, 9, 9, 10,
129 5, 6, 7, 7, 8, 9, 10, 12,
130 6, 7, 7, 8, 9, 10, 12, 15,
131 6, 7, 7, 9, 10, 11, 14, 17,
132 7, 7, 9, 10, 11, 14, 17, 21
134 4, 4, 4, 4, 4, 4, 4, 4,
135 4, 4, 4, 4, 4, 4, 4, 4,
136 4, 4, 4, 4, 4, 4, 4, 4,
137 4, 4, 4, 4, 4, 4, 4, 5,
138 4, 4, 4, 4, 4, 4, 5, 5,
139 4, 4, 4, 4, 4, 5, 5, 6,
140 4, 4, 4, 4, 5, 5, 6, 7,
141 4, 4, 4, 4, 5, 6, 7, 7
151 int qmat_luma[16][64];
152 int qmat_chroma[16][64];
157 unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros,
161 switch_bits = codebook & 3;
162 rice_order = codebook >> 5;
163 exp_order = (codebook >> 2) & 7;
165 first_exp = ((switch_bits + 1) << rice_order);
167 if (val >= first_exp) {
169 val += (1 << exp_order);
171 zeros = exp - exp_order + switch_bits + 1;
174 }
else if (rice_order) {
175 mask = (1 << rice_order) - 1;
176 put_bits(pb, (val >> rice_order), 0);
178 put_bits(pb, rice_order, val & mask);
185 #define QSCALE(qmat,ind,val) ((val) / (qmat[ind]))
186 #define TO_GOLOMB(val) ((val << 1) ^ (val >> 31))
187 #define DIFF_SIGN(val, sign) ((val >> 31) ^ sign)
188 #define IS_NEGATIVE(val) (((val >> 31) ^ -1) + 1)
189 #define TO_GOLOMB2(val,sign) (val==0 ? 0 : (val << 1) + sign)
193 int sign = (val >> 31);
194 return (val ^ sign) - sign;
197 #define FIRST_DC_CB 0xB8
202 int blocks_per_slice,
int *qmat)
206 int new_dc,
delta, diff_sign, new_code;
208 prev_dc =
QSCALE(qmat, 0, in[0] - 16384);
212 code = 5; sign = 0; idx = 64;
213 for (i = 1; i < blocks_per_slice; i++, idx += 64) {
214 new_dc =
QSCALE(qmat, 0, in[idx] - 16384);
215 delta = new_dc - prev_dc;
228 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
230 0x28, 0x28, 0x28, 0x4C };
233 DCTELEM *in,
int blocks_per_slice,
int *qmat)
239 for (i = 1; i < 64; i++) {
241 for (j = 0; j < blocks_per_slice; j++) {
242 int val =
QSCALE(qmat, indp, in[(j << 6) + indp]);
265 int16_t *p = (int16_t*)pixels;
269 for (i = 0; i < 8; i++) {
270 for (j = 0; j < 8; j++) {
286 int *qmat,
int chroma)
289 int i, blocks_per_slice;
293 for (i = 0; i < mb_count; i++) {
295 fdct_get(src + 8 * src_stride, src_stride,
block + ((2 - chroma) << 6));
298 fdct_get(src + 16 + 8 * src_stride, src_stride,
block + (3 << 6));
301 block += (256 >> chroma);
302 src += (32 >> chroma);
305 blocks_per_slice = mb_count << (2 - chroma);
317 int chroma_stride,
unsigned mb_count,
uint8_t *buf,
unsigned data_size,
318 unsigned* y_data_size,
unsigned* u_data_size,
unsigned* v_data_size,
324 buf, data_size, ctx->
qmat_luma[qp - 1], 0);
328 chroma_stride, buf + *y_data_size, data_size - *y_data_size,
332 chroma_stride, buf + *y_data_size + *u_data_size,
333 data_size - *y_data_size - *u_data_size,
337 return *y_data_size + *u_data_size + *v_data_size;
342 unsigned dst_width,
unsigned dst_height)
345 int box_width =
FFMIN(width - x, dst_width);
346 int box_height =
FFMIN(height - y, dst_height);
347 int i, j, src_stride = stride >> 1;
348 uint16_t last_pix, *last_line;
350 src += y * src_stride + x;
351 for (i = 0; i < box_height; ++i) {
352 for (j = 0; j < box_width; ++j) {
355 last_pix = dst[j - 1];
356 for (; j < dst_width; j++)
361 last_line = dst - dst_width;
362 for (; i < dst_height; i++) {
363 for (j = 0; j < dst_width; ++j) {
364 dst[j] = last_line[j];
371 int mb_y,
unsigned mb_count,
uint8_t *buf,
unsigned data_size,
374 int luma_stride, chroma_stride;
375 int hdr_size = 6, slice_size;
376 uint8_t *dest_y, *dest_u, *dest_v;
377 unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0;
380 int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3;
381 int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
386 dest_y = pic->
data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
387 dest_u = pic->
data[1] + (mb_y << 4) * chroma_stride + (mb_x << 4);
388 dest_v = pic->
data[2] + (mb_y << 4) * chroma_stride + (mb_x << 4);
394 (uint16_t *) ctx->
fill_y, mb_count << 4, 16);
397 (uint16_t *) ctx->
fill_u, mb_count << 3, 16);
400 (uint16_t *) ctx->
fill_v, mb_count << 3, 16);
403 mb_count << 5, mb_count << 4, mb_count, buf + hdr_size,
404 data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size,
408 luma_stride, chroma_stride, mb_count, buf + hdr_size,
409 data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size,
416 luma_stride, chroma_stride, mb_count, buf + hdr_size,
417 data_size - hdr_size, &y_data_size, &u_data_size,
420 }
else if (slice_size < low_bytes && *qp
425 luma_stride, chroma_stride, mb_count, buf + hdr_size,
426 data_size - hdr_size, &y_data_size, &u_data_size,
432 buf[0] = hdr_size << 3;
437 return hdr_size + y_data_size + u_data_size + v_data_size;
441 uint8_t *buf,
const int buf_size)
443 int mb_width = (avctx->
width + 15) >> 4;
444 int mb_height = (avctx->
height + 15) >> 4;
445 int hdr_size, sl_size, i;
446 int mb_y, sl_data_size, qp;
447 int unsafe_bot, unsafe_right;
448 uint8_t *sl_data, *sl_data_sizes;
449 int slice_per_line = 0, rem = mb_width;
452 slice_per_line += rem >> i;
457 hdr_size = 8; sl_data_size = buf_size - hdr_size;
458 sl_data_sizes = buf + hdr_size;
459 sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
460 for (mb_y = 0; mb_y < mb_height; mb_y++) {
463 while (mb_x < mb_width) {
464 while (mb_width - mb_x < slice_mb_count)
465 slice_mb_count >>= 1;
467 unsafe_bot = (avctx->
height & 0xf) && (mb_y == mb_height - 1);
468 unsafe_right = (avctx->
width & 0xf) && (mb_x + slice_mb_count == mb_width);
470 sl_size =
encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
471 sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp);
473 bytestream_put_be16(&sl_data_sizes, sl_size);
475 sl_data_size -= sl_size;
476 mb_x += slice_mb_count;
480 buf[0] = hdr_size << 3;
481 AV_WB32(buf + 1, sl_data - buf);
482 AV_WB16(buf + 5, slice_per_line * mb_height);
485 return sl_data - buf;
489 const AVFrame *pict,
int *got_packet)
491 int header_size = 148;
502 pkt->
size - header_size - 8);
504 bytestream_put_be32(&buf, pic_size + 8 + header_size);
507 bytestream_put_be16(&buf, header_size);
508 bytestream_put_be16(&buf, 0);
510 bytestream_put_be16(&buf, avctx->
width);
511 bytestream_put_be16(&buf, avctx->
height);
525 pkt->
size = pic_size + 8 + header_size;
534 for (i = 0; i < 64; i++)
535 dst[i] = src[i] * scale;
547 if (avctx->
width & 0x1) {
549 "frame width needs to be multiple of 2\n");
553 if ((avctx->
height & 0xf) || (avctx->
width & 0xf)) {
564 "encoding with ProRes standard (apcn) profile\n");
571 "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch]\n",
578 for (i = 1; i <= 16; i++) {
600 .
name =
"prores_anatoliy",