FFmpeg
proresenc_anatoliy.c
Go to the documentation of this file.
1 /*
2  * Apple ProRes encoder
3  *
4  * Copyright (c) 2011 Anatoliy Wasserman
5  * Copyright (c) 2012 Konstantin Shishkov
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * Apple ProRes encoder (Anatoliy Wasserman version)
27  * Known FOURCCs: 'ap4h' (444), 'apch' (HQ), 'apcn' (422), 'apcs' (LT), 'acpo' (Proxy)
28  */
29 
30 #include "libavutil/mem_internal.h"
31 #include "libavutil/opt.h"
32 #include "avcodec.h"
33 #include "codec_internal.h"
34 #include "encode.h"
35 #include "internal.h"
36 #include "profiles.h"
37 #include "proresdata.h"
38 #include "put_bits.h"
39 #include "bytestream.h"
40 #include "fdctdsp.h"
41 
42 #define DEFAULT_SLICE_MB_WIDTH 8
43 
44 static const AVProfile profiles[] = {
45  { FF_PROFILE_PRORES_PROXY, "apco"},
46  { FF_PROFILE_PRORES_LT, "apcs"},
47  { FF_PROFILE_PRORES_STANDARD, "apcn"},
48  { FF_PROFILE_PRORES_HQ, "apch"},
49  { FF_PROFILE_PRORES_4444, "ap4h"},
50  { FF_PROFILE_PRORES_XQ, "ap4x"},
52 };
53 
54 static const int qp_start_table[] = { 8, 3, 2, 1, 1, 1};
55 static const int qp_end_table[] = { 13, 9, 6, 6, 5, 4};
56 static const int bitrate_table[] = { 1000, 2100, 3500, 5400, 7000, 10000};
57 
61  AVCOL_TRC_ARIB_STD_B67, INT_MAX };
63  AVCOL_SPC_BT2020_NCL, INT_MAX };
64 
65 static const uint8_t QMAT_LUMA[6][64] = {
66  {
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
75  }, {
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
84  }, {
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
93  }, {
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
102  }, { /* 444 */
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
111  }, { /* 444 XQ */
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,
120  }
121 };
122 
123 static const uint8_t QMAT_CHROMA[6][64] = {
124  {
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
133  }, {
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
142  }, {
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
151  }, {
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
160  }, { /* 444 */
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
169  }, { /* 444 xq */
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
178  }
179 };
180 
181 
182 typedef struct {
183  AVClass *class;
185  uint8_t* fill_y;
186  uint8_t* fill_u;
187  uint8_t* fill_v;
188  uint8_t* fill_a;
189 
190  int qmat_luma[16][64];
191  int qmat_chroma[16][64];
192  const uint8_t *scantable;
193 
194  int is_422;
197 
198  char *vendor;
199 } ProresContext;
200 
201 static void encode_codeword(PutBitContext *pb, int val, int codebook)
202 {
203  unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros;
204 
205  /* number of bits to switch between rice and exp golomb */
206  switch_bits = codebook & 3;
207  rice_order = codebook >> 5;
208  exp_order = (codebook >> 2) & 7;
209 
210  first_exp = ((switch_bits + 1) << rice_order);
211 
212  if (val >= first_exp) { /* exp golomb */
213  val -= first_exp;
214  val += (1 << exp_order);
215  exp = av_log2(val);
216  zeros = exp - exp_order + switch_bits + 1;
217  put_bits(pb, zeros, 0);
218  put_bits(pb, exp + 1, val);
219  } else if (rice_order) {
220  put_bits(pb, (val >> rice_order), 0);
221  put_bits(pb, 1, 1);
222  put_sbits(pb, rice_order, val);
223  } else {
224  put_bits(pb, val, 0);
225  put_bits(pb, 1, 1);
226  }
227 }
228 
229 #define QSCALE(qmat,ind,val) ((val) / ((qmat)[ind]))
230 #define TO_GOLOMB(val) (((val) * 2) ^ ((val) >> 31))
231 #define DIFF_SIGN(val, sign) (((val) >> 31) ^ (sign))
232 #define IS_NEGATIVE(val) ((((val) >> 31) ^ -1) + 1)
233 #define TO_GOLOMB2(val,sign) ((val)==0 ? 0 : ((val) << 1) + (sign))
234 
236 {
237  int sign = (val >> 31);
238  return (val ^ sign) - sign;
239 }
240 
241 #define FIRST_DC_CB 0xB8
242 
243 static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
244 
245 static void encode_dc_coeffs(PutBitContext *pb, int16_t *in,
246  int blocks_per_slice, int *qmat)
247 {
248  int prev_dc, code;
249  int i, sign, idx;
250  int new_dc, delta, diff_sign, new_code;
251 
252  prev_dc = QSCALE(qmat, 0, in[0] - 16384);
253  code = TO_GOLOMB(prev_dc);
255 
256  code = 5; sign = 0; idx = 64;
257  for (i = 1; i < blocks_per_slice; i++, idx += 64) {
258  new_dc = QSCALE(qmat, 0, in[idx] - 16384);
259  delta = new_dc - prev_dc;
260  diff_sign = DIFF_SIGN(delta, sign);
261  new_code = TO_GOLOMB2(get_level(delta), diff_sign);
262 
263  encode_codeword(pb, new_code, dc_codebook[FFMIN(code, 6)]);
264 
265  code = new_code;
266  sign = delta >> 31;
267  prev_dc = new_dc;
268  }
269 }
270 
271 static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29,
272  0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
273 static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28,
274  0x28, 0x28, 0x28, 0x4C };
275 
277  int16_t *in, int blocks_per_slice, int *qmat, const uint8_t ff_prores_scan[64])
278 {
279  int prev_run = 4;
280  int prev_level = 2;
281 
282  int run = 0, level, code, i, j;
283  for (i = 1; i < 64; i++) {
284  int indp = ff_prores_scan[i];
285  for (j = 0; j < blocks_per_slice; j++) {
286  int val = QSCALE(qmat, indp, in[(j << 6) + indp]);
287  if (val) {
288  encode_codeword(pb, run, run_to_cb[FFMIN(prev_run, 15)]);
289 
290  prev_run = run;
291  run = 0;
292  level = get_level(val);
293  code = level - 1;
294 
295  encode_codeword(pb, code, lev_to_cb[FFMIN(prev_level, 9)]);
296 
297  prev_level = level;
298 
299  put_bits(pb, 1, IS_NEGATIVE(val));
300  } else {
301  ++run;
302  }
303  }
304  }
305 }
306 
307 static void get(const uint8_t *pixels, int stride, int16_t* block)
308 {
309  int i;
310 
311  for (i = 0; i < 8; i++) {
312  AV_WN64(block, AV_RN64(pixels));
313  AV_WN64(block+4, AV_RN64(pixels+8));
314  pixels += stride;
315  block += 8;
316  }
317 }
318 
319 static void fdct_get(FDCTDSPContext *fdsp, const uint8_t *pixels, int stride, int16_t* block)
320 {
321  get(pixels, stride, block);
322  fdsp->fdct(block);
323 }
324 
325 static void calc_plane_dct(FDCTDSPContext *fdsp, const uint8_t *src, int16_t * blocks, int src_stride, int mb_count, int chroma, int is_422)
326 {
327  int16_t *block;
328  int i;
329 
330  block = blocks;
331 
332  if (!chroma) { /* Luma plane */
333  for (i = 0; i < mb_count; i++) {
334  fdct_get(fdsp, src, src_stride, block + (0 << 6));
335  fdct_get(fdsp, src + 16, src_stride, block + (1 << 6));
336  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (2 << 6));
337  fdct_get(fdsp, src + 16 + 8 * src_stride, src_stride, block + (3 << 6));
338 
339  block += 256;
340  src += 32;
341  }
342  } else if (chroma && is_422){ /* chroma plane 422 */
343  for (i = 0; i < mb_count; i++) {
344  fdct_get(fdsp, src, src_stride, block + (0 << 6));
345  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (1 << 6));
346  block += (256 >> 1);
347  src += (32 >> 1);
348  }
349  } else { /* chroma plane 444 */
350  for (i = 0; i < mb_count; i++) {
351  fdct_get(fdsp, src, src_stride, block + (0 << 6));
352  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (1 << 6));
353  fdct_get(fdsp, src + 16, src_stride, block + (2 << 6));
354  fdct_get(fdsp, src + 16 + 8 * src_stride, src_stride, block + (3 << 6));
355 
356  block += 256;
357  src += 32;
358  }
359  }
360 }
361 
362 static int encode_slice_plane(int16_t *blocks, int mb_count, uint8_t *buf, unsigned buf_size, int *qmat, int sub_sample_chroma,
363  const uint8_t ff_prores_scan[64])
364 {
365  int blocks_per_slice;
366  PutBitContext pb;
367 
368  blocks_per_slice = mb_count << (2 - sub_sample_chroma);
369  init_put_bits(&pb, buf, buf_size);
370 
371  encode_dc_coeffs(&pb, blocks, blocks_per_slice, qmat);
372  encode_ac_coeffs(&pb, blocks, blocks_per_slice, qmat, ff_prores_scan);
373 
374  flush_put_bits(&pb);
375  return put_bits_ptr(&pb) - pb.buf;
376 }
377 
379  int16_t * blocks_y, int16_t * blocks_u, int16_t * blocks_v,
380  unsigned mb_count, uint8_t *buf, unsigned data_size,
381  unsigned* y_data_size, unsigned* u_data_size, unsigned* v_data_size,
382  int qp)
383 {
384  ProresContext* ctx = avctx->priv_data;
385 
386  *y_data_size = encode_slice_plane(blocks_y, mb_count,
387  buf, data_size, ctx->qmat_luma[qp - 1], 0, ctx->scantable);
388 
389  if (!(avctx->flags & AV_CODEC_FLAG_GRAY)) {
390  *u_data_size = encode_slice_plane(blocks_u, mb_count, buf + *y_data_size, data_size - *y_data_size,
391  ctx->qmat_chroma[qp - 1], ctx->is_422, ctx->scantable);
392 
393  *v_data_size = encode_slice_plane(blocks_v, mb_count, buf + *y_data_size + *u_data_size,
394  data_size - *y_data_size - *u_data_size,
395  ctx->qmat_chroma[qp - 1], ctx->is_422, ctx->scantable);
396  }
397 
398  return *y_data_size + *u_data_size + *v_data_size;
399 }
400 
401 static void put_alpha_diff(PutBitContext *pb, int cur, int prev)
402 {
403  const int abits = 16;
404  const int dbits = 7;
405  const int dsize = 1 << dbits - 1;
406  int diff = cur - prev;
407 
408  diff = av_mod_uintp2(diff, abits);
409  if (diff >= (1 << abits) - dsize)
410  diff -= 1 << abits;
411  if (diff < -dsize || diff > dsize || !diff) {
412  put_bits(pb, 1, 1);
413  put_bits(pb, abits, diff);
414  } else {
415  put_bits(pb, 1, 0);
416  put_bits(pb, dbits - 1, FFABS(diff) - 1);
417  put_bits(pb, 1, diff < 0);
418  }
419 }
420 
421 static inline void put_alpha_run(PutBitContext *pb, int run)
422 {
423  if (run) {
424  put_bits(pb, 1, 0);
425  if (run < 0x10)
426  put_bits(pb, 4, run);
427  else
428  put_bits(pb, 15, run);
429  } else {
430  put_bits(pb, 1, 1);
431  }
432 }
433 
434 static av_always_inline int encode_alpha_slice_data(AVCodecContext *avctx, int8_t * src_a,
435  unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned* a_data_size)
436 {
437  const int abits = 16;
438  const int mask = (1 << abits) - 1;
439  const int num_coeffs = mb_count * 256;
440  int prev = mask, cur;
441  int idx = 0;
442  int run = 0;
443  int16_t * blocks = (int16_t *)src_a;
444  PutBitContext pb;
445  init_put_bits(&pb, buf, data_size);
446 
447  cur = blocks[idx++];
448  put_alpha_diff(&pb, cur, prev);
449  prev = cur;
450  do {
451  cur = blocks[idx++];
452  if (cur != prev) {
453  put_alpha_run (&pb, run);
454  put_alpha_diff(&pb, cur, prev);
455  prev = cur;
456  run = 0;
457  } else {
458  run++;
459  }
460  } while (idx < num_coeffs);
461  if (run)
462  put_alpha_run(&pb, run);
463  flush_put_bits(&pb);
464  *a_data_size = put_bytes_output(&pb);
465 
466  if (put_bits_left(&pb) < 0) {
467  av_log(avctx, AV_LOG_ERROR,
468  "Underestimated required buffer size.\n");
469  return AVERROR_BUG;
470  } else {
471  return 0;
472  }
473 }
474 
475 static inline void subimage_with_fill_template(const uint16_t *src, unsigned x, unsigned y,
476  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
477  unsigned dst_width, unsigned dst_height, int is_alpha_plane,
478  int is_interlaced, int is_top_field)
479 {
480  int box_width = FFMIN(width - x, dst_width);
481  int i, j, src_stride, box_height;
482  uint16_t last_pix, *last_line;
483 
484  if (!is_interlaced) {
485  src_stride = stride >> 1;
486  src += y * src_stride + x;
487  box_height = FFMIN(height - y, dst_height);
488  } else {
489  src_stride = stride; /* 2 lines stride */
490  src += y * src_stride + x;
491  box_height = FFMIN(height/2 - y, dst_height);
492  if (!is_top_field)
493  src += stride >> 1;
494  }
495 
496  for (i = 0; i < box_height; ++i) {
497  for (j = 0; j < box_width; ++j) {
498  if (!is_alpha_plane) {
499  dst[j] = src[j];
500  } else {
501  dst[j] = src[j] << 6; /* alpha 10b to 16b */
502  }
503  }
504  if (!is_alpha_plane) {
505  last_pix = dst[j - 1];
506  } else {
507  last_pix = dst[j - 1] << 6; /* alpha 10b to 16b */
508  }
509  for (; j < dst_width; j++)
510  dst[j] = last_pix;
511  src += src_stride;
512  dst += dst_width;
513  }
514  last_line = dst - dst_width;
515  for (; i < dst_height; i++) {
516  for (j = 0; j < dst_width; ++j) {
517  dst[j] = last_line[j];
518  }
519  dst += dst_width;
520  }
521 }
522 
523 static void subimage_with_fill(const uint16_t *src, unsigned x, unsigned y,
524  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
525  unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
526 {
527  subimage_with_fill_template(src, x, y, stride, width, height, dst, dst_width, dst_height, 0, is_interlaced, is_top_field);
528 }
529 
530 /* reorganize alpha data and convert 10b -> 16b */
531 static void subimage_alpha_with_fill(const uint16_t *src, unsigned x, unsigned y,
532  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
533  unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
534 {
535  subimage_with_fill_template(src, x, y, stride, width, height, dst, dst_width, dst_height, 1, is_interlaced, is_top_field);
536 }
537 
538 static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, int mb_x,
539  int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size,
540  int unsafe, int *qp, int is_interlaced, int is_top_field)
541 {
542  int luma_stride, chroma_stride, alpha_stride = 0;
543  ProresContext* ctx = avctx->priv_data;
544  int hdr_size = 6 + (ctx->need_alpha * 2); /* v data size is write when there is alpha */
545  int ret = 0, slice_size;
546  const uint8_t *dest_y, *dest_u, *dest_v;
547  unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0, a_data_size = 0;
548  FDCTDSPContext *fdsp = &ctx->fdsp;
549  int tgt_bits = (mb_count * bitrate_table[avctx->profile]) >> 2;
550  int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3; // 12% bitrate fluctuation
551  int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
552 
553  LOCAL_ALIGNED(16, int16_t, blocks_y, [DEFAULT_SLICE_MB_WIDTH << 8]);
554  LOCAL_ALIGNED(16, int16_t, blocks_u, [DEFAULT_SLICE_MB_WIDTH << 8]);
555  LOCAL_ALIGNED(16, int16_t, blocks_v, [DEFAULT_SLICE_MB_WIDTH << 8]);
556 
557  luma_stride = pic->linesize[0];
558  chroma_stride = pic->linesize[1];
559 
560  if (ctx->need_alpha)
561  alpha_stride = pic->linesize[3];
562 
563  if (!is_interlaced) {
564  dest_y = pic->data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
565  dest_u = pic->data[1] + (mb_y << 4) * chroma_stride + (mb_x << (5 - ctx->is_422));
566  dest_v = pic->data[2] + (mb_y << 4) * chroma_stride + (mb_x << (5 - ctx->is_422));
567  } else {
568  dest_y = pic->data[0] + (mb_y << 4) * luma_stride * 2 + (mb_x << 5);
569  dest_u = pic->data[1] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 - ctx->is_422));
570  dest_v = pic->data[2] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 - ctx->is_422));
571  if (!is_top_field){ /* bottom field, offset dest */
572  dest_y += luma_stride;
573  dest_u += chroma_stride;
574  dest_v += chroma_stride;
575  }
576  }
577 
578  if (unsafe) {
579  subimage_with_fill((const uint16_t *) pic->data[0], mb_x << 4, mb_y << 4,
580  luma_stride, avctx->width, avctx->height,
581  (uint16_t *) ctx->fill_y, mb_count << 4, 16, is_interlaced, is_top_field);
582  subimage_with_fill((const uint16_t *) pic->data[1], mb_x << (4 - ctx->is_422), mb_y << 4,
583  chroma_stride, avctx->width >> ctx->is_422, avctx->height,
584  (uint16_t *) ctx->fill_u, mb_count << (4 - ctx->is_422), 16, is_interlaced, is_top_field);
585  subimage_with_fill((const uint16_t *) pic->data[2], mb_x << (4 - ctx->is_422), mb_y << 4,
586  chroma_stride, avctx->width >> ctx->is_422, avctx->height,
587  (uint16_t *) ctx->fill_v, mb_count << (4 - ctx->is_422), 16, is_interlaced, is_top_field);
588 
589  /* no need for interlaced special case, data already reorganized in subimage_with_fill */
590  calc_plane_dct(fdsp, ctx->fill_y, blocks_y, mb_count << 5, mb_count, 0, 0);
591  calc_plane_dct(fdsp, ctx->fill_u, blocks_u, mb_count << (5 - ctx->is_422), mb_count, 1, ctx->is_422);
592  calc_plane_dct(fdsp, ctx->fill_v, blocks_v, mb_count << (5 - ctx->is_422), mb_count, 1, ctx->is_422);
593 
594  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
595  mb_count, buf + hdr_size, data_size - hdr_size,
596  &y_data_size, &u_data_size, &v_data_size,
597  *qp);
598  } else {
599  if (!is_interlaced) {
600  calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride, mb_count, 0, 0);
601  calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride, mb_count, 1, ctx->is_422);
602  calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride, mb_count, 1, ctx->is_422);
603  } else {
604  calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride * 2, mb_count, 0, 0);
605  calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride * 2, mb_count, 1, ctx->is_422);
606  calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride * 2, mb_count, 1, ctx->is_422);
607  }
608 
609  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
610  mb_count, buf + hdr_size, data_size - hdr_size,
611  &y_data_size, &u_data_size, &v_data_size,
612  *qp);
613 
614  if (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]) {
615  do {
616  *qp += 1;
617  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
618  mb_count, buf + hdr_size, data_size - hdr_size,
619  &y_data_size, &u_data_size, &v_data_size,
620  *qp);
621  } while (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]);
622  } else if (slice_size < low_bytes && *qp
623  > qp_start_table[avctx->profile]) {
624  do {
625  *qp -= 1;
626  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
627  mb_count, buf + hdr_size, data_size - hdr_size,
628  &y_data_size, &u_data_size, &v_data_size,
629  *qp);
630  } while (slice_size < low_bytes && *qp > qp_start_table[avctx->profile]);
631  }
632  }
633 
634  buf[0] = hdr_size << 3;
635  buf[1] = *qp;
636  AV_WB16(buf + 2, y_data_size);
637  AV_WB16(buf + 4, u_data_size);
638 
639  if (ctx->need_alpha) {
640  AV_WB16(buf + 6, v_data_size); /* write v data size only if there is alpha */
641 
642  subimage_alpha_with_fill((const uint16_t *) pic->data[3], mb_x << 4, mb_y << 4,
643  alpha_stride, avctx->width, avctx->height,
644  (uint16_t *) ctx->fill_a, mb_count << 4, 16, is_interlaced, is_top_field);
645  ret = encode_alpha_slice_data(avctx, ctx->fill_a, mb_count,
646  buf + hdr_size + slice_size,
647  data_size - hdr_size - slice_size, &a_data_size);
648  }
649 
650  if (ret != 0) {
651  return ret;
652  }
653  return hdr_size + y_data_size + u_data_size + v_data_size + a_data_size;
654 }
655 
656 static int prores_encode_picture(AVCodecContext *avctx, const AVFrame *pic,
657  uint8_t *buf, const int buf_size, const int picture_index, const int is_top_field)
658 {
659  ProresContext *ctx = avctx->priv_data;
660  int mb_width = (avctx->width + 15) >> 4;
661  int hdr_size, sl_size, i;
662  int mb_y, sl_data_size, qp, mb_height, picture_height, unsafe_mb_height_limit;
663  int unsafe_bot, unsafe_right;
664  uint8_t *sl_data, *sl_data_sizes;
665  int slice_per_line = 0, rem = mb_width;
666 
667  if (!ctx->is_interlaced) { /* progressive encoding */
668  mb_height = (avctx->height + 15) >> 4;
669  unsafe_mb_height_limit = mb_height;
670  } else {
671  if (is_top_field) {
672  picture_height = (avctx->height + 1) / 2;
673  } else {
674  picture_height = avctx->height / 2;
675  }
676  mb_height = (picture_height + 15) >> 4;
677  unsafe_mb_height_limit = mb_height;
678  }
679 
680  for (i = av_log2(DEFAULT_SLICE_MB_WIDTH); i >= 0; --i) {
681  slice_per_line += rem >> i;
682  rem &= (1 << i) - 1;
683  }
684 
685  qp = qp_start_table[avctx->profile];
686  hdr_size = 8; sl_data_size = buf_size - hdr_size;
687  sl_data_sizes = buf + hdr_size;
688  sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
689  for (mb_y = 0; mb_y < mb_height; mb_y++) {
690  int mb_x = 0;
691  int slice_mb_count = DEFAULT_SLICE_MB_WIDTH;
692  while (mb_x < mb_width) {
693  while (mb_width - mb_x < slice_mb_count)
694  slice_mb_count >>= 1;
695 
696  unsafe_bot = (avctx->height & 0xf) && (mb_y == unsafe_mb_height_limit - 1);
697  unsafe_right = (avctx->width & 0xf) && (mb_x + slice_mb_count == mb_width);
698 
699  sl_size = encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
700  sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp, ctx->is_interlaced, is_top_field);
701  if (sl_size < 0){
702  return sl_size;
703  }
704 
705  bytestream_put_be16(&sl_data_sizes, sl_size);
706  sl_data += sl_size;
707  sl_data_size -= sl_size;
708  mb_x += slice_mb_count;
709  }
710  }
711 
712  buf[0] = hdr_size << 3;
713  AV_WB32(buf + 1, sl_data - buf);
714  AV_WB16(buf + 5, slice_per_line * mb_height); /* picture size */
715  buf[7] = av_log2(DEFAULT_SLICE_MB_WIDTH) << 4; /* number of slices */
716 
717  return sl_data - buf;
718 }
719 
721  const AVFrame *pict, int *got_packet)
722 {
723  ProresContext *ctx = avctx->priv_data;
724  int header_size = 148;
725  uint8_t *buf;
726  int compress_frame_size, pic_size, ret, is_top_field_first = 0;
727  uint8_t frame_flags;
728  int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + AV_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit
729 
730 
732  return ret;
733 
734  buf = pkt->data;
735  compress_frame_size = 8 + header_size;
736 
737  bytestream_put_be32(&buf, compress_frame_size);/* frame size will be update after picture(s) encoding */
738  bytestream_put_buffer(&buf, "icpf", 4);
739 
740  bytestream_put_be16(&buf, header_size);
741  bytestream_put_be16(&buf, 0); /* version */
742  bytestream_put_buffer(&buf, ctx->vendor, 4);
743  bytestream_put_be16(&buf, avctx->width);
744  bytestream_put_be16(&buf, avctx->height);
745  frame_flags = 0x82; /* 422 not interlaced */
746  if (avctx->profile >= FF_PROFILE_PRORES_4444) /* 4444 or 4444 Xq */
747  frame_flags |= 0x40; /* 444 chroma */
748  if (ctx->is_interlaced) {
749  if (pict->top_field_first || !pict->interlaced_frame) { /* tff frame or progressive frame interpret as tff */
750  av_log(avctx, AV_LOG_DEBUG, "use interlaced encoding, top field first\n");
751  frame_flags |= 0x04; /* interlaced tff */
752  is_top_field_first = 1;
753  } else {
754  av_log(avctx, AV_LOG_DEBUG, "use interlaced encoding, bottom field first\n");
755  frame_flags |= 0x08; /* interlaced bff */
756  }
757  } else {
758  av_log(avctx, AV_LOG_DEBUG, "use progressive encoding\n");
759  }
760  *buf++ = frame_flags;
761  *buf++ = 0; /* reserved */
762  /* only write color properties, if valid value. set to unspecified otherwise */
763  *buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", pict->color_primaries, valid_primaries, 0);
764  *buf++ = ff_int_from_list_or_default(avctx, "frame color trc", pict->color_trc, valid_trc, 0);
765  *buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", pict->colorspace, valid_colorspace, 0);
766  if (avctx->profile >= FF_PROFILE_PRORES_4444) {
767  if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
768  *buf++ = 0xA0;/* src b64a and no alpha */
769  } else {
770  *buf++ = 0xA2;/* src b64a and 16b alpha */
771  }
772  } else {
773  *buf++ = 32;/* src v210 and no alpha */
774  }
775  *buf++ = 0; /* reserved */
776  *buf++ = 3; /* luma and chroma matrix present */
777 
778  bytestream_put_buffer(&buf, QMAT_LUMA[avctx->profile], 64);
779  bytestream_put_buffer(&buf, QMAT_CHROMA[avctx->profile], 64);
780 
781  pic_size = prores_encode_picture(avctx, pict, buf,
782  pkt->size - compress_frame_size, 0, is_top_field_first);/* encode progressive or first field */
783  if (pic_size < 0) {
784  return pic_size;
785  }
786  compress_frame_size += pic_size;
787 
788  if (ctx->is_interlaced) { /* encode second field */
789  pic_size = prores_encode_picture(avctx, pict, pkt->data + compress_frame_size,
790  pkt->size - compress_frame_size, 1, !is_top_field_first);
791  if (pic_size < 0) {
792  return pic_size;
793  }
794  compress_frame_size += pic_size;
795  }
796 
797  AV_WB32(pkt->data, compress_frame_size);/* update frame size */
798  pkt->size = compress_frame_size;
799  *got_packet = 1;
800 
801  return 0;
802 }
803 
804 static void scale_mat(const uint8_t* src, int* dst, int scale)
805 {
806  int i;
807  for (i = 0; i < 64; i++)
808  dst[i] = src[i] * scale;
809 }
810 
812 {
813  int i;
814  ProresContext* ctx = avctx->priv_data;
815 
816  avctx->bits_per_raw_sample = 10;
817  ctx->need_alpha = 0;
818  ctx->is_interlaced = !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT);
819  if (ctx->is_interlaced) {
820  ctx->scantable = ff_prores_interlaced_scan;
821  } else {
822  ctx->scantable = ff_prores_progressive_scan;
823  }
824 
825  if (avctx->width & 0x1) {
826  av_log(avctx, AV_LOG_ERROR,
827  "frame width needs to be multiple of 2\n");
828  return AVERROR(EINVAL);
829  }
830 
831  if (avctx->width > 65534 || avctx->height > 65535) {
832  av_log(avctx, AV_LOG_ERROR,
833  "The maximum dimensions are 65534x65535\n");
834  return AVERROR(EINVAL);
835  }
836 
837  if (strlen(ctx->vendor) != 4) {
838  av_log(avctx, AV_LOG_ERROR, "vendor ID should be 4 bytes\n");
839  return AVERROR(EINVAL);
840  }
841 
842  if (avctx->profile == FF_PROFILE_UNKNOWN) {
843  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10) {
845  av_log(avctx, AV_LOG_INFO,
846  "encoding with ProRes standard (apcn) profile\n");
847  } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
849  av_log(avctx, AV_LOG_INFO,
850  "encoding with ProRes 4444 (ap4h) profile\n");
851  } else if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P10) {
853  av_log(avctx, AV_LOG_INFO,
854  "encoding with ProRes 4444+ (ap4h) profile\n");
855  }
856  } else if (avctx->profile < FF_PROFILE_PRORES_PROXY
857  || avctx->profile > FF_PROFILE_PRORES_XQ) {
858  av_log(
859  avctx,
860  AV_LOG_ERROR,
861  "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch, 4 - ap4h, 5 - ap4x]\n",
862  avctx->profile);
863  return AVERROR(EINVAL);
864  } else if ((avctx->pix_fmt == AV_PIX_FMT_YUV422P10) && (avctx->profile > FF_PROFILE_PRORES_HQ)){
865  av_log(avctx, AV_LOG_ERROR,
866  "encoding with ProRes 444/Xq (ap4h/ap4x) profile, need YUV444P10 input\n");
867  return AVERROR(EINVAL);
868  } else if ((avctx->pix_fmt == AV_PIX_FMT_YUV444P10 || avctx->pix_fmt == AV_PIX_FMT_YUVA444P10)
869  && (avctx->profile < FF_PROFILE_PRORES_4444)){
870  av_log(avctx, AV_LOG_ERROR,
871  "encoding with ProRes Proxy/LT/422/422 HQ (apco, apcs, apcn, ap4h) profile, need YUV422P10 input\n");
872  return AVERROR(EINVAL);
873  }
874 
875  if (avctx->profile < FF_PROFILE_PRORES_4444) { /* 422 versions */
876  ctx->is_422 = 1;
877  if ((avctx->height & 0xf) || (avctx->width & 0xf)) {
878  ctx->fill_y = av_malloc(4 * (DEFAULT_SLICE_MB_WIDTH << 8));
879  if (!ctx->fill_y)
880  return AVERROR(ENOMEM);
881  ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9);
882  ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 8);
883  }
884  } else { /* 444 */
885  ctx->is_422 = 0;
886  if ((avctx->height & 0xf) || (avctx->width & 0xf)) {
887  ctx->fill_y = av_malloc(3 * (DEFAULT_SLICE_MB_WIDTH << 9));
888  if (!ctx->fill_y)
889  return AVERROR(ENOMEM);
890  ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9);
891  ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 9);
892  }
893  if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P10) {
894  ctx->need_alpha = 1;
895  ctx->fill_a = av_malloc(DEFAULT_SLICE_MB_WIDTH << 9); /* 8 blocks x 16px x 16px x sizeof (uint16) */
896  if (!ctx->fill_a)
897  return AVERROR(ENOMEM);
898  }
899  }
900 
901  ff_fdctdsp_init(&ctx->fdsp, avctx);
902 
903  avctx->codec_tag = AV_RL32((const uint8_t*)profiles[avctx->profile].name);
904 
905  for (i = 1; i <= 16; i++) {
906  scale_mat(QMAT_LUMA[avctx->profile] , ctx->qmat_luma[i - 1] , i);
907  scale_mat(QMAT_CHROMA[avctx->profile], ctx->qmat_chroma[i - 1], i);
908  }
909 
910  return 0;
911 }
912 
914 {
915  ProresContext* ctx = avctx->priv_data;
916  av_freep(&ctx->fill_y);
917  av_freep(&ctx->fill_a);
918 
919  return 0;
920 }
921 
922 #define OFFSET(x) offsetof(ProresContext, x)
923 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
924 
925 static const AVOption options[] = {
926  { "vendor", "vendor ID", OFFSET(vendor), AV_OPT_TYPE_STRING, { .str = "fmpg" }, 0, 0, VE },
927  { NULL }
928 };
929 
930 static const AVClass prores_enc_class = {
931  .class_name = "ProRes encoder",
932  .item_name = av_default_item_name,
933  .option = options,
934  .version = LIBAVUTIL_VERSION_INT,
935 };
936 
937 static const enum AVPixelFormat pix_fmts[] = {
940 };
941 
943  .p.name = "prores_aw",
944  CODEC_LONG_NAME("Apple ProRes"),
945  .p.type = AVMEDIA_TYPE_VIDEO,
946  .p.id = AV_CODEC_ID_PRORES,
947  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
949  .p.pix_fmts = pix_fmts,
950  .priv_data_size = sizeof(ProresContext),
952  .close = prores_encode_close,
954  .p.priv_class = &prores_enc_class,
956  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
957 };
958 
960  .p.name = "prores",
961  CODEC_LONG_NAME("Apple ProRes"),
962  .p.type = AVMEDIA_TYPE_VIDEO,
963  .p.id = AV_CODEC_ID_PRORES,
964  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
966  .p.pix_fmts = pix_fmts,
967  .priv_data_size = sizeof(ProresContext),
969  .close = prores_encode_close,
971  .p.priv_class = &prores_enc_class,
973  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
974 };
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:596
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
FF_PROFILE_PRORES_XQ
#define FF_PROFILE_PRORES_XQ
Definition: avcodec.h:1678
level
uint8_t level
Definition: svq3.c:204
subimage_with_fill_template
static void subimage_with_fill_template(const uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_alpha_plane, int is_interlaced, int is_top_field)
Definition: proresenc_anatoliy.c:475
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
TO_GOLOMB2
#define TO_GOLOMB2(val, sign)
Definition: proresenc_anatoliy.c:233
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ProresContext::fdsp
FDCTDSPContext fdsp
Definition: proresenc_anatoliy.c:184
mem_internal.h
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
ff_prores_profiles
const AVProfile ff_prores_profiles[]
Definition: profiles.c:159
AVProfile::name
const char * name
short name for the profile
Definition: codec.h:178
encode_ac_coeffs
static void encode_ac_coeffs(PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat, const uint8_t ff_prores_scan[64])
Definition: proresenc_anatoliy.c:276
options
static const AVOption options[]
Definition: proresenc_anatoliy.c:925
prores_encode_picture
static int prores_encode_picture(AVCodecContext *avctx, const AVFrame *pic, uint8_t *buf, const int buf_size, const int picture_index, const int is_top_field)
Definition: proresenc_anatoliy.c:656
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:281
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
prores_enc_class
static const AVClass prores_enc_class
Definition: proresenc_anatoliy.c:930
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:594
av_mod_uintp2
#define av_mod_uintp2
Definition: common.h:122
ProresContext::vendor
char * vendor
Definition: proresenc_anatoliy.c:198
encode_slice
static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, int mb_x, int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size, int unsafe, int *qp, int is_interlaced, int is_top_field)
Definition: proresenc_anatoliy.c:538
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:603
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:368
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:221
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVFrame::top_field_first
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:491
AVOption
AVOption.
Definition: opt.h:251
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1635
ProresContext
Definition: proresdec.h:38
FFCodec
Definition: codec_internal.h:127
encode_alpha_slice_data
static av_always_inline int encode_alpha_slice_data(AVCodecContext *avctx, int8_t *src_a, unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned *a_data_size)
Definition: proresenc_anatoliy.c:434
VE
#define VE
Definition: proresenc_anatoliy.c:923
prores_encode_init
static av_cold int prores_encode_init(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:811
ff_prores_progressive_scan
const uint8_t ff_prores_progressive_scan[64]
Definition: proresdata.c:25
FIRST_DC_CB
#define FIRST_DC_CB
Definition: proresenc_anatoliy.c:241
encode_dc_coeffs
static void encode_dc_coeffs(PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat)
Definition: proresenc_anatoliy.c:245
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AVProfile
AVProfile.
Definition: codec.h:176
QMAT_CHROMA
static const uint8_t QMAT_CHROMA[6][64]
Definition: proresenc_anatoliy.c:123
FDCTDSPContext
Definition: fdctdsp.h:26
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ff_prores_aw_encoder
const FFCodec ff_prores_aw_encoder
Definition: proresenc_anatoliy.c:942
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:125
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:506
val
static double val(void *priv, double ch)
Definition: aeval.c:77
qp_start_table
static const int qp_start_table[]
Definition: proresenc_anatoliy.c:54
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
FF_PROFILE_PRORES_LT
#define FF_PROFILE_PRORES_LT
Definition: avcodec.h:1674
AV_CODEC_FLAG_INTERLACED_DCT
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:309
bitrate_table
static const int bitrate_table[]
Definition: proresenc_anatoliy.c:56
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:462
lev_to_cb
static const uint8_t lev_to_cb[10]
Definition: proresenc_anatoliy.c:273
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
ff_fdctdsp_init
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Definition: fdctdsp.c:26
AVCOL_PRI_RESERVED0
@ AVCOL_PRI_RESERVED0
Definition: pixfmt.h:534
mask
static const uint16_t mask[17]
Definition: lzw.c:38
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:112
prores_encode_frame
static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: proresenc_anatoliy.c:720
width
#define width
ProresContext::fill_v
uint8_t * fill_v
Definition: proresenc_anatoliy.c:187
prores_encode_close
static av_cold int prores_encode_close(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:913
put_alpha_run
static void put_alpha_run(PutBitContext *pb, int run)
Definition: proresenc_anatoliy.c:421
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:594
frame_size
int frame_size
Definition: mxfenc.c:2205
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:156
FF_PROFILE_UNKNOWN
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1566
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1487
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_INPUT_BUFFER_MIN_SIZE
#define AV_INPUT_BUFFER_MIN_SIZE
Definition: avcodec.h:191
IS_NEGATIVE
#define IS_NEGATIVE(val)
Definition: proresenc_anatoliy.c:232
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: proresenc_anatoliy.c:937
ff_prores_interlaced_scan
const uint8_t ff_prores_interlaced_scan[64]
Definition: proresdata.c:36
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:536
PutBitContext
Definition: put_bits.h:50
valid_primaries
static const int valid_primaries[]
Definition: proresenc_anatoliy.c:58
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:540
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:541
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:107
scale_mat
static void scale_mat(const uint8_t *src, int *dst, int scale)
Definition: proresenc_anatoliy.c:804
AVCOL_TRC_RESERVED0
@ AVCOL_TRC_RESERVED0
Definition: pixfmt.h:559
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
TO_GOLOMB
#define TO_GOLOMB(val)
Definition: proresenc_anatoliy.c:230
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
PutBitContext::buf
uint8_t * buf
Definition: put_bits.h:53
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:203
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
ff_prores_encoder
const FFCodec ff_prores_encoder
Definition: proresenc_anatoliy.c:959
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:535
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
profiles.h
valid_trc
static const int valid_trc[]
Definition: proresenc_anatoliy.c:60
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:460
get
static void get(const uint8_t *pixels, int stride, int16_t *block)
Definition: proresenc_anatoliy.c:307
DEFAULT_SLICE_MB_WIDTH
#define DEFAULT_SLICE_MB_WIDTH
Definition: proresenc_anatoliy.c:42
exp
int8_t exp
Definition: eval.c:72
get_level
static av_always_inline int get_level(int val)
Definition: proresenc_anatoliy.c:235
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:544
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:575
ProresContext::fill_y
uint8_t * fill_y
Definition: proresenc_anatoliy.c:185
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:547
profiles
static const AVProfile profiles[]
Definition: proresenc_anatoliy.c:44
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
put_alpha_diff
static void put_alpha_diff(PutBitContext *pb, int cur, int prev)
Definition: proresenc_anatoliy.c:401
ProresContext::fill_a
uint8_t * fill_a
Definition: proresenc_anatoliy.c:188
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:301
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
ProresContext::scantable
const uint8_t * scantable
Definition: proresenc_anatoliy.c:192
FF_PROFILE_PRORES_HQ
#define FF_PROFILE_PRORES_HQ
Definition: avcodec.h:1676
codec_internal.h
FF_PROFILE_PRORES_STANDARD
#define FF_PROFILE_PRORES_STANDARD
Definition: avcodec.h:1675
calc_plane_dct
static void calc_plane_dct(FDCTDSPContext *fdsp, const uint8_t *src, int16_t *blocks, int src_stride, int mb_count, int chroma, int is_422)
Definition: proresenc_anatoliy.c:325
ProresContext::is_interlaced
int is_interlaced
Definition: proresenc_anatoliy.c:196
proresdata.h
ProresContext::is_422
int is_422
Definition: proresenc_anatoliy.c:194
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:162
height
#define height
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:498
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:560
AVFrame::interlaced_frame
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:486
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
subimage_with_fill
static void subimage_with_fill(const uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
Definition: proresenc_anatoliy.c:523
encode_slice_plane
static int encode_slice_plane(int16_t *blocks, int mb_count, uint8_t *buf, unsigned buf_size, int *qmat, int sub_sample_chroma, const uint8_t ff_prores_scan[64])
Definition: proresenc_anatoliy.c:362
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:598
delta
float delta
Definition: vorbis_enc_data.h:430
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
encode_codeword
static void encode_codeword(PutBitContext *pb, int val, int codebook)
Definition: proresenc_anatoliy.c:201
fdctdsp.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
dc_codebook
static const uint8_t dc_codebook[7]
Definition: proresenc_anatoliy.c:243
OFFSET
#define OFFSET(x)
Definition: proresenc_anatoliy.c:922
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:590
fdct_get
static void fdct_get(FDCTDSPContext *fdsp, const uint8_t *pixels, int stride, int16_t *block)
Definition: proresenc_anatoliy.c:319
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
qp_end_table
static const int qp_end_table[]
Definition: proresenc_anatoliy.c:55
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
ProresContext::need_alpha
int need_alpha
Definition: proresenc_anatoliy.c:195
ret
ret
Definition: filter_design.txt:187
QSCALE
#define QSCALE(qmat, ind, val)
Definition: proresenc_anatoliy.c:229
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
FF_PROFILE_PRORES_4444
#define FF_PROFILE_PRORES_4444
Definition: avcodec.h:1677
FF_PROFILE_PRORES_PROXY
#define FF_PROFILE_PRORES_PROXY
Definition: avcodec.h:1673
subimage_alpha_with_fill
static void subimage_alpha_with_fill(const uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
Definition: proresenc_anatoliy.c:531
encode_slice_data
static av_always_inline unsigned encode_slice_data(AVCodecContext *avctx, int16_t *blocks_y, int16_t *blocks_u, int16_t *blocks_v, unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned *y_data_size, unsigned *u_data_size, unsigned *v_data_size, int qp)
Definition: proresenc_anatoliy.c:378
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
ProresContext::fill_u
uint8_t * fill_u
Definition: proresenc_anatoliy.c:186
AVCodecContext
main external API structure.
Definition: avcodec.h:426
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:579
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1565
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
QMAT_LUMA
static const uint8_t QMAT_LUMA[6][64]
Definition: proresenc_anatoliy.c:65
valid_colorspace
static const int valid_colorspace[]
Definition: proresenc_anatoliy.c:62
FDCTDSPContext::fdct
void(* fdct)(int16_t *block)
Definition: fdctdsp.h:27
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:548
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:451
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
run_to_cb
static const uint8_t run_to_cb[16]
Definition: proresenc_anatoliy.c:271
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
bytestream.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:375
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_WN64
#define AV_WN64(p, v)
Definition: intreadwrite.h:380
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:589
put_bits.h
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:35
codebook
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
DIFF_SIGN
#define DIFF_SIGN(val, sign)
Definition: proresenc_anatoliy.c:231
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200
ff_int_from_list_or_default
int ff_int_from_list_or_default(void *ctx, const char *val_name, int val, const int *array_valid_values, int default_value)
Check if a value is in the list.
Definition: utils.c:1153