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