FFmpeg  4.4.9
proresenc_kostya.c
Go to the documentation of this file.
1 /*
2  * Apple ProRes encoder
3  *
4  * Copyright (c) 2012 Konstantin Shishkov
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/mem_internal.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "avcodec.h"
27 #include "fdctdsp.h"
28 #include "put_bits.h"
29 #include "profiles.h"
30 #include "bytestream.h"
31 #include "internal.h"
32 #include "proresdata.h"
33 
34 #define CFACTOR_Y422 2
35 #define CFACTOR_Y444 3
36 
37 #define MAX_MBS_PER_SLICE 8
38 
39 #define MAX_PLANES 4
40 
41 enum {
49 };
50 
51 enum {
59 };
60 
61 static const uint8_t prores_quant_matrices[][64] = {
62  { // proxy
63  4, 7, 9, 11, 13, 14, 15, 63,
64  7, 7, 11, 12, 14, 15, 63, 63,
65  9, 11, 13, 14, 15, 63, 63, 63,
66  11, 11, 13, 14, 63, 63, 63, 63,
67  11, 13, 14, 63, 63, 63, 63, 63,
68  13, 14, 63, 63, 63, 63, 63, 63,
69  13, 63, 63, 63, 63, 63, 63, 63,
70  63, 63, 63, 63, 63, 63, 63, 63,
71  },
72  { // proxy chromas
73  4, 7, 9, 11, 13, 14, 63, 63,
74  7, 7, 11, 12, 14, 63, 63, 63,
75  9, 11, 13, 14, 63, 63, 63, 63,
76  11, 11, 13, 14, 63, 63, 63, 63,
77  11, 13, 14, 63, 63, 63, 63, 63,
78  13, 14, 63, 63, 63, 63, 63, 63,
79  13, 63, 63, 63, 63, 63, 63, 63,
80  63, 63, 63, 63, 63, 63, 63, 63
81  },
82  { // LT
83  4, 5, 6, 7, 9, 11, 13, 15,
84  5, 5, 7, 8, 11, 13, 15, 17,
85  6, 7, 9, 11, 13, 15, 15, 17,
86  7, 7, 9, 11, 13, 15, 17, 19,
87  7, 9, 11, 13, 14, 16, 19, 23,
88  9, 11, 13, 14, 16, 19, 23, 29,
89  9, 11, 13, 15, 17, 21, 28, 35,
90  11, 13, 16, 17, 21, 28, 35, 41,
91  },
92  { // standard
93  4, 4, 5, 5, 6, 7, 7, 9,
94  4, 4, 5, 6, 7, 7, 9, 9,
95  5, 5, 6, 7, 7, 9, 9, 10,
96  5, 5, 6, 7, 7, 9, 9, 10,
97  5, 6, 7, 7, 8, 9, 10, 12,
98  6, 7, 7, 8, 9, 10, 12, 15,
99  6, 7, 7, 9, 10, 11, 14, 17,
100  7, 7, 9, 10, 11, 14, 17, 21,
101  },
102  { // high quality
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  },
112  { // XQ luma
113  2, 2, 2, 2, 2, 2, 2, 2,
114  2, 2, 2, 2, 2, 2, 2, 2,
115  2, 2, 2, 2, 2, 2, 2, 2,
116  2, 2, 2, 2, 2, 2, 2, 3,
117  2, 2, 2, 2, 2, 2, 3, 3,
118  2, 2, 2, 2, 2, 3, 3, 3,
119  2, 2, 2, 2, 3, 3, 3, 4,
120  2, 2, 2, 2, 3, 3, 4, 4,
121  },
122  { // codec default
123  4, 4, 4, 4, 4, 4, 4, 4,
124  4, 4, 4, 4, 4, 4, 4, 4,
125  4, 4, 4, 4, 4, 4, 4, 4,
126  4, 4, 4, 4, 4, 4, 4, 4,
127  4, 4, 4, 4, 4, 4, 4, 4,
128  4, 4, 4, 4, 4, 4, 4, 4,
129  4, 4, 4, 4, 4, 4, 4, 4,
130  4, 4, 4, 4, 4, 4, 4, 4,
131  },
132 };
133 
134 #define NUM_MB_LIMITS 4
135 static const int prores_mb_limits[NUM_MB_LIMITS] = {
136  1620, // up to 720x576
137  2700, // up to 960x720
138  6075, // up to 1440x1080
139  9216, // up to 2048x1152
140 };
141 
142 static const struct prores_profile {
143  const char *full_name;
144  uint32_t tag;
148  int quant;
150 } prores_profile_info[6] = {
151  {
152  .full_name = "proxy",
153  .tag = MKTAG('a', 'p', 'c', 'o'),
154  .min_quant = 4,
155  .max_quant = 8,
156  .br_tab = { 300, 242, 220, 194 },
157  .quant = QUANT_MAT_PROXY,
158  .quant_chroma = QUANT_MAT_PROXY_CHROMA,
159  },
160  {
161  .full_name = "LT",
162  .tag = MKTAG('a', 'p', 'c', 's'),
163  .min_quant = 1,
164  .max_quant = 9,
165  .br_tab = { 720, 560, 490, 440 },
166  .quant = QUANT_MAT_LT,
167  .quant_chroma = QUANT_MAT_LT,
168  },
169  {
170  .full_name = "standard",
171  .tag = MKTAG('a', 'p', 'c', 'n'),
172  .min_quant = 1,
173  .max_quant = 6,
174  .br_tab = { 1050, 808, 710, 632 },
175  .quant = QUANT_MAT_STANDARD,
176  .quant_chroma = QUANT_MAT_STANDARD,
177  },
178  {
179  .full_name = "high quality",
180  .tag = MKTAG('a', 'p', 'c', 'h'),
181  .min_quant = 1,
182  .max_quant = 6,
183  .br_tab = { 1566, 1216, 1070, 950 },
184  .quant = QUANT_MAT_HQ,
185  .quant_chroma = QUANT_MAT_HQ,
186  },
187  {
188  .full_name = "4444",
189  .tag = MKTAG('a', 'p', '4', 'h'),
190  .min_quant = 1,
191  .max_quant = 6,
192  .br_tab = { 2350, 1828, 1600, 1425 },
193  .quant = QUANT_MAT_HQ,
194  .quant_chroma = QUANT_MAT_HQ,
195  },
196  {
197  .full_name = "4444XQ",
198  .tag = MKTAG('a', 'p', '4', 'x'),
199  .min_quant = 1,
200  .max_quant = 6,
201  .br_tab = { 3525, 2742, 2400, 2137 },
202  .quant = QUANT_MAT_HQ, /* Fix me : use QUANT_MAT_XQ_LUMA */
203  .quant_chroma = QUANT_MAT_HQ,
204  }
205 };
206 
207 #define TRELLIS_WIDTH 16
208 #define SCORE_LIMIT INT_MAX / 2
209 
210 struct TrellisNode {
212  int quant;
213  int bits;
214  int score;
215 };
216 
217 #define MAX_STORED_Q 16
218 
219 typedef struct ProresThreadData {
221  DECLARE_ALIGNED(16, uint16_t, emu_buf)[16 * 16];
222  int16_t custom_q[64];
223  int16_t custom_chroma_q[64];
226 
227 typedef struct ProresContext {
228  AVClass *class;
230  DECLARE_ALIGNED(16, uint16_t, emu_buf)[16*16];
231  int16_t quants[MAX_STORED_Q][64];
233  int16_t custom_q[64];
234  int16_t custom_chroma_q[64];
237  const uint8_t *scantable;
238 
239  void (*fdct)(FDCTDSPContext *fdsp, const uint16_t *src,
240  ptrdiff_t linesize, int16_t *block);
242 
243  const AVFrame *pic;
249  int pictures_per_frame; // 1 for progressive, 2 for interlaced
255  int warn;
256 
257  char *vendor;
259 
262 
263  int profile;
265 
266  int *slice_q;
267 
269 } ProresContext;
270 
271 static void get_slice_data(ProresContext *ctx, const uint16_t *src,
272  ptrdiff_t linesize, int x, int y, int w, int h,
273  int16_t *blocks, uint16_t *emu_buf,
274  int mbs_per_slice, int blocks_per_mb, int is_chroma)
275 {
276  const uint16_t *esrc;
277  const int mb_width = 4 * blocks_per_mb;
278  ptrdiff_t elinesize;
279  int i, j, k;
280 
281  for (i = 0; i < mbs_per_slice; i++, src += mb_width) {
282  if (x >= w) {
283  memset(blocks, 0, 64 * (mbs_per_slice - i) * blocks_per_mb
284  * sizeof(*blocks));
285  return;
286  }
287  if (x + mb_width <= w && y + 16 <= h) {
288  esrc = src;
289  elinesize = linesize;
290  } else {
291  int bw, bh, pix;
292 
293  esrc = emu_buf;
294  elinesize = 16 * sizeof(*emu_buf);
295 
296  bw = FFMIN(w - x, mb_width);
297  bh = FFMIN(h - y, 16);
298 
299  for (j = 0; j < bh; j++) {
300  memcpy(emu_buf + j * 16,
301  (const uint8_t*)src + j * linesize,
302  bw * sizeof(*src));
303  pix = emu_buf[j * 16 + bw - 1];
304  for (k = bw; k < mb_width; k++)
305  emu_buf[j * 16 + k] = pix;
306  }
307  for (; j < 16; j++)
308  memcpy(emu_buf + j * 16,
309  emu_buf + (bh - 1) * 16,
310  mb_width * sizeof(*emu_buf));
311  }
312  if (!is_chroma) {
313  ctx->fdct(&ctx->fdsp, esrc, elinesize, blocks);
314  blocks += 64;
315  if (blocks_per_mb > 2) {
316  ctx->fdct(&ctx->fdsp, esrc + 8, elinesize, blocks);
317  blocks += 64;
318  }
319  ctx->fdct(&ctx->fdsp, esrc + elinesize * 4, elinesize, blocks);
320  blocks += 64;
321  if (blocks_per_mb > 2) {
322  ctx->fdct(&ctx->fdsp, esrc + elinesize * 4 + 8, elinesize, blocks);
323  blocks += 64;
324  }
325  } else {
326  ctx->fdct(&ctx->fdsp, esrc, elinesize, blocks);
327  blocks += 64;
328  ctx->fdct(&ctx->fdsp, esrc + elinesize * 4, elinesize, blocks);
329  blocks += 64;
330  if (blocks_per_mb > 2) {
331  ctx->fdct(&ctx->fdsp, esrc + 8, elinesize, blocks);
332  blocks += 64;
333  ctx->fdct(&ctx->fdsp, esrc + elinesize * 4 + 8, elinesize, blocks);
334  blocks += 64;
335  }
336  }
337 
338  x += mb_width;
339  }
340 }
341 
342 static void get_alpha_data(ProresContext *ctx, const uint16_t *src,
343  ptrdiff_t linesize, int x, int y, int w, int h,
344  uint16_t *blocks, int mbs_per_slice, int abits)
345 {
346  const int slice_width = 16 * mbs_per_slice;
347  int i, j, copy_w, copy_h;
348 
349  copy_w = FFMIN(w - x, slice_width);
350  copy_h = FFMIN(h - y, 16);
351  for (i = 0; i < copy_h; i++) {
352  memcpy(blocks, src, copy_w * sizeof(*src));
353  if (abits == 8)
354  for (j = 0; j < copy_w; j++)
355  blocks[j] >>= 2;
356  else
357  for (j = 0; j < copy_w; j++)
358  blocks[j] = (blocks[j] << 6) | (blocks[j] >> 4);
359  for (j = copy_w; j < slice_width; j++)
360  blocks[j] = blocks[copy_w - 1];
361  blocks += slice_width;
362  src += linesize >> 1;
363  }
364  for (; i < 16; i++) {
365  memcpy(blocks, blocks - slice_width, slice_width * sizeof(*blocks));
366  blocks += slice_width;
367  }
368 }
369 
370 /**
371  * Write an unsigned rice/exp golomb codeword.
372  */
373 static inline void encode_vlc_codeword(PutBitContext *pb, unsigned codebook, int val)
374 {
375  unsigned int rice_order, exp_order, switch_bits, switch_val;
376  int exponent;
377 
378  /* number of prefix bits to switch between Rice and expGolomb */
379  switch_bits = (codebook & 3) + 1;
380  rice_order = codebook >> 5; /* rice code order */
381  exp_order = (codebook >> 2) & 7; /* exp golomb code order */
382 
383  switch_val = switch_bits << rice_order;
384 
385  if (val >= switch_val) {
386  val -= switch_val - (1 << exp_order);
387  exponent = av_log2(val);
388 
389  put_bits(pb, exponent - exp_order + switch_bits, 0);
390  put_bits(pb, exponent + 1, val);
391  } else {
392  exponent = val >> rice_order;
393 
394  if (exponent)
395  put_bits(pb, exponent, 0);
396  put_bits(pb, 1, 1);
397  if (rice_order)
398  put_sbits(pb, rice_order, val);
399  }
400 }
401 
402 #define GET_SIGN(x) ((x) >> 31)
403 #define MAKE_CODE(x) ((((x)) * 2) ^ GET_SIGN(x))
404 
405 static void encode_dcs(PutBitContext *pb, int16_t *blocks,
406  int blocks_per_slice, int scale)
407 {
408  int i;
409  int codebook = 3, code, dc, prev_dc, delta, sign, new_sign;
410 
411  prev_dc = (blocks[0] - 0x4000) / scale;
413  sign = 0;
414  codebook = 3;
415  blocks += 64;
416 
417  for (i = 1; i < blocks_per_slice; i++, blocks += 64) {
418  dc = (blocks[0] - 0x4000) / scale;
419  delta = dc - prev_dc;
420  new_sign = GET_SIGN(delta);
421  delta = (delta ^ sign) - sign;
422  code = MAKE_CODE(delta);
424  codebook = (code + (code & 1)) >> 1;
425  codebook = FFMIN(codebook, 3);
426  sign = new_sign;
427  prev_dc = dc;
428  }
429 }
430 
431 static void encode_acs(PutBitContext *pb, int16_t *blocks,
432  int blocks_per_slice,
433  int plane_size_factor,
434  const uint8_t *scan, const int16_t *qmat)
435 {
436  int idx, i;
437  int run, level, run_cb, lev_cb;
438  int max_coeffs, abs_level;
439 
440  max_coeffs = blocks_per_slice << 6;
441  run_cb = ff_prores_run_to_cb_index[4];
442  lev_cb = ff_prores_lev_to_cb_index[2];
443  run = 0;
444 
445  for (i = 1; i < 64; i++) {
446  for (idx = scan[i]; idx < max_coeffs; idx += 64) {
447  level = blocks[idx] / qmat[scan[i]];
448  if (level) {
449  abs_level = FFABS(level);
452  abs_level - 1);
453  put_sbits(pb, 1, GET_SIGN(level));
454 
455  run_cb = ff_prores_run_to_cb_index[FFMIN(run, 15)];
456  lev_cb = ff_prores_lev_to_cb_index[FFMIN(abs_level, 9)];
457  run = 0;
458  } else {
459  run++;
460  }
461  }
462  }
463 }
464 
466  const uint16_t *src, ptrdiff_t linesize,
467  int mbs_per_slice, int16_t *blocks,
468  int blocks_per_mb, int plane_size_factor,
469  const int16_t *qmat)
470 {
471  int blocks_per_slice, saved_pos;
472 
473  saved_pos = put_bits_count(pb);
474  blocks_per_slice = mbs_per_slice * blocks_per_mb;
475 
476  encode_dcs(pb, blocks, blocks_per_slice, qmat[0]);
477  encode_acs(pb, blocks, blocks_per_slice, plane_size_factor,
478  ctx->scantable, qmat);
479  flush_put_bits(pb);
480 
481  return (put_bits_count(pb) - saved_pos) >> 3;
482 }
483 
484 static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits)
485 {
486  const int dbits = (abits == 8) ? 4 : 7;
487  const int dsize = 1 << dbits - 1;
488  int diff = cur - prev;
489 
490  diff = av_mod_uintp2(diff, abits);
491  if (diff >= (1 << abits) - dsize)
492  diff -= 1 << abits;
493  if (diff < -dsize || diff > dsize || !diff) {
494  put_bits(pb, 1, 1);
495  put_bits(pb, abits, diff);
496  } else {
497  put_bits(pb, 1, 0);
498  put_bits(pb, dbits - 1, FFABS(diff) - 1);
499  put_bits(pb, 1, diff < 0);
500  }
501 }
502 
503 static void put_alpha_run(PutBitContext *pb, int run)
504 {
505  if (run) {
506  put_bits(pb, 1, 0);
507  if (run < 0x10)
508  put_bits(pb, 4, run);
509  else
510  put_bits(pb, 15, run);
511  } else {
512  put_bits(pb, 1, 1);
513  }
514 }
515 
516 // todo alpha quantisation for high quants
518  int mbs_per_slice, uint16_t *blocks,
519  int quant)
520 {
521  const int abits = ctx->alpha_bits;
522  const int mask = (1 << abits) - 1;
523  const int num_coeffs = mbs_per_slice * 256;
524  int saved_pos = put_bits_count(pb);
525  int prev = mask, cur;
526  int idx = 0;
527  int run = 0;
528 
529  cur = blocks[idx++];
530  put_alpha_diff(pb, cur, prev, abits);
531  prev = cur;
532  do {
533  cur = blocks[idx++];
534  if (cur != prev) {
535  put_alpha_run (pb, run);
536  put_alpha_diff(pb, cur, prev, abits);
537  prev = cur;
538  run = 0;
539  } else {
540  run++;
541  }
542  } while (idx < num_coeffs);
543  if (run)
544  put_alpha_run(pb, run);
545  flush_put_bits(pb);
546  return (put_bits_count(pb) - saved_pos) >> 3;
547 }
548 
549 static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,
550  PutBitContext *pb,
551  int sizes[4], int x, int y, int quant,
552  int mbs_per_slice)
553 {
554  ProresContext *ctx = avctx->priv_data;
555  int i, xp, yp;
556  int total_size = 0;
557  const uint16_t *src;
558  int slice_width_factor = av_log2(mbs_per_slice);
559  int num_cblocks, pwidth, line_add, picture_height;
560  ptrdiff_t linesize;
561  int plane_factor, is_chroma;
562  uint16_t *qmat;
563  uint16_t *qmat_chroma;
564 
565  if (ctx->pictures_per_frame == 1)
566  line_add = 0;
567  else
568  line_add = ctx->cur_picture_idx ^ !pic->top_field_first;
569 
570  if ((y << 4) * ctx->pictures_per_frame + line_add >= avctx->height)
571  line_add = 0;
572  picture_height = (avctx->height - line_add + ctx->pictures_per_frame - 1) / ctx->pictures_per_frame;
573 
574  if (ctx->force_quant) {
575  qmat = ctx->quants[0];
576  qmat_chroma = ctx->quants_chroma[0];
577  } else if (quant < MAX_STORED_Q) {
578  qmat = ctx->quants[quant];
579  qmat_chroma = ctx->quants_chroma[quant];
580  } else {
581  qmat = ctx->custom_q;
582  qmat_chroma = ctx->custom_chroma_q;
583  for (i = 0; i < 64; i++) {
584  qmat[i] = ctx->quant_mat[i] * quant;
585  qmat_chroma[i] = ctx->quant_chroma_mat[i] * quant;
586  }
587  }
588 
589  for (i = 0; i < ctx->num_planes; i++) {
590  is_chroma = (i == 1 || i == 2);
591  plane_factor = slice_width_factor + 2;
592  if (is_chroma)
593  plane_factor += ctx->chroma_factor - 3;
594  if (!is_chroma || ctx->chroma_factor == CFACTOR_Y444) {
595  xp = x << 4;
596  yp = y << 4;
597  num_cblocks = 4;
598  pwidth = avctx->width;
599  } else {
600  xp = x << 3;
601  yp = y << 4;
602  num_cblocks = 2;
603  pwidth = avctx->width >> 1;
604  }
605 
606  linesize = pic->linesize[i] * ctx->pictures_per_frame;
607  src = (const uint16_t*)(pic->data[i] + yp * linesize +
608  line_add * pic->linesize[i]) + xp;
609 
610  if (i < 3) {
611  get_slice_data(ctx, src, linesize, xp, yp,
612  pwidth, picture_height,
613  ctx->blocks[0], ctx->emu_buf,
614  mbs_per_slice, num_cblocks, is_chroma);
615  if (!is_chroma) {/* luma quant */
616  sizes[i] = encode_slice_plane(ctx, pb, src, linesize,
617  mbs_per_slice, ctx->blocks[0],
618  num_cblocks, plane_factor,
619  qmat);
620  } else { /* chroma plane */
621  sizes[i] = encode_slice_plane(ctx, pb, src, linesize,
622  mbs_per_slice, ctx->blocks[0],
623  num_cblocks, plane_factor,
624  qmat_chroma);
625  }
626  } else {
627  get_alpha_data(ctx, src, linesize, xp, yp,
628  pwidth, picture_height,
629  ctx->blocks[0], mbs_per_slice, ctx->alpha_bits);
630  sizes[i] = encode_alpha_plane(ctx, pb, mbs_per_slice,
631  ctx->blocks[0], quant);
632  }
633  total_size += sizes[i];
634  if (put_bits_left(pb) < 0) {
635  av_log(avctx, AV_LOG_ERROR,
636  "Underestimated required buffer size.\n");
637  return AVERROR_BUG;
638  }
639  }
640  return total_size;
641 }
642 
643 static inline int estimate_vlc(unsigned codebook, int val)
644 {
645  unsigned int rice_order, exp_order, switch_bits, switch_val;
646  int exponent;
647 
648  /* number of prefix bits to switch between Rice and expGolomb */
649  switch_bits = (codebook & 3) + 1;
650  rice_order = codebook >> 5; /* rice code order */
651  exp_order = (codebook >> 2) & 7; /* exp golomb code order */
652 
653  switch_val = switch_bits << rice_order;
654 
655  if (val >= switch_val) {
656  val -= switch_val - (1 << exp_order);
657  exponent = av_log2(val);
658 
659  return exponent * 2 - exp_order + switch_bits + 1;
660  } else {
661  return (val >> rice_order) + rice_order + 1;
662  }
663 }
664 
665 static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice,
666  int scale)
667 {
668  int i;
669  int codebook = 3, code, dc, prev_dc, delta, sign, new_sign;
670  int bits;
671 
672  prev_dc = (blocks[0] - 0x4000) / scale;
673  bits = estimate_vlc(FIRST_DC_CB, MAKE_CODE(prev_dc));
674  sign = 0;
675  codebook = 3;
676  blocks += 64;
677  *error += FFABS(blocks[0] - 0x4000) % scale;
678 
679  for (i = 1; i < blocks_per_slice; i++, blocks += 64) {
680  dc = (blocks[0] - 0x4000) / scale;
681  *error += FFABS(blocks[0] - 0x4000) % scale;
682  delta = dc - prev_dc;
683  new_sign = GET_SIGN(delta);
684  delta = (delta ^ sign) - sign;
685  code = MAKE_CODE(delta);
687  codebook = (code + (code & 1)) >> 1;
688  codebook = FFMIN(codebook, 3);
689  sign = new_sign;
690  prev_dc = dc;
691  }
692 
693  return bits;
694 }
695 
696 static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice,
697  int plane_size_factor,
698  const uint8_t *scan, const int16_t *qmat)
699 {
700  int idx, i;
701  int run, level, run_cb, lev_cb;
702  int max_coeffs, abs_level;
703  int bits = 0;
704 
705  max_coeffs = blocks_per_slice << 6;
706  run_cb = ff_prores_run_to_cb_index[4];
707  lev_cb = ff_prores_lev_to_cb_index[2];
708  run = 0;
709 
710  for (i = 1; i < 64; i++) {
711  for (idx = scan[i]; idx < max_coeffs; idx += 64) {
712  level = blocks[idx] / qmat[scan[i]];
713  *error += FFABS(blocks[idx]) % qmat[scan[i]];
714  if (level) {
715  abs_level = FFABS(level);
718  abs_level - 1) + 1;
719 
720  run_cb = ff_prores_run_to_cb_index[FFMIN(run, 15)];
721  lev_cb = ff_prores_lev_to_cb_index[FFMIN(abs_level, 9)];
722  run = 0;
723  } else {
724  run++;
725  }
726  }
727  }
728 
729  return bits;
730 }
731 
732 static int estimate_slice_plane(ProresContext *ctx, int *error, int plane,
733  const uint16_t *src, ptrdiff_t linesize,
734  int mbs_per_slice,
735  int blocks_per_mb, int plane_size_factor,
736  const int16_t *qmat, ProresThreadData *td)
737 {
738  int blocks_per_slice;
739  int bits;
740 
741  blocks_per_slice = mbs_per_slice * blocks_per_mb;
742 
743  bits = estimate_dcs(error, td->blocks[plane], blocks_per_slice, qmat[0]);
744  bits += estimate_acs(error, td->blocks[plane], blocks_per_slice,
745  plane_size_factor, ctx->scantable, qmat);
746 
747  return FFALIGN(bits, 8);
748 }
749 
750 static int est_alpha_diff(int cur, int prev, int abits)
751 {
752  const int dbits = (abits == 8) ? 4 : 7;
753  const int dsize = 1 << dbits - 1;
754  int diff = cur - prev;
755 
756  diff = av_mod_uintp2(diff, abits);
757  if (diff >= (1 << abits) - dsize)
758  diff -= 1 << abits;
759  if (diff < -dsize || diff > dsize || !diff)
760  return abits + 1;
761  else
762  return dbits + 1;
763 }
764 
766  const uint16_t *src, ptrdiff_t linesize,
767  int mbs_per_slice, int16_t *blocks)
768 {
769  const int abits = ctx->alpha_bits;
770  const int mask = (1 << abits) - 1;
771  const int num_coeffs = mbs_per_slice * 256;
772  int prev = mask, cur;
773  int idx = 0;
774  int run = 0;
775  int bits;
776 
777  cur = blocks[idx++];
778  bits = est_alpha_diff(cur, prev, abits);
779  prev = cur;
780  do {
781  cur = blocks[idx++];
782  if (cur != prev) {
783  if (!run)
784  bits++;
785  else if (run < 0x10)
786  bits += 4;
787  else
788  bits += 15;
789  bits += est_alpha_diff(cur, prev, abits);
790  prev = cur;
791  run = 0;
792  } else {
793  run++;
794  }
795  } while (idx < num_coeffs);
796 
797  if (run) {
798  if (run < 0x10)
799  bits += 4;
800  else
801  bits += 15;
802  }
803 
804  return bits;
805 }
806 
808  int trellis_node, int x, int y, int mbs_per_slice,
810 {
811  ProresContext *ctx = avctx->priv_data;
812  int i, q, pq, xp, yp;
813  const uint16_t *src;
814  int slice_width_factor = av_log2(mbs_per_slice);
815  int num_cblocks[MAX_PLANES], pwidth;
816  int plane_factor[MAX_PLANES], is_chroma[MAX_PLANES];
817  const int min_quant = ctx->profile_info->min_quant;
818  const int max_quant = ctx->profile_info->max_quant;
819  int error, bits, bits_limit;
820  int mbs, prev, cur, new_score;
821  int slice_bits[TRELLIS_WIDTH], slice_score[TRELLIS_WIDTH];
822  int overquant;
823  uint16_t *qmat;
824  uint16_t *qmat_chroma;
825  int linesize[4], line_add, picture_height;
826  int alpha_bits = 0;
827 
828  if (ctx->pictures_per_frame == 1)
829  line_add = 0;
830  else
831  line_add = ctx->cur_picture_idx ^ !ctx->pic->top_field_first;
832 
833  if ((y << 4) * ctx->pictures_per_frame + line_add >= avctx->height)
834  line_add = 0;
835  picture_height = (avctx->height - line_add + ctx->pictures_per_frame - 1) / ctx->pictures_per_frame;
836  mbs = x + mbs_per_slice;
837 
838  for (i = 0; i < ctx->num_planes; i++) {
839  is_chroma[i] = (i == 1 || i == 2);
840  plane_factor[i] = slice_width_factor + 2;
841  if (is_chroma[i])
842  plane_factor[i] += ctx->chroma_factor - 3;
843  if (!is_chroma[i] || ctx->chroma_factor == CFACTOR_Y444) {
844  xp = x << 4;
845  yp = y << 4;
846  num_cblocks[i] = 4;
847  pwidth = avctx->width;
848  } else {
849  xp = x << 3;
850  yp = y << 4;
851  num_cblocks[i] = 2;
852  pwidth = avctx->width >> 1;
853  }
854 
855  linesize[i] = ctx->pic->linesize[i] * ctx->pictures_per_frame;
856  src = (const uint16_t *)(ctx->pic->data[i] + yp * linesize[i] +
857  line_add * ctx->pic->linesize[i]) + xp;
858 
859  if (i < 3) {
860  get_slice_data(ctx, src, linesize[i], xp, yp,
861  pwidth, picture_height,
862  td->blocks[i], td->emu_buf,
863  mbs_per_slice, num_cblocks[i], is_chroma[i]);
864  } else {
865  get_alpha_data(ctx, src, linesize[i], xp, yp,
866  pwidth, picture_height,
867  td->blocks[i], mbs_per_slice, ctx->alpha_bits);
868  }
869  }
870 
871  for (q = min_quant; q < max_quant + 2; q++) {
872  td->nodes[trellis_node + q].prev_node = -1;
873  td->nodes[trellis_node + q].quant = q;
874  }
875 
876  if (ctx->alpha_bits)
877  alpha_bits = estimate_alpha_plane(ctx, src, linesize[3],
878  mbs_per_slice, td->blocks[3]);
879  // todo: maybe perform coarser quantising to fit into frame size when needed
880  for (q = min_quant; q <= max_quant; q++) {
881  bits = alpha_bits;
882  error = 0;
884  src, linesize[0],
885  mbs_per_slice,
886  num_cblocks[0], plane_factor[0],
887  ctx->quants[q], td); /* estimate luma plane */
888  for (i = 1; i < ctx->num_planes - !!ctx->alpha_bits; i++) { /* estimate chroma plane */
890  src, linesize[i],
891  mbs_per_slice,
892  num_cblocks[i], plane_factor[i],
893  ctx->quants_chroma[q], td);
894  }
895  if (bits > 65000 * 8)
896  error = SCORE_LIMIT;
897 
898  slice_bits[q] = bits;
899  slice_score[q] = error;
900  }
901  if (slice_bits[max_quant] <= ctx->bits_per_mb * mbs_per_slice) {
902  slice_bits[max_quant + 1] = slice_bits[max_quant];
903  slice_score[max_quant + 1] = slice_score[max_quant] + 1;
904  overquant = max_quant;
905  } else {
906  for (q = max_quant + 1; q < 128; q++) {
907  bits = alpha_bits;
908  error = 0;
909  if (q < MAX_STORED_Q) {
910  qmat = ctx->quants[q];
911  qmat_chroma = ctx->quants_chroma[q];
912  } else {
913  qmat = td->custom_q;
914  qmat_chroma = td->custom_chroma_q;
915  for (i = 0; i < 64; i++) {
916  qmat[i] = ctx->quant_mat[i] * q;
917  qmat_chroma[i] = ctx->quant_chroma_mat[i] * q;
918  }
919  }
921  src, linesize[0],
922  mbs_per_slice,
923  num_cblocks[0], plane_factor[0],
924  qmat, td);/* estimate luma plane */
925  for (i = 1; i < ctx->num_planes - !!ctx->alpha_bits; i++) { /* estimate chroma plane */
927  src, linesize[i],
928  mbs_per_slice,
929  num_cblocks[i], plane_factor[i],
930  qmat_chroma, td);
931  }
932  if (bits <= ctx->bits_per_mb * mbs_per_slice)
933  break;
934  }
935 
936  slice_bits[max_quant + 1] = bits;
937  slice_score[max_quant + 1] = error;
938  overquant = q;
939  }
940  td->nodes[trellis_node + max_quant + 1].quant = overquant;
941 
942  bits_limit = mbs * ctx->bits_per_mb;
943  for (pq = min_quant; pq < max_quant + 2; pq++) {
944  prev = trellis_node - TRELLIS_WIDTH + pq;
945 
946  for (q = min_quant; q < max_quant + 2; q++) {
947  cur = trellis_node + q;
948 
949  bits = td->nodes[prev].bits + slice_bits[q];
950  error = slice_score[q];
951  if (bits > bits_limit)
952  error = SCORE_LIMIT;
953 
954  if (td->nodes[prev].score < SCORE_LIMIT && error < SCORE_LIMIT)
955  new_score = td->nodes[prev].score + error;
956  else
957  new_score = SCORE_LIMIT;
958  if (td->nodes[cur].prev_node == -1 ||
959  td->nodes[cur].score >= new_score) {
960 
961  td->nodes[cur].bits = bits;
962  td->nodes[cur].score = new_score;
963  td->nodes[cur].prev_node = prev;
964  }
965  }
966  }
967 
968  error = td->nodes[trellis_node + min_quant].score;
969  pq = trellis_node + min_quant;
970  for (q = min_quant + 1; q < max_quant + 2; q++) {
971  if (td->nodes[trellis_node + q].score <= error) {
972  error = td->nodes[trellis_node + q].score;
973  pq = trellis_node + q;
974  }
975  }
976 
977  return pq;
978 }
979 
980 static int find_quant_thread(AVCodecContext *avctx, void *arg,
981  int jobnr, int threadnr)
982 {
983  ProresContext *ctx = avctx->priv_data;
984  ProresThreadData *td = ctx->tdata + threadnr;
985  int mbs_per_slice = ctx->mbs_per_slice;
986  int x, y = jobnr, mb, q = 0;
987 
988  for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) {
989  while (ctx->mb_width - x < mbs_per_slice)
990  mbs_per_slice >>= 1;
991  q = find_slice_quant(avctx,
992  (mb + 1) * TRELLIS_WIDTH, x, y,
993  mbs_per_slice, td);
994  }
995 
996  for (x = ctx->slices_width - 1; x >= 0; x--) {
997  ctx->slice_q[x + y * ctx->slices_width] = td->nodes[q].quant;
998  q = td->nodes[q].prev_node;
999  }
1000 
1001  return 0;
1002 }
1003 
1005  const AVFrame *pic, int *got_packet)
1006 {
1007  ProresContext *ctx = avctx->priv_data;
1008  uint8_t *orig_buf, *buf, *slice_hdr, *slice_sizes, *tmp;
1009  uint8_t *picture_size_pos;
1010  PutBitContext pb;
1011  int x, y, i, mb, q = 0;
1012  int sizes[4] = { 0 };
1013  int slice_hdr_size = 2 + 2 * (ctx->num_planes - 1);
1014  int frame_size, picture_size, slice_size;
1015  int pkt_size, ret;
1016  int max_slice_size = (ctx->frame_size_upper_bound - 200) / (ctx->pictures_per_frame * ctx->slices_per_picture + 1);
1017  int slice_size_upper_bound = ctx->slice_size_upper_bound;
1018  uint8_t frame_flags;
1019 
1020  ctx->pic = pic;
1021  pkt_size = ctx->frame_size_upper_bound + slice_size_upper_bound;
1022 
1023  if ((ret = ff_alloc_packet2(avctx, pkt, pkt_size + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
1024  return ret;
1025 
1026  orig_buf = pkt->data;
1027 
1028  // frame atom
1029  orig_buf += 4; // frame size
1030  bytestream_put_be32 (&orig_buf, FRAME_ID); // frame container ID
1031  buf = orig_buf;
1032 
1033  // frame header
1034  tmp = buf;
1035  buf += 2; // frame header size will be stored here
1036  bytestream_put_be16 (&buf, 0); // version 1
1037  bytestream_put_buffer(&buf, ctx->vendor, 4);
1038  bytestream_put_be16 (&buf, avctx->width);
1039  bytestream_put_be16 (&buf, avctx->height);
1040 
1041  frame_flags = ctx->chroma_factor << 6;
1042  if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
1043  frame_flags |= pic->top_field_first ? 0x04 : 0x08;
1044  bytestream_put_byte (&buf, frame_flags);
1045 
1046  bytestream_put_byte (&buf, 0); // reserved
1047  bytestream_put_byte (&buf, pic->color_primaries);
1048  bytestream_put_byte (&buf, pic->color_trc);
1049  bytestream_put_byte (&buf, pic->colorspace);
1050  bytestream_put_byte (&buf, 0x40 | (ctx->alpha_bits >> 3));
1051  bytestream_put_byte (&buf, 0); // reserved
1052  if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
1053  bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
1054  // luma quantisation matrix
1055  for (i = 0; i < 64; i++)
1056  bytestream_put_byte(&buf, ctx->quant_mat[i]);
1057  // chroma quantisation matrix
1058  for (i = 0; i < 64; i++)
1059  bytestream_put_byte(&buf, ctx->quant_chroma_mat[i]);
1060  } else {
1061  bytestream_put_byte (&buf, 0x00); // matrix flags - default matrices are used
1062  }
1063  bytestream_put_be16 (&tmp, buf - orig_buf); // write back frame header size
1064 
1065  for (ctx->cur_picture_idx = 0;
1066  ctx->cur_picture_idx < ctx->pictures_per_frame;
1067  ctx->cur_picture_idx++) {
1068  // picture header
1069  picture_size_pos = buf + 1;
1070  bytestream_put_byte (&buf, 0x40); // picture header size (in bits)
1071  buf += 4; // picture data size will be stored here
1072  bytestream_put_be16 (&buf, ctx->slices_per_picture);
1073  bytestream_put_byte (&buf, av_log2(ctx->mbs_per_slice) << 4); // slice width and height in MBs
1074 
1075  // seek table - will be filled during slice encoding
1076  slice_sizes = buf;
1077  buf += ctx->slices_per_picture * 2;
1078 
1079  // slices
1080  if (!ctx->force_quant) {
1081  ret = avctx->execute2(avctx, find_quant_thread, (void*)pic, NULL,
1082  ctx->mb_height);
1083  if (ret)
1084  return ret;
1085  }
1086 
1087  for (y = 0; y < ctx->mb_height; y++) {
1088  int mbs_per_slice = ctx->mbs_per_slice;
1089  for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) {
1090  q = ctx->force_quant ? ctx->force_quant
1091  : ctx->slice_q[mb + y * ctx->slices_width];
1092 
1093  while (ctx->mb_width - x < mbs_per_slice)
1094  mbs_per_slice >>= 1;
1095 
1096  bytestream_put_byte(&buf, slice_hdr_size << 3);
1097  slice_hdr = buf;
1098  buf += slice_hdr_size - 1;
1099  if (pkt_size - (buf - orig_buf) < slice_size_upper_bound) {
1100  uint8_t *start = pkt->data;
1101  // Recompute new size according to max_slice_size
1102  // and deduce delta
1103  int delta = 200 + (ctx->pictures_per_frame *
1104  ctx->slices_per_picture + 1) *
1105  max_slice_size - pkt_size;
1106 
1107  delta = FFMAX(delta, slice_size_upper_bound);
1108  ctx->frame_size_upper_bound += delta;
1109 
1110  if (!ctx->warn) {
1111  avpriv_request_sample(avctx,
1112  "Packet too small: is %i,"
1113  " needs %i (slice: %i). "
1114  "Correct allocation",
1115  pkt_size, delta, max_slice_size);
1116  ctx->warn = 1;
1117  }
1118 
1119  ret = av_grow_packet(pkt, delta);
1120  if (ret < 0)
1121  return ret;
1122 
1123  pkt_size += delta;
1124  // restore pointers
1125  orig_buf = pkt->data + (orig_buf - start);
1126  buf = pkt->data + (buf - start);
1127  picture_size_pos = pkt->data + (picture_size_pos - start);
1128  slice_sizes = pkt->data + (slice_sizes - start);
1129  slice_hdr = pkt->data + (slice_hdr - start);
1130  tmp = pkt->data + (tmp - start);
1131  }
1132  init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf)));
1133  ret = encode_slice(avctx, pic, &pb, sizes, x, y, q,
1134  mbs_per_slice);
1135  if (ret < 0)
1136  return ret;
1137 
1138  bytestream_put_byte(&slice_hdr, q);
1139  slice_size = slice_hdr_size + sizes[ctx->num_planes - 1];
1140  for (i = 0; i < ctx->num_planes - 1; i++) {
1141  bytestream_put_be16(&slice_hdr, sizes[i]);
1142  slice_size += sizes[i];
1143  }
1144  bytestream_put_be16(&slice_sizes, slice_size);
1145  buf += slice_size - slice_hdr_size;
1146  if (max_slice_size < slice_size)
1147  max_slice_size = slice_size;
1148  }
1149  }
1150 
1151  picture_size = buf - (picture_size_pos - 1);
1152  bytestream_put_be32(&picture_size_pos, picture_size);
1153  }
1154 
1155  orig_buf -= 8;
1156  frame_size = buf - orig_buf;
1157  bytestream_put_be32(&orig_buf, frame_size);
1158 
1159  pkt->size = frame_size;
1161  *got_packet = 1;
1162 
1163  return 0;
1164 }
1165 
1167 {
1168  ProresContext *ctx = avctx->priv_data;
1169  int i;
1170 
1171  if (ctx->tdata) {
1172  for (i = 0; i < avctx->thread_count; i++)
1173  av_freep(&ctx->tdata[i].nodes);
1174  }
1175  av_freep(&ctx->tdata);
1176  av_freep(&ctx->slice_q);
1177 
1178  return 0;
1179 }
1180 
1181 static void prores_fdct(FDCTDSPContext *fdsp, const uint16_t *src,
1182  ptrdiff_t linesize, int16_t *block)
1183 {
1184  int x, y;
1185  const uint16_t *tsrc = src;
1186 
1187  for (y = 0; y < 8; y++) {
1188  for (x = 0; x < 8; x++)
1189  block[y * 8 + x] = tsrc[x];
1190  tsrc += linesize >> 1;
1191  }
1192  fdsp->fdct(block);
1193 }
1194 
1196 {
1197  ProresContext *ctx = avctx->priv_data;
1198  int mps;
1199  int i, j;
1200  int min_quant, max_quant;
1201  int interlaced = !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT);
1202 
1203  avctx->bits_per_raw_sample = 10;
1204 #if FF_API_CODED_FRAME
1207  avctx->coded_frame->key_frame = 1;
1209 #endif
1210 
1211  ctx->fdct = prores_fdct;
1214  ff_fdctdsp_init(&ctx->fdsp, avctx);
1215 
1216  mps = ctx->mbs_per_slice;
1217  if (mps & (mps - 1)) {
1218  av_log(avctx, AV_LOG_ERROR,
1219  "there should be an integer power of two MBs per slice\n");
1220  return AVERROR(EINVAL);
1221  }
1222  if (ctx->profile == PRORES_PROFILE_AUTO) {
1224  ctx->profile = (desc->flags & AV_PIX_FMT_FLAG_ALPHA ||
1225  !(desc->log2_chroma_w + desc->log2_chroma_h))
1227  av_log(avctx, AV_LOG_INFO, "Autoselected %s. It can be overridden "
1228  "through -profile option.\n", ctx->profile == PRORES_PROFILE_4444
1229  ? "4:4:4:4 profile because of the used input colorspace"
1230  : "HQ profile to keep best quality");
1231  }
1233  if (ctx->profile != PRORES_PROFILE_4444 &&
1234  ctx->profile != PRORES_PROFILE_4444XQ) {
1235  // force alpha and warn
1236  av_log(avctx, AV_LOG_WARNING, "Profile selected will not "
1237  "encode alpha. Override with -profile if needed.\n");
1238  ctx->alpha_bits = 0;
1239  }
1240  if (ctx->alpha_bits & 7) {
1241  av_log(avctx, AV_LOG_ERROR, "alpha bits should be 0, 8 or 16\n");
1242  return AVERROR(EINVAL);
1243  }
1244  avctx->bits_per_coded_sample = 32;
1245  } else {
1246  ctx->alpha_bits = 0;
1247  }
1248 
1249  ctx->chroma_factor = avctx->pix_fmt == AV_PIX_FMT_YUV422P10
1250  ? CFACTOR_Y422
1251  : CFACTOR_Y444;
1252  ctx->profile_info = prores_profile_info + ctx->profile;
1253  ctx->num_planes = 3 + !!ctx->alpha_bits;
1254 
1255  ctx->mb_width = FFALIGN(avctx->width, 16) >> 4;
1256 
1257  if (interlaced)
1258  ctx->mb_height = FFALIGN(avctx->height, 32) >> 5;
1259  else
1260  ctx->mb_height = FFALIGN(avctx->height, 16) >> 4;
1261 
1262  ctx->slices_width = ctx->mb_width / mps;
1263  ctx->slices_width += av_popcount(ctx->mb_width - ctx->slices_width * mps);
1264  ctx->slices_per_picture = ctx->mb_height * ctx->slices_width;
1265  ctx->pictures_per_frame = 1 + interlaced;
1266 
1267  if (ctx->quant_sel == -1) {
1268  ctx->quant_mat = prores_quant_matrices[ctx->profile_info->quant];
1269  ctx->quant_chroma_mat = prores_quant_matrices[ctx->profile_info->quant_chroma];
1270  } else {
1271  ctx->quant_mat = prores_quant_matrices[ctx->quant_sel];
1272  ctx->quant_chroma_mat = prores_quant_matrices[ctx->quant_sel];
1273  }
1274 
1275  if (strlen(ctx->vendor) != 4) {
1276  av_log(avctx, AV_LOG_ERROR, "vendor ID should be 4 bytes\n");
1277  return AVERROR_INVALIDDATA;
1278  }
1279 
1280  ctx->force_quant = avctx->global_quality / FF_QP2LAMBDA;
1281  if (!ctx->force_quant) {
1282  if (!ctx->bits_per_mb) {
1283  for (i = 0; i < NUM_MB_LIMITS - 1; i++)
1284  if (prores_mb_limits[i] >= ctx->mb_width * ctx->mb_height *
1285  ctx->pictures_per_frame)
1286  break;
1287  ctx->bits_per_mb = ctx->profile_info->br_tab[i];
1288  if (ctx->alpha_bits)
1289  ctx->bits_per_mb *= 20;
1290  } else if (ctx->bits_per_mb < 128) {
1291  av_log(avctx, AV_LOG_ERROR, "too few bits per MB, please set at least 128\n");
1292  return AVERROR_INVALIDDATA;
1293  }
1294 
1295  min_quant = ctx->profile_info->min_quant;
1296  max_quant = ctx->profile_info->max_quant;
1297  for (i = min_quant; i < MAX_STORED_Q; i++) {
1298  for (j = 0; j < 64; j++) {
1299  ctx->quants[i][j] = ctx->quant_mat[j] * i;
1300  ctx->quants_chroma[i][j] = ctx->quant_chroma_mat[j] * i;
1301  }
1302  }
1303 
1304  ctx->slice_q = av_malloc(ctx->slices_per_picture * sizeof(*ctx->slice_q));
1305  if (!ctx->slice_q) {
1306  encode_close(avctx);
1307  return AVERROR(ENOMEM);
1308  }
1309 
1310  ctx->tdata = av_mallocz(avctx->thread_count * sizeof(*ctx->tdata));
1311  if (!ctx->tdata) {
1312  encode_close(avctx);
1313  return AVERROR(ENOMEM);
1314  }
1315 
1316  for (j = 0; j < avctx->thread_count; j++) {
1317  ctx->tdata[j].nodes = av_malloc((ctx->slices_width + 1)
1318  * TRELLIS_WIDTH
1319  * sizeof(*ctx->tdata->nodes));
1320  if (!ctx->tdata[j].nodes) {
1321  encode_close(avctx);
1322  return AVERROR(ENOMEM);
1323  }
1324  for (i = min_quant; i < max_quant + 2; i++) {
1325  ctx->tdata[j].nodes[i].prev_node = -1;
1326  ctx->tdata[j].nodes[i].bits = 0;
1327  ctx->tdata[j].nodes[i].score = 0;
1328  }
1329  }
1330  } else {
1331  int ls = 0;
1332  int ls_chroma = 0;
1333 
1334  if (ctx->force_quant > 64) {
1335  av_log(avctx, AV_LOG_ERROR, "too large quantiser, maximum is 64\n");
1336  return AVERROR_INVALIDDATA;
1337  }
1338 
1339  for (j = 0; j < 64; j++) {
1340  ctx->quants[0][j] = ctx->quant_mat[j] * ctx->force_quant;
1341  ctx->quants_chroma[0][j] = ctx->quant_chroma_mat[j] * ctx->force_quant;
1342  ls += av_log2((1 << 11) / ctx->quants[0][j]) * 2 + 1;
1343  ls_chroma += av_log2((1 << 11) / ctx->quants_chroma[0][j]) * 2 + 1;
1344  }
1345 
1346  ctx->bits_per_mb = ls * 4 + ls_chroma * 4;
1347  if (ctx->chroma_factor == CFACTOR_Y444)
1348  ctx->bits_per_mb += ls_chroma * 4;
1349  }
1350 
1351  int64_t frame_size_upper_bound = (int64_t)(ctx->pictures_per_frame *
1352  ctx->slices_per_picture + 1) *
1353  (2 + 2 * ctx->num_planes +
1354  (mps * ctx->bits_per_mb) / 8)
1355  + 200;
1356  ctx->slice_size_upper_bound = mps * (ctx->chroma_factor == CFACTOR_Y444 ? 768 : 512) * 8;
1357 
1358  if (ctx->alpha_bits) {
1359  // The alpha plane is run-coded and might exceed the bit budget.
1360  int alpha_slice_size = /* num pixels per slice */ mps * 256 *
1361  /* bits per pixel */ (1 + ctx->alpha_bits + 1) + 7 >> 3;
1362  frame_size_upper_bound += (int64_t)(ctx->pictures_per_frame *
1363  ctx->slices_per_picture + 1) * alpha_slice_size;
1364  ctx->slice_size_upper_bound += alpha_slice_size;
1365  }
1366 
1367  if (frame_size_upper_bound + ctx->slice_size_upper_bound + AV_INPUT_BUFFER_MIN_SIZE > INT_MAX) {
1368  av_log(avctx, AV_LOG_ERROR, "Frame too large to encode\n");
1369  return AVERROR(EINVAL);
1370  }
1371  ctx->frame_size_upper_bound = frame_size_upper_bound;
1372 
1373  avctx->codec_tag = ctx->profile_info->tag;
1374 
1375  av_log(avctx, AV_LOG_DEBUG,
1376  "profile %d, %d slices, interlacing: %s, %d bits per MB\n",
1377  ctx->profile, ctx->slices_per_picture * ctx->pictures_per_frame,
1378  interlaced ? "yes" : "no", ctx->bits_per_mb);
1379  av_log(avctx, AV_LOG_DEBUG, "frame size upper bound: %d\n",
1380  ctx->frame_size_upper_bound);
1381 
1382  return 0;
1383 }
1384 
1385 #define OFFSET(x) offsetof(ProresContext, x)
1386 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1387 
1388 static const AVOption options[] = {
1389  { "mbs_per_slice", "macroblocks per slice", OFFSET(mbs_per_slice),
1390  AV_OPT_TYPE_INT, { .i64 = 8 }, 1, MAX_MBS_PER_SLICE, VE },
1391  { "profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT,
1392  { .i64 = PRORES_PROFILE_AUTO },
1394  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_AUTO },
1395  0, 0, VE, "profile" },
1396  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_PROXY },
1397  0, 0, VE, "profile" },
1398  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_LT },
1399  0, 0, VE, "profile" },
1400  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_STANDARD },
1401  0, 0, VE, "profile" },
1402  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_HQ },
1403  0, 0, VE, "profile" },
1404  { "4444", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444 },
1405  0, 0, VE, "profile" },
1406  { "4444xq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444XQ },
1407  0, 0, VE, "profile" },
1408  { "vendor", "vendor ID", OFFSET(vendor),
1409  AV_OPT_TYPE_STRING, { .str = "Lavc" }, 0, 0, VE },
1410  { "bits_per_mb", "desired bits per macroblock", OFFSET(bits_per_mb),
1411  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8192, VE },
1412  { "quant_mat", "quantiser matrix", OFFSET(quant_sel), AV_OPT_TYPE_INT,
1413  { .i64 = -1 }, -1, QUANT_MAT_DEFAULT, VE, "quant_mat" },
1414  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 },
1415  0, 0, VE, "quant_mat" },
1416  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_PROXY },
1417  0, 0, VE, "quant_mat" },
1418  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_LT },
1419  0, 0, VE, "quant_mat" },
1420  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_STANDARD },
1421  0, 0, VE, "quant_mat" },
1422  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_HQ },
1423  0, 0, VE, "quant_mat" },
1424  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_DEFAULT },
1425  0, 0, VE, "quant_mat" },
1426  { "alpha_bits", "bits for alpha plane", OFFSET(alpha_bits), AV_OPT_TYPE_INT,
1427  { .i64 = 16 }, 0, 16, VE },
1428  { NULL }
1429 };
1430 
1431 static const AVClass proresenc_class = {
1432  .class_name = "ProRes encoder",
1433  .item_name = av_default_item_name,
1434  .option = options,
1435  .version = LIBAVUTIL_VERSION_INT,
1436 };
1437 
1439  .name = "prores_ks",
1440  .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)"),
1441  .type = AVMEDIA_TYPE_VIDEO,
1442  .id = AV_CODEC_ID_PRORES,
1443  .priv_data_size = sizeof(ProresContext),
1444  .init = encode_init,
1445  .close = encode_close,
1446  .encode2 = encode_frame,
1448  .pix_fmts = (const enum AVPixelFormat[]) {
1451  },
1452  .priv_class = &proresenc_class,
1454 };
static double val(void *priv, double ch)
Definition: aeval.c:76
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
uint8_t
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
#define FFMIN(a, b)
Definition: common.h:105
#define MKTAG(a, b, c, d)
Definition: common.h:478
#define av_mod_uintp2
Definition: common.h:149
#define av_popcount
Definition: common.h:176
#define FFMAX(a, b)
Definition: common.h:103
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:34
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Definition: fdctdsp.c:26
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:321
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:112
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:108
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:197
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:222
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:122
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:117
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
for(j=16;j >0;--j)
static const int sizes[][2]
Definition: img2dec.c:54
int i
Definition: input.c:407
#define av_log2
Definition: intmath.h:83
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:218
const char * arg
Definition: jacosubdec.c:67
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
const char * desc
Definition: libsvtav1.c:83
uint8_t w
Definition: llviddspenc.c:39
static const uint16_t mask[17]
Definition: lzw.c:38
#define FFALIGN(x, a)
Definition: macros.h:48
uint8_t interlaced
Definition: mxfenc.c:2208
int frame_size
Definition: mxfenc.c:2206
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:179
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
const AVProfile ff_prores_profiles[]
Definition: profiles.c:159
const uint8_t ff_prores_ac_codebook[7]
Definition: proresdata.c:55
const uint8_t ff_prores_dc_codebook[4]
Definition: proresdata.c:48
const uint8_t ff_prores_progressive_scan[64]
Definition: proresdata.c:25
const uint8_t ff_prores_run_to_cb_index[16]
Lookup tables for adaptive switching between codebooks according with previous run/level value.
Definition: proresdata.c:69
const uint8_t ff_prores_lev_to_cb_index[10]
Definition: proresdata.c:72
const uint8_t ff_prores_interlaced_scan[64]
Definition: proresdata.c:36
#define FIRST_DC_CB
Definition: proresdata.h:33
#define FRAME_ID
Definition: proresdata.h:28
static int est_alpha_diff(int cur, int prev, int abits)
static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, int mbs_per_slice, uint16_t *blocks, int quant)
@ QUANT_MAT_STANDARD
@ QUANT_MAT_XQ_LUMA
@ QUANT_MAT_PROXY
@ QUANT_MAT_DEFAULT
@ QUANT_MAT_LT
@ QUANT_MAT_PROXY_CHROMA
@ QUANT_MAT_HQ
static const AVClass proresenc_class
static int estimate_alpha_plane(ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks)
@ PRORES_PROFILE_4444
@ PRORES_PROFILE_STANDARD
@ PRORES_PROFILE_LT
@ PRORES_PROFILE_4444XQ
@ PRORES_PROFILE_AUTO
@ PRORES_PROFILE_HQ
@ PRORES_PROFILE_PROXY
static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat)
static const AVOption options[]
#define VE
#define GET_SIGN(x)
#define MAX_PLANES
static void encode_acs(PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat)
static av_cold int encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static void encode_vlc_codeword(PutBitContext *pb, unsigned codebook, int val)
Write an unsigned rice/exp golomb codeword.
static void put_alpha_run(PutBitContext *pb, int run)
static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, PutBitContext *pb, int sizes[4], int x, int y, int quant, int mbs_per_slice)
static const int prores_mb_limits[NUM_MB_LIMITS]
static const struct prores_profile prores_profile_info[6]
static void get_alpha_data(ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int x, int y, int w, int h, uint16_t *blocks, int mbs_per_slice, int abits)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
#define CFACTOR_Y444
#define CFACTOR_Y422
static int estimate_vlc(unsigned codebook, int val)
static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice, int scale)
#define MAX_MBS_PER_SLICE
static int find_slice_quant(AVCodecContext *avctx, int trellis_node, int x, int y, int mbs_per_slice, ProresThreadData *td)
static void get_slice_data(ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int x, int y, int w, int h, int16_t *blocks, uint16_t *emu_buf, int mbs_per_slice, int blocks_per_mb, int is_chroma)
AVCodec ff_prores_ks_encoder
#define MAKE_CODE(x)
#define OFFSET(x)
#define NUM_MB_LIMITS
static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits)
#define TRELLIS_WIDTH
static int estimate_slice_plane(ProresContext *ctx, int *error, int plane, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int blocks_per_mb, int plane_size_factor, const int16_t *qmat, ProresThreadData *td)
static void prores_fdct(FDCTDSPContext *fdsp, const uint16_t *src, ptrdiff_t linesize, int16_t *block)
static const uint8_t prores_quant_matrices[][64]
static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks, int blocks_per_mb, int plane_size_factor, const int16_t *qmat)
static void encode_dcs(PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int scale)
#define SCORE_LIMIT
static int find_quant_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
#define MAX_STORED_Q
bitstream writer API
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:253
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:57
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:76
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:102
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:110
mfxU16 profile
Definition: qsvenc.c:45
#define td
Definition: regdef.h:70
typedef void(RENAME(mix_any_func_type))
const uint8_t * code
Definition: spdifenc.c:413
Describe the class of an AVClass context structure.
Definition: log.h:67
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:72
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int width
picture width / height.
Definition: avcodec.h:709
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:602
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:561
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1744
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:1768
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1751
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1777
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:616
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1848
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:396
enum AVColorPrimaries color_primaries
Definition: frame.h:564
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:470
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:573
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:566
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
void(* fdct)(int16_t *block)
Definition: fdctdsp.h:27
FDCTDSPContext fdsp
const struct prores_profile * profile_info
int16_t quants[MAX_STORED_Q][64]
uint16_t emu_buf[16 *16]
const uint8_t * quant_mat
const AVFrame * pic
int16_t blocks[MAX_PLANES][64 *4 *MAX_MBS_PER_SLICE]
int16_t custom_q[64]
int16_t quants_chroma[MAX_STORED_Q][64]
const uint8_t * quant_chroma_mat
const uint8_t * scantable
void(* fdct)(FDCTDSPContext *fdsp, const uint16_t *src, ptrdiff_t linesize, int16_t *block)
ProresThreadData * tdata
unsigned mb_width
width of the current picture in mb
Definition: proresdec.h:47
int16_t custom_chroma_q[64]
int16_t blocks[MAX_PLANES][64 *4 *MAX_MBS_PER_SLICE]
int16_t custom_chroma_q[64]
struct TrellisNode * nodes
uint16_t emu_buf[16 *16]
int16_t custom_q[64]
int br_tab[NUM_MB_LIMITS]
const char * full_name
uint8_t run
Definition: svq3.c:205
uint8_t level
Definition: svq3.c:206
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static void error(const char *err)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
#define src
Definition: vp8dsp.c:255
static int16_t block[64]
Definition: dct.c:116
AVPacket * pkt
Definition: movenc.c:59
AVFormatContext * ctx
Definition: movenc.c:48
#define mb
if(ret< 0)
Definition: vf_mcdeint.c:282
static av_always_inline int diff(const uint32_t a, const uint32_t b)
const uint8_t * quant
float delta
uint8_t bits
Definition: vp3data.h:141