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 "profiles.h"
36 #include "proresdata.h"
37 #include "put_bits.h"
38 #include "bytestream.h"
39 #include "fdctdsp.h"
40 
41 #define DEFAULT_SLICE_MB_WIDTH 8
42 
43 static const AVProfile profiles[] = {
44  { AV_PROFILE_PRORES_PROXY, "apco"},
45  { AV_PROFILE_PRORES_LT, "apcs"},
46  { AV_PROFILE_PRORES_STANDARD, "apcn"},
47  { AV_PROFILE_PRORES_HQ, "apch"},
48  { AV_PROFILE_PRORES_4444, "ap4h"},
49  { AV_PROFILE_PRORES_XQ, "ap4x"},
51 };
52 
53 static const int qp_start_table[] = { 8, 3, 2, 1, 1, 1};
54 static const int qp_end_table[] = { 13, 9, 6, 6, 5, 4};
55 static const int bitrate_table[] = { 1000, 2100, 3500, 5400, 7000, 10000};
56 
60  AVCOL_TRC_ARIB_STD_B67, INT_MAX };
62  AVCOL_SPC_BT2020_NCL, INT_MAX };
63 
64 static const uint8_t QMAT_LUMA[6][64] = {
65  {
66  4, 7, 9, 11, 13, 14, 15, 63,
67  7, 7, 11, 12, 14, 15, 63, 63,
68  9, 11, 13, 14, 15, 63, 63, 63,
69  11, 11, 13, 14, 63, 63, 63, 63,
70  11, 13, 14, 63, 63, 63, 63, 63,
71  13, 14, 63, 63, 63, 63, 63, 63,
72  13, 63, 63, 63, 63, 63, 63, 63,
73  63, 63, 63, 63, 63, 63, 63, 63
74  }, {
75  4, 5, 6, 7, 9, 11, 13, 15,
76  5, 5, 7, 8, 11, 13, 15, 17,
77  6, 7, 9, 11, 13, 15, 15, 17,
78  7, 7, 9, 11, 13, 15, 17, 19,
79  7, 9, 11, 13, 14, 16, 19, 23,
80  9, 11, 13, 14, 16, 19, 23, 29,
81  9, 11, 13, 15, 17, 21, 28, 35,
82  11, 13, 16, 17, 21, 28, 35, 41
83  }, {
84  4, 4, 5, 5, 6, 7, 7, 9,
85  4, 4, 5, 6, 7, 7, 9, 9,
86  5, 5, 6, 7, 7, 9, 9, 10,
87  5, 5, 6, 7, 7, 9, 9, 10,
88  5, 6, 7, 7, 8, 9, 10, 12,
89  6, 7, 7, 8, 9, 10, 12, 15,
90  6, 7, 7, 9, 10, 11, 14, 17,
91  7, 7, 9, 10, 11, 14, 17, 21
92  }, {
93  4, 4, 4, 4, 4, 4, 4, 4,
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, 5,
97  4, 4, 4, 4, 4, 4, 5, 5,
98  4, 4, 4, 4, 4, 5, 5, 6,
99  4, 4, 4, 4, 5, 5, 6, 7,
100  4, 4, 4, 4, 5, 6, 7, 7
101  }, { /* 444 */
102  4, 4, 4, 4, 4, 4, 4, 4,
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, 5,
106  4, 4, 4, 4, 4, 4, 5, 5,
107  4, 4, 4, 4, 4, 5, 5, 6,
108  4, 4, 4, 4, 5, 5, 6, 7,
109  4, 4, 4, 4, 5, 6, 7, 7
110  }, { /* 444 XQ */
111  2, 2, 2, 2, 2, 2, 2, 2,
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, 3,
115  2, 2, 2, 2, 2, 2, 3, 3,
116  2, 2, 2, 2, 2, 3, 3, 3,
117  2, 2, 2, 2, 3, 3, 3, 4,
118  2, 2, 2, 2, 3, 3, 4, 4,
119  }
120 };
121 
122 static const uint8_t QMAT_CHROMA[6][64] = {
123  {
124  4, 7, 9, 11, 13, 14, 63, 63,
125  7, 7, 11, 12, 14, 63, 63, 63,
126  9, 11, 13, 14, 63, 63, 63, 63,
127  11, 11, 13, 14, 63, 63, 63, 63,
128  11, 13, 14, 63, 63, 63, 63, 63,
129  13, 14, 63, 63, 63, 63, 63, 63,
130  13, 63, 63, 63, 63, 63, 63, 63,
131  63, 63, 63, 63, 63, 63, 63, 63
132  }, {
133  4, 5, 6, 7, 9, 11, 13, 15,
134  5, 5, 7, 8, 11, 13, 15, 17,
135  6, 7, 9, 11, 13, 15, 15, 17,
136  7, 7, 9, 11, 13, 15, 17, 19,
137  7, 9, 11, 13, 14, 16, 19, 23,
138  9, 11, 13, 14, 16, 19, 23, 29,
139  9, 11, 13, 15, 17, 21, 28, 35,
140  11, 13, 16, 17, 21, 28, 35, 41
141  }, {
142  4, 4, 5, 5, 6, 7, 7, 9,
143  4, 4, 5, 6, 7, 7, 9, 9,
144  5, 5, 6, 7, 7, 9, 9, 10,
145  5, 5, 6, 7, 7, 9, 9, 10,
146  5, 6, 7, 7, 8, 9, 10, 12,
147  6, 7, 7, 8, 9, 10, 12, 15,
148  6, 7, 7, 9, 10, 11, 14, 17,
149  7, 7, 9, 10, 11, 14, 17, 21
150  }, {
151  4, 4, 4, 4, 4, 4, 4, 4,
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, 5,
155  4, 4, 4, 4, 4, 4, 5, 5,
156  4, 4, 4, 4, 4, 5, 5, 6,
157  4, 4, 4, 4, 5, 5, 6, 7,
158  4, 4, 4, 4, 5, 6, 7, 7
159  }, { /* 444 */
160  4, 4, 4, 4, 4, 4, 4, 4,
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, 5,
164  4, 4, 4, 4, 4, 4, 5, 5,
165  4, 4, 4, 4, 4, 5, 5, 6,
166  4, 4, 4, 4, 5, 5, 6, 7,
167  4, 4, 4, 4, 5, 6, 7, 7
168  }, { /* 444 xq */
169  4, 4, 4, 4, 4, 4, 4, 4,
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, 5,
173  4, 4, 4, 4, 4, 4, 5, 5,
174  4, 4, 4, 4, 4, 5, 5, 6,
175  4, 4, 4, 4, 5, 5, 6, 7,
176  4, 4, 4, 4, 5, 6, 7, 7
177  }
178 };
179 
180 
181 typedef struct {
182  AVClass *class;
184  uint8_t* fill_y;
185  uint8_t* fill_u;
186  uint8_t* fill_v;
187  uint8_t* fill_a;
188 
189  int qmat_luma[16][64];
190  int qmat_chroma[16][64];
191  const uint8_t *scantable;
192 
193  int is_422;
196 
197  char *vendor;
198 } ProresContext;
199 
200 /**
201  * Check if a value is in the list. If not, return the default value
202  *
203  * @param ctx Context for the log msg
204  * @param val_name Name of the checked value, for log msg
205  * @param array_valid_values Array of valid int, ended with INT_MAX
206  * @param default_value Value return if checked value is not in the array
207  * @return Value or default_value.
208  */
209 static int int_from_list_or_default(void *ctx, const char *val_name, int val,
210  const int *array_valid_values, int default_value)
211 {
212  int i = 0;
213 
214  while (1) {
215  int ref_val = array_valid_values[i];
216  if (ref_val == INT_MAX)
217  break;
218  if (val == ref_val)
219  return val;
220  i++;
221  }
222  /* val is not a valid value */
224  "%s %d are not supported. Set to default value : %d\n",
225  val_name, val, default_value);
226  return default_value;
227 }
228 
229 static void encode_codeword(PutBitContext *pb, int val, int codebook)
230 {
231  unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros;
232 
233  /* number of bits to switch between rice and exp golomb */
234  switch_bits = codebook & 3;
235  rice_order = codebook >> 5;
236  exp_order = (codebook >> 2) & 7;
237 
238  first_exp = ((switch_bits + 1) << rice_order);
239 
240  if (val >= first_exp) { /* exp golomb */
241  val -= first_exp;
242  val += (1 << exp_order);
243  exp = av_log2(val);
244  zeros = exp - exp_order + switch_bits + 1;
245  put_bits(pb, zeros, 0);
246  put_bits(pb, exp + 1, val);
247  } else if (rice_order) {
248  put_bits(pb, (val >> rice_order), 0);
249  put_bits(pb, 1, 1);
250  put_sbits(pb, rice_order, val);
251  } else {
252  put_bits(pb, val, 0);
253  put_bits(pb, 1, 1);
254  }
255 }
256 
257 #define QSCALE(qmat,ind,val) ((val) / ((qmat)[ind]))
258 #define TO_GOLOMB(val) (((val) * 2) ^ ((val) >> 31))
259 #define DIFF_SIGN(val, sign) (((val) >> 31) ^ (sign))
260 #define IS_NEGATIVE(val) ((((val) >> 31) ^ -1) + 1)
261 #define TO_GOLOMB2(val,sign) ((val)==0 ? 0 : ((val) << 1) + (sign))
262 
264 {
265  int sign = (val >> 31);
266  return (val ^ sign) - sign;
267 }
268 
269 #define FIRST_DC_CB 0xB8
270 
271 static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
272 
273 static void encode_dc_coeffs(PutBitContext *pb, int16_t *in,
274  int blocks_per_slice, int *qmat)
275 {
276  int prev_dc, code;
277  int i, sign, idx;
278  int new_dc, delta, diff_sign, new_code;
279 
280  prev_dc = QSCALE(qmat, 0, in[0] - 16384);
281  code = TO_GOLOMB(prev_dc);
283 
284  code = 5; sign = 0; idx = 64;
285  for (i = 1; i < blocks_per_slice; i++, idx += 64) {
286  new_dc = QSCALE(qmat, 0, in[idx] - 16384);
287  delta = new_dc - prev_dc;
288  diff_sign = DIFF_SIGN(delta, sign);
289  new_code = TO_GOLOMB2(get_level(delta), diff_sign);
290 
291  encode_codeword(pb, new_code, dc_codebook[FFMIN(code, 6)]);
292 
293  code = new_code;
294  sign = delta >> 31;
295  prev_dc = new_dc;
296  }
297 }
298 
299 static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29,
300  0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
301 static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28,
302  0x28, 0x28, 0x28, 0x4C };
303 
305  int16_t *in, int blocks_per_slice, int *qmat, const uint8_t ff_prores_scan[64])
306 {
307  int prev_run = 4;
308  int prev_level = 2;
309 
310  int run = 0, level, code, i, j;
311  for (i = 1; i < 64; i++) {
312  int indp = ff_prores_scan[i];
313  for (j = 0; j < blocks_per_slice; j++) {
314  int val = QSCALE(qmat, indp, in[(j << 6) + indp]);
315  if (val) {
316  encode_codeword(pb, run, run_to_cb[FFMIN(prev_run, 15)]);
317 
318  prev_run = run;
319  run = 0;
320  level = get_level(val);
321  code = level - 1;
322 
323  encode_codeword(pb, code, lev_to_cb[FFMIN(prev_level, 9)]);
324 
325  prev_level = level;
326 
327  put_bits(pb, 1, IS_NEGATIVE(val));
328  } else {
329  ++run;
330  }
331  }
332  }
333 }
334 
335 static void get(const uint8_t *pixels, int stride, int16_t* block)
336 {
337  int i;
338 
339  for (i = 0; i < 8; i++) {
340  AV_WN64(block, AV_RN64(pixels));
341  AV_WN64(block+4, AV_RN64(pixels+8));
342  pixels += stride;
343  block += 8;
344  }
345 }
346 
347 static void fdct_get(FDCTDSPContext *fdsp, const uint8_t *pixels, int stride, int16_t* block)
348 {
349  get(pixels, stride, block);
350  fdsp->fdct(block);
351 }
352 
353 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)
354 {
355  int16_t *block;
356  int i;
357 
358  block = blocks;
359 
360  if (!chroma) { /* Luma plane */
361  for (i = 0; i < mb_count; i++) {
362  fdct_get(fdsp, src, src_stride, block + (0 << 6));
363  fdct_get(fdsp, src + 16, src_stride, block + (1 << 6));
364  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (2 << 6));
365  fdct_get(fdsp, src + 16 + 8 * src_stride, src_stride, block + (3 << 6));
366 
367  block += 256;
368  src += 32;
369  }
370  } else if (chroma && is_422){ /* chroma plane 422 */
371  for (i = 0; i < mb_count; i++) {
372  fdct_get(fdsp, src, src_stride, block + (0 << 6));
373  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (1 << 6));
374  block += (256 >> 1);
375  src += (32 >> 1);
376  }
377  } else { /* chroma plane 444 */
378  for (i = 0; i < mb_count; i++) {
379  fdct_get(fdsp, src, src_stride, block + (0 << 6));
380  fdct_get(fdsp, src + 8 * src_stride, src_stride, block + (1 << 6));
381  fdct_get(fdsp, src + 16, src_stride, block + (2 << 6));
382  fdct_get(fdsp, src + 16 + 8 * src_stride, src_stride, block + (3 << 6));
383 
384  block += 256;
385  src += 32;
386  }
387  }
388 }
389 
390 static int encode_slice_plane(int16_t *blocks, int mb_count, uint8_t *buf, unsigned buf_size, int *qmat, int sub_sample_chroma,
391  const uint8_t ff_prores_scan[64])
392 {
393  int blocks_per_slice;
394  PutBitContext pb;
395 
396  blocks_per_slice = mb_count << (2 - sub_sample_chroma);
397  init_put_bits(&pb, buf, buf_size);
398 
399  encode_dc_coeffs(&pb, blocks, blocks_per_slice, qmat);
400  encode_ac_coeffs(&pb, blocks, blocks_per_slice, qmat, ff_prores_scan);
401 
402  flush_put_bits(&pb);
403  return put_bits_ptr(&pb) - pb.buf;
404 }
405 
407  int16_t * blocks_y, int16_t * blocks_u, int16_t * blocks_v,
408  unsigned mb_count, uint8_t *buf, unsigned data_size,
409  unsigned* y_data_size, unsigned* u_data_size, unsigned* v_data_size,
410  int qp)
411 {
412  ProresContext* ctx = avctx->priv_data;
413 
414  *y_data_size = encode_slice_plane(blocks_y, mb_count,
415  buf, data_size, ctx->qmat_luma[qp - 1], 0, ctx->scantable);
416 
417  if (!(avctx->flags & AV_CODEC_FLAG_GRAY)) {
418  *u_data_size = encode_slice_plane(blocks_u, mb_count, buf + *y_data_size, data_size - *y_data_size,
419  ctx->qmat_chroma[qp - 1], ctx->is_422, ctx->scantable);
420 
421  *v_data_size = encode_slice_plane(blocks_v, mb_count, buf + *y_data_size + *u_data_size,
422  data_size - *y_data_size - *u_data_size,
423  ctx->qmat_chroma[qp - 1], ctx->is_422, ctx->scantable);
424  }
425 
426  return *y_data_size + *u_data_size + *v_data_size;
427 }
428 
429 static void put_alpha_diff(PutBitContext *pb, int cur, int prev)
430 {
431  const int abits = 16;
432  const int dbits = 7;
433  const int dsize = 1 << dbits - 1;
434  int diff = cur - prev;
435 
436  diff = av_mod_uintp2(diff, abits);
437  if (diff >= (1 << abits) - dsize)
438  diff -= 1 << abits;
439  if (diff < -dsize || diff > dsize || !diff) {
440  put_bits(pb, 1, 1);
441  put_bits(pb, abits, diff);
442  } else {
443  put_bits(pb, 1, 0);
444  put_bits(pb, dbits - 1, FFABS(diff) - 1);
445  put_bits(pb, 1, diff < 0);
446  }
447 }
448 
449 static inline void put_alpha_run(PutBitContext *pb, int run)
450 {
451  if (run) {
452  put_bits(pb, 1, 0);
453  if (run < 0x10)
454  put_bits(pb, 4, run);
455  else
456  put_bits(pb, 15, run);
457  } else {
458  put_bits(pb, 1, 1);
459  }
460 }
461 
462 static av_always_inline int encode_alpha_slice_data(AVCodecContext *avctx, int8_t * src_a,
463  unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned* a_data_size)
464 {
465  const int abits = 16;
466  const int mask = (1 << abits) - 1;
467  const int num_coeffs = mb_count * 256;
468  int prev = mask, cur;
469  int idx = 0;
470  int run = 0;
471  int16_t * blocks = (int16_t *)src_a;
472  PutBitContext pb;
473  init_put_bits(&pb, buf, data_size);
474 
475  cur = blocks[idx++];
476  put_alpha_diff(&pb, cur, prev);
477  prev = cur;
478  do {
479  cur = blocks[idx++];
480  if (cur != prev) {
481  put_alpha_run (&pb, run);
482  put_alpha_diff(&pb, cur, prev);
483  prev = cur;
484  run = 0;
485  } else {
486  run++;
487  }
488  } while (idx < num_coeffs);
489  if (run)
490  put_alpha_run(&pb, run);
491  flush_put_bits(&pb);
492  *a_data_size = put_bytes_output(&pb);
493 
494  if (put_bits_left(&pb) < 0) {
495  av_log(avctx, AV_LOG_ERROR,
496  "Underestimated required buffer size.\n");
497  return AVERROR_BUG;
498  } else {
499  return 0;
500  }
501 }
502 
503 static inline void subimage_with_fill_template(const uint16_t *src, unsigned x, unsigned y,
504  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
505  unsigned dst_width, unsigned dst_height, int is_alpha_plane,
506  int is_interlaced, int is_top_field)
507 {
508  int box_width = FFMIN(width - x, dst_width);
509  int i, j, src_stride, box_height;
510  uint16_t last_pix, *last_line;
511 
512  if (!is_interlaced) {
513  src_stride = stride >> 1;
514  src += y * src_stride + x;
515  box_height = FFMIN(height - y, dst_height);
516  } else {
517  src_stride = stride; /* 2 lines stride */
518  src += y * src_stride + x;
519  box_height = FFMIN(height/2 - y, dst_height);
520  if (!is_top_field)
521  src += stride >> 1;
522  }
523 
524  for (i = 0; i < box_height; ++i) {
525  for (j = 0; j < box_width; ++j) {
526  if (!is_alpha_plane) {
527  dst[j] = src[j];
528  } else {
529  dst[j] = src[j] << 6; /* alpha 10b to 16b */
530  }
531  }
532  if (!is_alpha_plane) {
533  last_pix = dst[j - 1];
534  } else {
535  last_pix = dst[j - 1] << 6; /* alpha 10b to 16b */
536  }
537  for (; j < dst_width; j++)
538  dst[j] = last_pix;
539  src += src_stride;
540  dst += dst_width;
541  }
542  last_line = dst - dst_width;
543  for (; i < dst_height; i++) {
544  for (j = 0; j < dst_width; ++j) {
545  dst[j] = last_line[j];
546  }
547  dst += dst_width;
548  }
549 }
550 
551 static void subimage_with_fill(const uint16_t *src, unsigned x, unsigned y,
552  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
553  unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
554 {
555  subimage_with_fill_template(src, x, y, stride, width, height, dst, dst_width, dst_height, 0, is_interlaced, is_top_field);
556 }
557 
558 /* reorganize alpha data and convert 10b -> 16b */
559 static void subimage_alpha_with_fill(const uint16_t *src, unsigned x, unsigned y,
560  unsigned stride, unsigned width, unsigned height, uint16_t *dst,
561  unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
562 {
563  subimage_with_fill_template(src, x, y, stride, width, height, dst, dst_width, dst_height, 1, is_interlaced, is_top_field);
564 }
565 
566 static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, int mb_x,
567  int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size,
568  int unsafe, int *qp, int is_interlaced, int is_top_field)
569 {
570  int luma_stride, chroma_stride, alpha_stride = 0;
571  ProresContext* ctx = avctx->priv_data;
572  int hdr_size = 6 + (ctx->need_alpha * 2); /* v data size is write when there is alpha */
573  int ret = 0, slice_size;
574  const uint8_t *dest_y, *dest_u, *dest_v;
575  unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0, a_data_size = 0;
576  FDCTDSPContext *fdsp = &ctx->fdsp;
577  int tgt_bits = (mb_count * bitrate_table[avctx->profile]) >> 2;
578  int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3; // 12% bitrate fluctuation
579  int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3;
580 
581  LOCAL_ALIGNED(16, int16_t, blocks_y, [DEFAULT_SLICE_MB_WIDTH << 8]);
582  LOCAL_ALIGNED(16, int16_t, blocks_u, [DEFAULT_SLICE_MB_WIDTH << 8]);
583  LOCAL_ALIGNED(16, int16_t, blocks_v, [DEFAULT_SLICE_MB_WIDTH << 8]);
584 
585  luma_stride = pic->linesize[0];
586  chroma_stride = pic->linesize[1];
587 
588  if (ctx->need_alpha)
589  alpha_stride = pic->linesize[3];
590 
591  if (!is_interlaced) {
592  dest_y = pic->data[0] + (mb_y << 4) * luma_stride + (mb_x << 5);
593  dest_u = pic->data[1] + (mb_y << 4) * chroma_stride + (mb_x << (5 - ctx->is_422));
594  dest_v = pic->data[2] + (mb_y << 4) * chroma_stride + (mb_x << (5 - ctx->is_422));
595  } else {
596  dest_y = pic->data[0] + (mb_y << 4) * luma_stride * 2 + (mb_x << 5);
597  dest_u = pic->data[1] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 - ctx->is_422));
598  dest_v = pic->data[2] + (mb_y << 4) * chroma_stride * 2 + (mb_x << (5 - ctx->is_422));
599  if (!is_top_field){ /* bottom field, offset dest */
600  dest_y += luma_stride;
601  dest_u += chroma_stride;
602  dest_v += chroma_stride;
603  }
604  }
605 
606  if (unsafe) {
607  subimage_with_fill((const uint16_t *) pic->data[0], mb_x << 4, mb_y << 4,
608  luma_stride, avctx->width, avctx->height,
609  (uint16_t *) ctx->fill_y, mb_count << 4, 16, is_interlaced, is_top_field);
610  subimage_with_fill((const uint16_t *) pic->data[1], mb_x << (4 - ctx->is_422), mb_y << 4,
611  chroma_stride, avctx->width >> ctx->is_422, avctx->height,
612  (uint16_t *) ctx->fill_u, mb_count << (4 - ctx->is_422), 16, is_interlaced, is_top_field);
613  subimage_with_fill((const uint16_t *) pic->data[2], mb_x << (4 - ctx->is_422), mb_y << 4,
614  chroma_stride, avctx->width >> ctx->is_422, avctx->height,
615  (uint16_t *) ctx->fill_v, mb_count << (4 - ctx->is_422), 16, is_interlaced, is_top_field);
616 
617  /* no need for interlaced special case, data already reorganized in subimage_with_fill */
618  calc_plane_dct(fdsp, ctx->fill_y, blocks_y, mb_count << 5, mb_count, 0, 0);
619  calc_plane_dct(fdsp, ctx->fill_u, blocks_u, mb_count << (5 - ctx->is_422), mb_count, 1, ctx->is_422);
620  calc_plane_dct(fdsp, ctx->fill_v, blocks_v, mb_count << (5 - ctx->is_422), mb_count, 1, ctx->is_422);
621 
622  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
623  mb_count, buf + hdr_size, data_size - hdr_size,
624  &y_data_size, &u_data_size, &v_data_size,
625  *qp);
626  } else {
627  if (!is_interlaced) {
628  calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride, mb_count, 0, 0);
629  calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride, mb_count, 1, ctx->is_422);
630  calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride, mb_count, 1, ctx->is_422);
631  } else {
632  calc_plane_dct(fdsp, dest_y, blocks_y, luma_stride * 2, mb_count, 0, 0);
633  calc_plane_dct(fdsp, dest_u, blocks_u, chroma_stride * 2, mb_count, 1, ctx->is_422);
634  calc_plane_dct(fdsp, dest_v, blocks_v, chroma_stride * 2, mb_count, 1, ctx->is_422);
635  }
636 
637  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
638  mb_count, buf + hdr_size, data_size - hdr_size,
639  &y_data_size, &u_data_size, &v_data_size,
640  *qp);
641 
642  if (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]) {
643  do {
644  *qp += 1;
645  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
646  mb_count, buf + hdr_size, data_size - hdr_size,
647  &y_data_size, &u_data_size, &v_data_size,
648  *qp);
649  } while (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]);
650  } else if (slice_size < low_bytes && *qp
651  > qp_start_table[avctx->profile]) {
652  do {
653  *qp -= 1;
654  slice_size = encode_slice_data(avctx, blocks_y, blocks_u, blocks_v,
655  mb_count, buf + hdr_size, data_size - hdr_size,
656  &y_data_size, &u_data_size, &v_data_size,
657  *qp);
658  } while (slice_size < low_bytes && *qp > qp_start_table[avctx->profile]);
659  }
660  }
661 
662  buf[0] = hdr_size << 3;
663  buf[1] = *qp;
664  AV_WB16(buf + 2, y_data_size);
665  AV_WB16(buf + 4, u_data_size);
666 
667  if (ctx->need_alpha) {
668  AV_WB16(buf + 6, v_data_size); /* write v data size only if there is alpha */
669 
670  subimage_alpha_with_fill((const uint16_t *) pic->data[3], mb_x << 4, mb_y << 4,
671  alpha_stride, avctx->width, avctx->height,
672  (uint16_t *) ctx->fill_a, mb_count << 4, 16, is_interlaced, is_top_field);
673  ret = encode_alpha_slice_data(avctx, ctx->fill_a, mb_count,
674  buf + hdr_size + slice_size,
675  data_size - hdr_size - slice_size, &a_data_size);
676  }
677 
678  if (ret != 0) {
679  return ret;
680  }
681  return hdr_size + y_data_size + u_data_size + v_data_size + a_data_size;
682 }
683 
684 static int prores_encode_picture(AVCodecContext *avctx, const AVFrame *pic,
685  uint8_t *buf, const int buf_size, const int picture_index, const int is_top_field)
686 {
687  ProresContext *ctx = avctx->priv_data;
688  int mb_width = (avctx->width + 15) >> 4;
689  int hdr_size, sl_size, i;
690  int mb_y, sl_data_size, qp, mb_height, picture_height, unsafe_mb_height_limit;
691  int unsafe_bot, unsafe_right;
692  uint8_t *sl_data, *sl_data_sizes;
693  int slice_per_line = 0, rem = mb_width;
694 
695  if (!ctx->is_interlaced) { /* progressive encoding */
696  mb_height = (avctx->height + 15) >> 4;
697  unsafe_mb_height_limit = mb_height;
698  } else {
699  if (is_top_field) {
700  picture_height = (avctx->height + 1) / 2;
701  } else {
702  picture_height = avctx->height / 2;
703  }
704  mb_height = (picture_height + 15) >> 4;
705  unsafe_mb_height_limit = mb_height;
706  }
707 
708  for (i = av_log2(DEFAULT_SLICE_MB_WIDTH); i >= 0; --i) {
709  slice_per_line += rem >> i;
710  rem &= (1 << i) - 1;
711  }
712 
713  qp = qp_start_table[avctx->profile];
714  hdr_size = 8; sl_data_size = buf_size - hdr_size;
715  sl_data_sizes = buf + hdr_size;
716  sl_data = sl_data_sizes + (slice_per_line * mb_height * 2);
717  for (mb_y = 0; mb_y < mb_height; mb_y++) {
718  int mb_x = 0;
719  int slice_mb_count = DEFAULT_SLICE_MB_WIDTH;
720  while (mb_x < mb_width) {
721  while (mb_width - mb_x < slice_mb_count)
722  slice_mb_count >>= 1;
723 
724  unsafe_bot = (avctx->height & 0xf) && (mb_y == unsafe_mb_height_limit - 1);
725  unsafe_right = (avctx->width & 0xf) && (mb_x + slice_mb_count == mb_width);
726 
727  sl_size = encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count,
728  sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp, ctx->is_interlaced, is_top_field);
729  if (sl_size < 0){
730  return sl_size;
731  }
732 
733  bytestream_put_be16(&sl_data_sizes, sl_size);
734  sl_data += sl_size;
735  sl_data_size -= sl_size;
736  mb_x += slice_mb_count;
737  }
738  }
739 
740  buf[0] = hdr_size << 3;
741  AV_WB32(buf + 1, sl_data - buf);
742  AV_WB16(buf + 5, slice_per_line * mb_height); /* picture size */
743  buf[7] = av_log2(DEFAULT_SLICE_MB_WIDTH) << 4; /* number of slices */
744 
745  return sl_data - buf;
746 }
747 
749  const AVFrame *pict, int *got_packet)
750 {
751  ProresContext *ctx = avctx->priv_data;
752  int header_size = 148;
753  uint8_t *buf;
754  int compress_frame_size, pic_size, ret, is_top_field_first = 0;
755  uint8_t frame_flags;
756  int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + AV_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit
757 
758 
760  return ret;
761 
762  buf = pkt->data;
763  compress_frame_size = 8 + header_size;
764 
765  bytestream_put_be32(&buf, compress_frame_size);/* frame size will be update after picture(s) encoding */
766  bytestream_put_buffer(&buf, "icpf", 4);
767 
768  bytestream_put_be16(&buf, header_size);
769  bytestream_put_be16(&buf, 0); /* version */
770  bytestream_put_buffer(&buf, ctx->vendor, 4);
771  bytestream_put_be16(&buf, avctx->width);
772  bytestream_put_be16(&buf, avctx->height);
773  frame_flags = 0x82; /* 422 not interlaced */
774  if (avctx->profile >= AV_PROFILE_PRORES_4444) /* 4444 or 4444 Xq */
775  frame_flags |= 0x40; /* 444 chroma */
776  if (ctx->is_interlaced) {
778  /* tff frame or progressive frame interpret as tff */
779  av_log(avctx, AV_LOG_DEBUG, "use interlaced encoding, top field first\n");
780  frame_flags |= 0x04; /* interlaced tff */
781  is_top_field_first = 1;
782  } else {
783  av_log(avctx, AV_LOG_DEBUG, "use interlaced encoding, bottom field first\n");
784  frame_flags |= 0x08; /* interlaced bff */
785  }
786  } else {
787  av_log(avctx, AV_LOG_DEBUG, "use progressive encoding\n");
788  }
789  *buf++ = frame_flags;
790  *buf++ = 0; /* reserved */
791  /* only write color properties, if valid value. set to unspecified otherwise */
792  *buf++ = int_from_list_or_default(avctx, "frame color primaries",
793  pict->color_primaries, valid_primaries, 0);
794  *buf++ = int_from_list_or_default(avctx, "frame color trc",
795  pict->color_trc, valid_trc, 0);
796  *buf++ = int_from_list_or_default(avctx, "frame colorspace",
797  pict->colorspace, valid_colorspace, 0);
798  if (avctx->profile >= AV_PROFILE_PRORES_4444) {
799  if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
800  *buf++ = 0xA0;/* src b64a and no alpha */
801  } else {
802  *buf++ = 0xA2;/* src b64a and 16b alpha */
803  }
804  } else {
805  *buf++ = 32;/* src v210 and no alpha */
806  }
807  *buf++ = 0; /* reserved */
808  *buf++ = 3; /* luma and chroma matrix present */
809 
810  bytestream_put_buffer(&buf, QMAT_LUMA[avctx->profile], 64);
811  bytestream_put_buffer(&buf, QMAT_CHROMA[avctx->profile], 64);
812 
813  pic_size = prores_encode_picture(avctx, pict, buf,
814  pkt->size - compress_frame_size, 0, is_top_field_first);/* encode progressive or first field */
815  if (pic_size < 0) {
816  return pic_size;
817  }
818  compress_frame_size += pic_size;
819 
820  if (ctx->is_interlaced) { /* encode second field */
821  pic_size = prores_encode_picture(avctx, pict, pkt->data + compress_frame_size,
822  pkt->size - compress_frame_size, 1, !is_top_field_first);
823  if (pic_size < 0) {
824  return pic_size;
825  }
826  compress_frame_size += pic_size;
827  }
828 
829  AV_WB32(pkt->data, compress_frame_size);/* update frame size */
830  pkt->size = compress_frame_size;
831  *got_packet = 1;
832 
833  return 0;
834 }
835 
836 static void scale_mat(const uint8_t* src, int* dst, int scale)
837 {
838  int i;
839  for (i = 0; i < 64; i++)
840  dst[i] = src[i] * scale;
841 }
842 
844 {
845  int i;
846  ProresContext* ctx = avctx->priv_data;
847 
848  avctx->bits_per_raw_sample = 10;
849  ctx->need_alpha = 0;
850  ctx->is_interlaced = !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT);
851  if (ctx->is_interlaced) {
852  ctx->scantable = ff_prores_interlaced_scan;
853  } else {
854  ctx->scantable = ff_prores_progressive_scan;
855  }
856 
857  if (avctx->width & 0x1) {
858  av_log(avctx, AV_LOG_ERROR,
859  "frame width needs to be multiple of 2\n");
860  return AVERROR(EINVAL);
861  }
862 
863  if (avctx->width > 65534 || avctx->height > 65535) {
864  av_log(avctx, AV_LOG_ERROR,
865  "The maximum dimensions are 65534x65535\n");
866  return AVERROR(EINVAL);
867  }
868 
869  if (strlen(ctx->vendor) != 4) {
870  av_log(avctx, AV_LOG_ERROR, "vendor ID should be 4 bytes\n");
871  return AVERROR(EINVAL);
872  }
873 
874  if (avctx->profile == AV_PROFILE_UNKNOWN) {
875  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10) {
877  av_log(avctx, AV_LOG_INFO,
878  "encoding with ProRes standard (apcn) profile\n");
879  } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
881  av_log(avctx, AV_LOG_INFO,
882  "encoding with ProRes 4444 (ap4h) profile\n");
883  } else if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P10) {
885  av_log(avctx, AV_LOG_INFO,
886  "encoding with ProRes 4444+ (ap4h) profile\n");
887  }
888  } else if (avctx->profile < AV_PROFILE_PRORES_PROXY
889  || avctx->profile > AV_PROFILE_PRORES_XQ) {
890  av_log(
891  avctx,
892  AV_LOG_ERROR,
893  "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch, 4 - ap4h, 5 - ap4x]\n",
894  avctx->profile);
895  return AVERROR(EINVAL);
896  } else if ((avctx->pix_fmt == AV_PIX_FMT_YUV422P10) && (avctx->profile > AV_PROFILE_PRORES_HQ)){
897  av_log(avctx, AV_LOG_ERROR,
898  "encoding with ProRes 444/Xq (ap4h/ap4x) profile, need YUV444P10 input\n");
899  return AVERROR(EINVAL);
900  } else if ((avctx->pix_fmt == AV_PIX_FMT_YUV444P10 || avctx->pix_fmt == AV_PIX_FMT_YUVA444P10)
901  && (avctx->profile < AV_PROFILE_PRORES_4444)){
902  av_log(avctx, AV_LOG_ERROR,
903  "encoding with ProRes Proxy/LT/422/422 HQ (apco, apcs, apcn, ap4h) profile, need YUV422P10 input\n");
904  return AVERROR(EINVAL);
905  }
906 
907  if (avctx->profile < AV_PROFILE_PRORES_4444) { /* 422 versions */
908  ctx->is_422 = 1;
909  if ((avctx->height & 0xf) || (avctx->width & 0xf)) {
910  ctx->fill_y = av_malloc(4 * (DEFAULT_SLICE_MB_WIDTH << 8));
911  if (!ctx->fill_y)
912  return AVERROR(ENOMEM);
913  ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9);
914  ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 8);
915  }
916  } else { /* 444 */
917  ctx->is_422 = 0;
918  if ((avctx->height & 0xf) || (avctx->width & 0xf)) {
919  ctx->fill_y = av_malloc(3 * (DEFAULT_SLICE_MB_WIDTH << 9));
920  if (!ctx->fill_y)
921  return AVERROR(ENOMEM);
922  ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9);
923  ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 9);
924  }
925  if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P10) {
926  ctx->need_alpha = 1;
927  ctx->fill_a = av_malloc(DEFAULT_SLICE_MB_WIDTH << 9); /* 8 blocks x 16px x 16px x sizeof (uint16) */
928  if (!ctx->fill_a)
929  return AVERROR(ENOMEM);
930  }
931  }
932 
933  ff_fdctdsp_init(&ctx->fdsp, avctx);
934 
935  avctx->codec_tag = AV_RL32((const uint8_t*)profiles[avctx->profile].name);
936 
937  for (i = 1; i <= 16; i++) {
938  scale_mat(QMAT_LUMA[avctx->profile] , ctx->qmat_luma[i - 1] , i);
939  scale_mat(QMAT_CHROMA[avctx->profile], ctx->qmat_chroma[i - 1], i);
940  }
941 
942  return 0;
943 }
944 
946 {
947  ProresContext* ctx = avctx->priv_data;
948  av_freep(&ctx->fill_y);
949  av_freep(&ctx->fill_a);
950 
951  return 0;
952 }
953 
954 #define OFFSET(x) offsetof(ProresContext, x)
955 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
956 
957 static const AVOption options[] = {
958  { "vendor", "vendor ID", OFFSET(vendor), AV_OPT_TYPE_STRING, { .str = "fmpg" }, 0, 0, VE },
959  { NULL }
960 };
961 
962 static const AVClass prores_enc_class = {
963  .class_name = "ProRes encoder",
964  .item_name = av_default_item_name,
965  .option = options,
966  .version = LIBAVUTIL_VERSION_INT,
967 };
968 
969 static const enum AVPixelFormat pix_fmts[] = {
972 };
973 
975  .p.name = "prores_aw",
976  CODEC_LONG_NAME("Apple ProRes"),
977  .p.type = AVMEDIA_TYPE_VIDEO,
978  .p.id = AV_CODEC_ID_PRORES,
979  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
981  .p.pix_fmts = pix_fmts,
982  .priv_data_size = sizeof(ProresContext),
984  .close = prores_encode_close,
986  .p.priv_class = &prores_enc_class,
988  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
989 };
990 
992  .p.name = "prores",
993  CODEC_LONG_NAME("Apple ProRes"),
994  .p.type = AVMEDIA_TYPE_VIDEO,
995  .p.id = AV_CODEC_ID_PRORES,
996  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
998  .p.pix_fmts = pix_fmts,
999  .priv_data_size = sizeof(ProresContext),
1001  .close = prores_encode_close,
1003  .p.priv_class = &prores_enc_class,
1005  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1006 };
int_from_list_or_default
static int 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: proresenc_anatoliy.c:209
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:660
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:503
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:261
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:183
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:172
AVProfile::name
const char * name
short name for the profile
Definition: codec.h:181
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:304
options
static const AVOption options[]
Definition: proresenc_anatoliy.c:957
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:684
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:962
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:658
av_mod_uintp2
#define av_mod_uintp2
Definition: common.h:123
ProresContext::vendor
char * vendor
Definition: proresenc_anatoliy.c:197
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:566
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:667
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:366
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
AVPacket::data
uint8_t * data
Definition: packet.h:491
AVOption
AVOption.
Definition: opt.h:251
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
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:1639
ProresContext
Definition: proresdec.h:43
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:462
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:649
VE
#define VE
Definition: proresenc_anatoliy.c:955
prores_encode_init
static av_cold int prores_encode_init(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:843
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:269
encode_dc_coeffs
static void encode_dc_coeffs(PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat)
Definition: proresenc_anatoliy.c:273
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_PROFILE_PRORES_STANDARD
#define AV_PROFILE_PRORES_STANDARD
Definition: defs.h:181
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:641
AVProfile
AVProfile.
Definition: codec.h:179
QMAT_CHROMA
static const uint8_t QMAT_CHROMA[6][64]
Definition: proresenc_anatoliy.c:122
AV_PROFILE_PRORES_HQ
#define AV_PROFILE_PRORES_HQ
Definition: defs.h:182
FDCTDSPContext
Definition: fdctdsp.h:28
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:974
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:521
val
static double val(void *priv, double ch)
Definition: aeval.c:78
qp_start_table
static const int qp_start_table[]
Definition: proresenc_anatoliy.c:53
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
AV_CODEC_FLAG_INTERLACED_DCT
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:326
bitrate_table
static const int bitrate_table[]
Definition: proresenc_anatoliy.c:55
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:471
lev_to_cb
static const uint8_t lev_to_cb[10]
Definition: proresenc_anatoliy.c:301
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:25
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
AVCOL_PRI_RESERVED0
@ AVCOL_PRI_RESERVED0
Definition: pixfmt.h:546
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:748
width
#define width
ProresContext::fill_v
uint8_t * fill_v
Definition: proresenc_anatoliy.c:186
prores_encode_close
static av_cold int prores_encode_close(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:945
put_alpha_run
static void put_alpha_run(PutBitContext *pb, int run)
Definition: proresenc_anatoliy.c:449
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:606
frame_size
int frame_size
Definition: mxfenc.c:2311
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:159
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1517
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:195
IS_NEGATIVE
#define IS_NEGATIVE(val)
Definition: proresenc_anatoliy.c:260
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: proresenc_anatoliy.c:969
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:548
PutBitContext
Definition: put_bits.h:50
valid_primaries
static const int valid_primaries[]
Definition: proresenc_anatoliy.c:57
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:552
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:553
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
scale_mat
static void scale_mat(const uint8_t *src, int *dst, int scale)
Definition: proresenc_anatoliy.c:836
AVCOL_TRC_RESERVED0
@ AVCOL_TRC_RESERVED0
Definition: pixfmt.h:571
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
TO_GOLOMB
#define TO_GOLOMB(val)
Definition: proresenc_anatoliy.c:258
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:403
ff_prores_encoder
const FFCodec ff_prores_encoder
Definition: proresenc_anatoliy.c:991
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:547
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:59
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:469
get
static void get(const uint8_t *pixels, int stride, int16_t *block)
Definition: proresenc_anatoliy.c:335
DEFAULT_SLICE_MB_WIDTH
#define DEFAULT_SLICE_MB_WIDTH
Definition: proresenc_anatoliy.c:41
exp
int8_t exp
Definition: eval.c:72
AV_PROFILE_PRORES_LT
#define AV_PROFILE_PRORES_LT
Definition: defs.h:180
get_level
static av_always_inline int get_level(int val)
Definition: proresenc_anatoliy.c:263
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:556
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:417
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:587
ProresContext::fill_y
uint8_t * fill_y
Definition: proresenc_anatoliy.c:184
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:559
profiles
static const AVProfile profiles[]
Definition: proresenc_anatoliy.c:43
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:429
ProresContext::fill_a
uint8_t * fill_a
Definition: proresenc_anatoliy.c:187
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:318
AVPacket::size
int size
Definition: packet.h:492
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:106
ProresContext::scantable
const uint8_t * scantable
Definition: proresenc_anatoliy.c:191
codec_internal.h
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:353
ProresContext::is_interlaced
int is_interlaced
Definition: proresenc_anatoliy.c:195
proresdata.h
ProresContext::is_422
int is_422
Definition: proresenc_anatoliy.c:193
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:164
AV_PROFILE_PRORES_4444
#define AV_PROFILE_PRORES_4444
Definition: defs.h:183
height
#define height
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:508
AV_PROFILE_PRORES_PROXY
#define AV_PROFILE_PRORES_PROXY
Definition: defs.h:179
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:572
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:551
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:390
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
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:610
delta
float delta
Definition: vorbis_enc_data.h:430
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:590
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:229
fdctdsp.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
dc_codebook
static const uint8_t dc_codebook[7]
Definition: proresenc_anatoliy.c:271
OFFSET
#define OFFSET(x)
Definition: proresenc_anatoliy.c:954
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:602
fdct_get
static void fdct_get(FDCTDSPContext *fdsp, const uint8_t *pixels, int stride, int16_t *block)
Definition: proresenc_anatoliy.c:347
AVCodecContext::height
int height
Definition: avcodec.h:621
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
qp_end_table
static const int qp_end_table[]
Definition: proresenc_anatoliy.c:54
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
ProresContext::need_alpha
int need_alpha
Definition: proresenc_anatoliy.c:194
ret
ret
Definition: filter_design.txt:187
QSCALE
#define QSCALE(qmat, ind, val)
Definition: proresenc_anatoliy.c:257
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
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:559
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:406
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:185
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:591
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:1596
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
QMAT_LUMA
static const uint8_t QMAT_LUMA[6][64]
Definition: proresenc_anatoliy.c:64
valid_colorspace
static const int valid_colorspace[]
Definition: proresenc_anatoliy.c:61
FDCTDSPContext::fdct
void(* fdct)(int16_t *block)
Definition: fdctdsp.h:29
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:560
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:466
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
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:299
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
bytestream.h
AV_PROFILE_PRORES_XQ
#define AV_PROFILE_PRORES_XQ
Definition: defs.h:184
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:385
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:378
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:601
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:61
codebook
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
DIFF_SIGN
#define DIFF_SIGN(val, sign)
Definition: proresenc_anatoliy.c:259
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200