3 * Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
4 * Copyright (c) 2011 MirriAd Ltd
6 * VC-3 encoder funded by the British Broadcasting Corporation
7 * 10 bit support added by MirriAd Ltd, Joseph Artsimovich <joseph@mirriad.com>
9 * This file is part of FFmpeg.
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libavutil/attributes.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/timer.h"
35 #include "mpegvideo.h"
36 #include "pixblockdsp.h"
40 // The largest value that will not lead to overflow for 10-bit samples.
41 #define DNX10BIT_QMAT_SHIFT 18
42 #define RC_VARIANCE 1 // use variance or ssd for fast rc
43 #define LAMBDA_FRAC_BITS 10
45 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
46 static const AVOption options[] = {
47 { "nitris_compat", "encode with Avid Nitris compatibility",
48 offsetof(DNXHDEncContext, nitris_compat), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
49 { "ibias", "intra quant bias",
50 offsetof(DNXHDEncContext, intra_quant_bias), AV_OPT_TYPE_INT,
51 { .i64 = 0 }, INT_MIN, INT_MAX, VE },
52 { "profile", NULL, offsetof(DNXHDEncContext, profile), AV_OPT_TYPE_INT,
53 { .i64 = FF_PROFILE_DNXHD },
54 FF_PROFILE_DNXHD, FF_PROFILE_DNXHR_444, VE, "profile" },
55 { "dnxhd", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHD },
56 0, 0, VE, "profile" },
57 { "dnxhr_444", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHR_444 },
58 0, 0, VE, "profile" },
59 { "dnxhr_hqx", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHR_HQX },
60 0, 0, VE, "profile" },
61 { "dnxhr_hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHR_HQ },
62 0, 0, VE, "profile" },
63 { "dnxhr_sq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHR_SQ },
64 0, 0, VE, "profile" },
65 { "dnxhr_lb", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_DNXHR_LB },
66 0, 0, VE, "profile" },
70 static const AVClass dnxhd_class = {
71 .class_name = "dnxhd",
72 .item_name = av_default_item_name,
74 .version = LIBAVUTIL_VERSION_INT,
77 static void dnxhd_8bit_get_pixels_8x4_sym(int16_t *av_restrict block,
78 const uint8_t *pixels,
82 for (i = 0; i < 4; i++) {
94 memcpy(block, block - 8, sizeof(*block) * 8);
95 memcpy(block + 8, block - 16, sizeof(*block) * 8);
96 memcpy(block + 16, block - 24, sizeof(*block) * 8);
97 memcpy(block + 24, block - 32, sizeof(*block) * 8);
100 static av_always_inline
101 void dnxhd_10bit_get_pixels_8x4_sym(int16_t *av_restrict block,
102 const uint8_t *pixels,
105 memcpy(block + 0 * 8, pixels + 0 * line_size, 8 * sizeof(*block));
106 memcpy(block + 7 * 8, pixels + 0 * line_size, 8 * sizeof(*block));
107 memcpy(block + 1 * 8, pixels + 1 * line_size, 8 * sizeof(*block));
108 memcpy(block + 6 * 8, pixels + 1 * line_size, 8 * sizeof(*block));
109 memcpy(block + 2 * 8, pixels + 2 * line_size, 8 * sizeof(*block));
110 memcpy(block + 5 * 8, pixels + 2 * line_size, 8 * sizeof(*block));
111 memcpy(block + 3 * 8, pixels + 3 * line_size, 8 * sizeof(*block));
112 memcpy(block + 4 * 8, pixels + 3 * line_size, 8 * sizeof(*block));
115 static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block,
116 int n, int qscale, int *overflow)
118 const uint8_t *scantable= ctx->intra_scantable.scantable;
119 const int *qmat = n<4 ? ctx->q_intra_matrix[qscale] : ctx->q_chroma_intra_matrix[qscale];
120 int last_non_zero = 0;
123 ctx->fdsp.fdct(block);
125 // Divide by 4 with rounding, to compensate scaling of DCT coefficients
126 block[0] = (block[0] + 2) >> 2;
128 for (i = 1; i < 64; ++i) {
129 int j = scantable[i];
130 int sign = FF_SIGNBIT(block[j]);
131 int level = (block[j] ^ sign) - sign;
132 level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT;
133 block[j] = (level ^ sign) - sign;
138 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
139 if (ctx->idsp.perm_type != FF_IDCT_PERM_NONE)
140 ff_block_permute(block, ctx->idsp.idct_permutation,
141 scantable, last_non_zero);
143 return last_non_zero;
146 static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
148 int i, j, level, run;
149 int max_level = 1 << (ctx->cid_table->bit_depth + 2);
151 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->vlc_codes,
152 max_level, 4 * sizeof(*ctx->vlc_codes), fail);
153 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->vlc_bits,
154 max_level, 4 * sizeof(*ctx->vlc_bits), fail);
155 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes,
157 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits,
160 ctx->vlc_codes += max_level * 2;
161 ctx->vlc_bits += max_level * 2;
162 for (level = -max_level; level < max_level; level++) {
163 for (run = 0; run < 2; run++) {
164 int index = (level << 1) | run;
165 int sign, offset = 0, alevel = level;
167 MASK_ABS(sign, alevel);
169 offset = (alevel - 1) >> 6;
170 alevel -= offset << 6;
172 for (j = 0; j < 257; j++) {
173 if (ctx->cid_table->ac_info[2*j+0] >> 1 == alevel &&
174 (!offset || (ctx->cid_table->ac_info[2*j+1] & 1) && offset) &&
175 (!run || (ctx->cid_table->ac_info[2*j+1] & 2) && run)) {
176 av_assert1(!ctx->vlc_codes[index]);
178 ctx->vlc_codes[index] =
179 (ctx->cid_table->ac_codes[j] << 1) | (sign & 1);
180 ctx->vlc_bits[index] = ctx->cid_table->ac_bits[j] + 1;
182 ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];
183 ctx->vlc_bits[index] = ctx->cid_table->ac_bits[j];
188 av_assert0(!alevel || j < 257);
190 ctx->vlc_codes[index] =
191 (ctx->vlc_codes[index] << ctx->cid_table->index_bits) | offset;
192 ctx->vlc_bits[index] += ctx->cid_table->index_bits;
196 for (i = 0; i < 62; i++) {
197 int run = ctx->cid_table->run[i];
198 av_assert0(run < 63);
199 ctx->run_codes[run] = ctx->cid_table->run_codes[i];
200 ctx->run_bits[run] = ctx->cid_table->run_bits[i];
204 return AVERROR(ENOMEM);
207 static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
209 // init first elem to 1 to avoid div by 0 in convert_matrix
210 uint16_t weight_matrix[64] = { 1, }; // convert_matrix needs uint16_t*
212 const uint8_t *luma_weight_table = ctx->cid_table->luma_weight;
213 const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight;
215 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l,
216 (ctx->m.avctx->qmax + 1), 64 * sizeof(int), fail);
217 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c,
218 (ctx->m.avctx->qmax + 1), 64 * sizeof(int), fail);
219 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16,
220 (ctx->m.avctx->qmax + 1), 64 * 2 * sizeof(uint16_t),
222 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16,
223 (ctx->m.avctx->qmax + 1), 64 * 2 * sizeof(uint16_t),
226 if (ctx->cid_table->bit_depth == 8) {
227 for (i = 1; i < 64; i++) {
228 int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
229 weight_matrix[j] = ctx->cid_table->luma_weight[i];
231 ff_convert_matrix(&ctx->m, ctx->qmatrix_l, ctx->qmatrix_l16,
232 weight_matrix, ctx->intra_quant_bias, 1,
233 ctx->m.avctx->qmax, 1);
234 for (i = 1; i < 64; i++) {
235 int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
236 weight_matrix[j] = ctx->cid_table->chroma_weight[i];
238 ff_convert_matrix(&ctx->m, ctx->qmatrix_c, ctx->qmatrix_c16,
239 weight_matrix, ctx->intra_quant_bias, 1,
240 ctx->m.avctx->qmax, 1);
242 for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
243 for (i = 0; i < 64; i++) {
244 ctx->qmatrix_l[qscale][i] <<= 2;
245 ctx->qmatrix_c[qscale][i] <<= 2;
246 ctx->qmatrix_l16[qscale][0][i] <<= 2;
247 ctx->qmatrix_l16[qscale][1][i] <<= 2;
248 ctx->qmatrix_c16[qscale][0][i] <<= 2;
249 ctx->qmatrix_c16[qscale][1][i] <<= 2;
254 for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
255 for (i = 1; i < 64; i++) {
256 int j = ff_zigzag_direct[i];
258 /* The quantization formula from the VC-3 standard is:
259 * quantized = sign(block[i]) * floor(abs(block[i]/s) * p /
260 * (qscale * weight_table[i]))
261 * Where p is 32 for 8-bit samples and 8 for 10-bit ones.
262 * The s factor compensates scaling of DCT coefficients done by
263 * the DCT routines, and therefore is not present in standard.
264 * It's 8 for 8-bit samples and 4 for 10-bit ones.
265 * We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be:
266 * ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) /
267 * (qscale * weight_table[i])
268 * For 10-bit samples, p / s == 2 */
269 ctx->qmatrix_l[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) /
270 (qscale * luma_weight_table[i]);
271 ctx->qmatrix_c[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) /
272 (qscale * chroma_weight_table[i]);
277 ctx->m.q_chroma_intra_matrix16 = ctx->qmatrix_c16;
278 ctx->m.q_chroma_intra_matrix = ctx->qmatrix_c;
279 ctx->m.q_intra_matrix16 = ctx->qmatrix_l16;
280 ctx->m.q_intra_matrix = ctx->qmatrix_l;
284 return AVERROR(ENOMEM);
287 static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx)
289 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_rc, (ctx->m.avctx->qmax + 1),
290 ctx->m.mb_num * sizeof(RCEntry), fail);
291 if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) {
292 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_cmp,
293 ctx->m.mb_num, sizeof(RCCMPEntry), fail);
294 FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_cmp_tmp,
295 ctx->m.mb_num, sizeof(RCCMPEntry), fail);
297 ctx->frame_bits = (ctx->coding_unit_size -
298 ctx->data_offset - 4 - ctx->min_padding) * 8;
300 ctx->lambda = 2 << LAMBDA_FRAC_BITS; // qscale 2
303 return AVERROR(ENOMEM);
306 static int dnxhd_get_hr_frame_size(const CIDEntry* profile, int mb_num)
308 int result = mb_num * profile->packet_scale.num / profile->packet_scale.den;
309 result = (result + 2048) / 4096 * 4096;
310 return FFMAX(result, 8192);
312 static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
314 DNXHDEncContext *ctx = avctx->priv_data;
315 int i, index, bit_depth, ret;
317 switch (avctx->pix_fmt) {
318 case AV_PIX_FMT_YUV422P:
321 case AV_PIX_FMT_YUV422P10:
325 av_log(avctx, AV_LOG_ERROR,
326 "pixel format is incompatible with DNxHD\n");
327 return AVERROR(EINVAL);
330 if (ctx->profile == FF_PROFILE_DNXHR_444 ||
331 ctx->profile == FF_PROFILE_DNXHR_HQX) {
332 avpriv_report_missing_feature(avctx,
333 "dnxhr_444 or dnxhr_hqx profile");
334 return AVERROR_PATCHWELCOME;
337 avctx->profile = ctx->profile;
338 ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth);
340 av_log(avctx, AV_LOG_ERROR,
341 "video parameters incompatible with DNxHD. Valid DNxHD profiles:\n");
342 ff_dnxhd_print_profiles(avctx, AV_LOG_ERROR);
343 return AVERROR(EINVAL);
345 av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid);
347 if (ctx->cid >= 1270 && ctx->cid <= 1274)
348 avctx->codec_tag = MKTAG('A','V','d','h');
350 if (avctx->width < 256 || avctx->height < 120) {
351 av_log(avctx, AV_LOG_ERROR,
352 "Input dimensions too small, input must be at least 256x120\n");
353 return AVERROR(EINVAL);
356 index = ff_dnxhd_get_cid_table(ctx->cid);
357 av_assert0(index >= 0);
359 ctx->cid_table = &ff_dnxhd_cid_table[index];
361 ctx->m.avctx = avctx;
365 avctx->bits_per_raw_sample = ctx->cid_table->bit_depth;
367 ff_blockdsp_init(&ctx->bdsp, avctx);
368 ff_fdctdsp_init(&ctx->m.fdsp, avctx);
369 ff_mpv_idct_init(&ctx->m);
370 ff_mpegvideoencdsp_init(&ctx->m.mpvencdsp, avctx);
371 ff_pixblockdsp_init(&ctx->m.pdsp, avctx);
372 ff_dct_encode_init(&ctx->m);
374 if (ctx->profile != FF_PROFILE_DNXHD)
375 ff_videodsp_init(&ctx->m.vdsp, bit_depth);
377 if (!ctx->m.dct_quantize)
378 ctx->m.dct_quantize = ff_dct_quantize_c;
380 if (ctx->cid_table->bit_depth == 10) {
381 ctx->m.dct_quantize = dnxhd_10bit_dct_quantize;
382 ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym;
383 ctx->block_width_l2 = 4;
385 ctx->get_pixels_8x4_sym = dnxhd_8bit_get_pixels_8x4_sym;
386 ctx->block_width_l2 = 3;
390 ff_dnxhdenc_init_x86(ctx);
392 ctx->m.mb_height = (avctx->height + 15) / 16;
393 ctx->m.mb_width = (avctx->width + 15) / 16;
395 if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
397 ctx->m.mb_height /= 2;
400 ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width;
402 if (ctx->cid_table->frame_size == DNXHD_VARIABLE) {
403 ctx->frame_size = dnxhd_get_hr_frame_size(ctx->cid_table,
405 ctx->coding_unit_size = ctx->frame_size;
407 ctx->frame_size = ctx->cid_table->frame_size;
408 ctx->coding_unit_size = ctx->cid_table->coding_unit_size;
411 if (ctx->m.mb_height > 68)
412 ctx->data_offset = 0x170 + (ctx->m.mb_height << 2);
414 ctx->data_offset = 0x280;
416 #if FF_API_QUANT_BIAS
417 FF_DISABLE_DEPRECATION_WARNINGS
418 if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
419 ctx->intra_quant_bias = avctx->intra_quant_bias;
420 FF_ENABLE_DEPRECATION_WARNINGS
422 // XXX tune lbias/cbias
423 if ((ret = dnxhd_init_qmat(ctx, ctx->intra_quant_bias, 0)) < 0)
426 /* Avid Nitris hardware decoder requires a minimum amount of padding
427 * in the coding unit payload */
428 if (ctx->nitris_compat)
429 ctx->min_padding = 1600;
431 if ((ret = dnxhd_init_vlc(ctx)) < 0)
433 if ((ret = dnxhd_init_rc(ctx)) < 0)
436 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size,
437 ctx->m.mb_height * sizeof(uint32_t), fail);
438 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_offs,
439 ctx->m.mb_height * sizeof(uint32_t), fail);
440 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits,
441 ctx->m.mb_num * sizeof(uint16_t), fail);
442 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale,
443 ctx->m.mb_num * sizeof(uint8_t), fail);
445 #if FF_API_CODED_FRAME
446 FF_DISABLE_DEPRECATION_WARNINGS
447 avctx->coded_frame->key_frame = 1;
448 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
449 FF_ENABLE_DEPRECATION_WARNINGS
452 if (avctx->thread_count > MAX_THREADS) {
453 av_log(avctx, AV_LOG_ERROR, "too many threads\n");
454 return AVERROR(EINVAL);
457 if (avctx->qmax <= 1) {
458 av_log(avctx, AV_LOG_ERROR, "qmax must be at least 2\n");
459 return AVERROR(EINVAL);
462 ctx->thread[0] = ctx;
463 for (i = 1; i < avctx->thread_count; i++) {
464 ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext));
465 memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext));
469 fail: // for FF_ALLOCZ_OR_GOTO
470 return AVERROR(ENOMEM);
473 static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
475 DNXHDEncContext *ctx = avctx->priv_data;
477 memset(buf, 0, ctx->data_offset);
480 AV_WB16(buf + 0x02, ctx->data_offset);
481 if (ctx->cid >= 1270 && ctx->cid <= 1274)
486 buf[5] = ctx->interlaced ? ctx->cur_field + 2 : 0x01;
487 buf[6] = 0x80; // crc flag off
488 buf[7] = 0xa0; // reserved
489 AV_WB16(buf + 0x18, avctx->height >> ctx->interlaced); // ALPF
490 AV_WB16(buf + 0x1a, avctx->width); // SPL
491 AV_WB16(buf + 0x1d, avctx->height >> ctx->interlaced); // NAL
493 buf[0x21] = ctx->cid_table->bit_depth == 10 ? 0x58 : 0x38;
494 buf[0x22] = 0x88 + (ctx->interlaced << 2);
495 AV_WB32(buf + 0x28, ctx->cid); // CID
496 buf[0x2c] = ctx->interlaced ? 0 : 0x80;
498 buf[0x5f] = 0x01; // UDL
500 buf[0x167] = 0x02; // reserved
501 AV_WB16(buf + 0x16a, ctx->m.mb_height * 4 + 4); // MSIPS
502 buf[0x16d] = ctx->m.mb_height; // Ns
503 buf[0x16f] = 0x10; // reserved
505 ctx->msip = buf + 0x170;
509 static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
513 nbits = av_log2_16bit(-2 * diff);
516 nbits = av_log2_16bit(2 * diff);
518 put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits,
519 (ctx->cid_table->dc_codes[nbits] << nbits) +
520 av_mod_uintp2(diff, nbits));
523 static av_always_inline
524 void dnxhd_encode_block(DNXHDEncContext *ctx, int16_t *block,
525 int last_index, int n)
527 int last_non_zero = 0;
530 dnxhd_encode_dc(ctx, block[0] - ctx->m.last_dc[n]);
531 ctx->m.last_dc[n] = block[0];
533 for (i = 1; i <= last_index; i++) {
534 j = ctx->m.intra_scantable.permutated[i];
537 int run_level = i - last_non_zero - 1;
538 int rlevel = (slevel << 1) | !!run_level;
539 put_bits(&ctx->m.pb, ctx->vlc_bits[rlevel], ctx->vlc_codes[rlevel]);
541 put_bits(&ctx->m.pb, ctx->run_bits[run_level],
542 ctx->run_codes[run_level]);
546 put_bits(&ctx->m.pb, ctx->vlc_bits[0], ctx->vlc_codes[0]); // EOB
549 static av_always_inline
550 void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n,
551 int qscale, int last_index)
553 const uint8_t *weight_matrix;
557 weight_matrix = (n & 2) ? ctx->cid_table->chroma_weight
558 : ctx->cid_table->luma_weight;
560 for (i = 1; i <= last_index; i++) {
561 int j = ctx->m.intra_scantable.permutated[i];
565 level = (1 - 2 * level) * qscale * weight_matrix[i];
566 if (ctx->cid_table->bit_depth == 10) {
567 if (weight_matrix[i] != 8)
571 if (weight_matrix[i] != 32)
577 level = (2 * level + 1) * qscale * weight_matrix[i];
578 if (ctx->cid_table->bit_depth == 10) {
579 if (weight_matrix[i] != 8)
583 if (weight_matrix[i] != 32)
593 static av_always_inline int dnxhd_ssd_block(int16_t *qblock, int16_t *block)
597 for (i = 0; i < 64; i++)
598 score += (block[i] - qblock[i]) * (block[i] - qblock[i]);
602 static av_always_inline
603 int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, int16_t *block, int last_index)
605 int last_non_zero = 0;
608 for (i = 1; i <= last_index; i++) {
609 j = ctx->m.intra_scantable.permutated[i];
612 int run_level = i - last_non_zero - 1;
613 bits += ctx->vlc_bits[(level << 1) |
614 !!run_level] + ctx->run_bits[run_level];
621 static av_always_inline
622 void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y)
624 const int bs = ctx->block_width_l2;
625 const int bw = 1 << bs;
626 int dct_y_offset = ctx->dct_y_offset;
627 int dct_uv_offset = ctx->dct_uv_offset;
628 int linesize = ctx->m.linesize;
629 int uvlinesize = ctx->m.uvlinesize;
630 const uint8_t *ptr_y = ctx->thread[0]->src[0] +
631 ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs + 1);
632 const uint8_t *ptr_u = ctx->thread[0]->src[1] +
633 ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
634 const uint8_t *ptr_v = ctx->thread[0]->src[2] +
635 ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
636 PixblockDSPContext *pdsp = &ctx->m.pdsp;
637 VideoDSPContext *vdsp = &ctx->m.vdsp;
639 if (vdsp->emulated_edge_mc && ((mb_x << 4) + 16 > ctx->m.avctx->width ||
640 (mb_y << 4) + 16 > ctx->m.avctx->height)) {
641 int y_w = ctx->m.avctx->width - (mb_x << 4);
642 int y_h = ctx->m.avctx->height - (mb_y << 4);
643 int uv_w = (y_w + 1) / 2;
648 vdsp->emulated_edge_mc(&ctx->edge_buf_y[0], ptr_y,
649 linesize, ctx->m.linesize,
652 vdsp->emulated_edge_mc(&ctx->edge_buf_uv[0][0], ptr_u,
653 uvlinesize, ctx->m.uvlinesize,
656 vdsp->emulated_edge_mc(&ctx->edge_buf_uv[1][0], ptr_v,
657 uvlinesize, ctx->m.uvlinesize,
661 dct_y_offset = bw * linesize;
662 dct_uv_offset = bw * uvlinesize;
663 ptr_y = &ctx->edge_buf_y[0];
664 ptr_u = &ctx->edge_buf_uv[0][0];
665 ptr_v = &ctx->edge_buf_uv[1][0];
668 pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize);
669 pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize);
670 pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize);
671 pdsp->get_pixels(ctx->blocks[3], ptr_v, uvlinesize);
673 if (mb_y + 1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) {
674 if (ctx->interlaced) {
675 ctx->get_pixels_8x4_sym(ctx->blocks[4],
676 ptr_y + dct_y_offset,
678 ctx->get_pixels_8x4_sym(ctx->blocks[5],
679 ptr_y + dct_y_offset + bw,
681 ctx->get_pixels_8x4_sym(ctx->blocks[6],
682 ptr_u + dct_uv_offset,
684 ctx->get_pixels_8x4_sym(ctx->blocks[7],
685 ptr_v + dct_uv_offset,
688 ctx->bdsp.clear_block(ctx->blocks[4]);
689 ctx->bdsp.clear_block(ctx->blocks[5]);
690 ctx->bdsp.clear_block(ctx->blocks[6]);
691 ctx->bdsp.clear_block(ctx->blocks[7]);
694 pdsp->get_pixels(ctx->blocks[4],
695 ptr_y + dct_y_offset, linesize);
696 pdsp->get_pixels(ctx->blocks[5],
697 ptr_y + dct_y_offset + bw, linesize);
698 pdsp->get_pixels(ctx->blocks[6],
699 ptr_u + dct_uv_offset, uvlinesize);
700 pdsp->get_pixels(ctx->blocks[7],
701 ptr_v + dct_uv_offset, uvlinesize);
705 static av_always_inline
706 int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
708 const static uint8_t component[8]={0,0,1,2,0,0,1,2};
712 static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
713 int jobnr, int threadnr)
715 DNXHDEncContext *ctx = avctx->priv_data;
716 int mb_y = jobnr, mb_x;
717 int qscale = ctx->qscale;
718 LOCAL_ALIGNED_16(int16_t, block, [64]);
719 ctx = ctx->thread[threadnr];
723 ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
725 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
726 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
732 dnxhd_get_blocks(ctx, mb_x, mb_y);
734 for (i = 0; i < 8; i++) {
735 int16_t *src_block = ctx->blocks[i];
736 int overflow, nbits, diff, last_index;
737 int n = dnxhd_switch_matrix(ctx, i);
739 memcpy(block, src_block, 64 * sizeof(*block));
740 last_index = ctx->m.dct_quantize(&ctx->m, block, 4 & (2*i),
742 ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index);
744 diff = block[0] - ctx->m.last_dc[n];
746 nbits = av_log2_16bit(-2 * diff);
748 nbits = av_log2_16bit(2 * diff);
750 av_assert1(nbits < ctx->cid_table->bit_depth + 4);
751 dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
753 ctx->m.last_dc[n] = block[0];
755 if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) {
756 dnxhd_unquantize_c(ctx, block, i, qscale, last_index);
757 ctx->m.idsp.idct(block);
758 ssd += dnxhd_ssd_block(block, src_block);
761 ctx->mb_rc[(qscale * ctx->m.mb_num) + mb].ssd = ssd;
762 ctx->mb_rc[(qscale * ctx->m.mb_num) + mb].bits = ac_bits + dc_bits + 12 +
763 8 * ctx->vlc_bits[0];
768 static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg,
769 int jobnr, int threadnr)
771 DNXHDEncContext *ctx = avctx->priv_data;
772 int mb_y = jobnr, mb_x;
773 ctx = ctx->thread[threadnr];
774 init_put_bits(&ctx->m.pb, (uint8_t *)arg + ctx->data_offset + ctx->slice_offs[jobnr],
775 ctx->slice_size[jobnr]);
779 ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
780 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
781 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
782 int qscale = ctx->mb_qscale[mb];
785 put_bits(&ctx->m.pb, 12, qscale << 1);
787 dnxhd_get_blocks(ctx, mb_x, mb_y);
789 for (i = 0; i < 8; i++) {
790 int16_t *block = ctx->blocks[i];
791 int overflow, n = dnxhd_switch_matrix(ctx, i);
792 int last_index = ctx->m.dct_quantize(&ctx->m, block, 4 & (2*i),
795 dnxhd_encode_block(ctx, block, last_index, n);
796 // STOP_TIMER("encode_block");
799 if (put_bits_count(&ctx->m.pb) & 31)
800 put_bits(&ctx->m.pb, 32 - (put_bits_count(&ctx->m.pb) & 31), 0);
801 flush_put_bits(&ctx->m.pb);
805 static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
809 for (mb_y = 0; mb_y < ctx->m.mb_height; mb_y++) {
811 ctx->slice_offs[mb_y] = offset;
812 ctx->slice_size[mb_y] = 0;
813 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
814 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
815 ctx->slice_size[mb_y] += ctx->mb_bits[mb];
817 ctx->slice_size[mb_y] = (ctx->slice_size[mb_y] + 31) & ~31;
818 ctx->slice_size[mb_y] >>= 3;
819 thread_size = ctx->slice_size[mb_y];
820 offset += thread_size;
824 static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg,
825 int jobnr, int threadnr)
827 DNXHDEncContext *ctx = avctx->priv_data;
828 int mb_y = jobnr, mb_x, x, y;
829 int partial_last_row = (mb_y == ctx->m.mb_height - 1) &&
830 ((avctx->height >> ctx->interlaced) & 0xF);
832 ctx = ctx->thread[threadnr];
833 if (ctx->cid_table->bit_depth == 8) {
834 uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize);
835 for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) {
836 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
840 if (!partial_last_row && mb_x * 16 <= avctx->width - 16 && (avctx->width % 16) == 0) {
841 sum = ctx->m.mpvencdsp.pix_sum(pix, ctx->m.linesize);
842 varc = ctx->m.mpvencdsp.pix_norm1(pix, ctx->m.linesize);
844 int bw = FFMIN(avctx->width - 16 * mb_x, 16);
845 int bh = FFMIN((avctx->height >> ctx->interlaced) - 16 * mb_y, 16);
847 for (y = 0; y < bh; y++) {
848 for (x = 0; x < bw; x++) {
849 uint8_t val = pix[x + y * ctx->m.linesize];
855 varc = (varc - (((unsigned) sum * sum) >> 8) + 128) >> 8;
857 ctx->mb_cmp[mb].value = varc;
858 ctx->mb_cmp[mb].mb = mb;
861 const int linesize = ctx->m.linesize >> 1;
862 for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x) {
863 uint16_t *pix = (uint16_t *)ctx->thread[0]->src[0] +
864 ((mb_y << 4) * linesize) + (mb_x << 4);
865 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
868 int bw = FFMIN(avctx->width - 16 * mb_x, 16);
869 int bh = FFMIN((avctx->height >> ctx->interlaced) - 16 * mb_y, 16);
872 // Macroblocks are 16x16 pixels, unlike DCT blocks which are 8x8.
873 for (i = 0; i < bh; ++i) {
874 for (j = 0; j < bw; ++j) {
875 // Turn 16-bit pixels into 10-bit ones.
876 const int sample = (unsigned) pix[j] >> 6;
878 sqsum += sample * sample;
879 // 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX
883 mean = sum >> 8; // 16*16 == 2^8
885 ctx->mb_cmp[mb].value = sqmean - mean * mean;
886 ctx->mb_cmp[mb].mb = mb;
892 static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
894 int lambda, up_step, down_step;
895 int last_lower = INT_MAX, last_higher = 0;
898 for (q = 1; q < avctx->qmax; q++) {
900 avctx->execute2(avctx, dnxhd_calc_bits_thread,
901 NULL, NULL, ctx->m.mb_height);
903 up_step = down_step = 2 << LAMBDA_FRAC_BITS;
904 lambda = ctx->lambda;
909 if (lambda == last_higher) {
911 end = 1; // need to set final qscales/bits
913 for (y = 0; y < ctx->m.mb_height; y++) {
914 for (x = 0; x < ctx->m.mb_width; x++) {
915 unsigned min = UINT_MAX;
917 int mb = y * ctx->m.mb_width + x;
919 for (q = 1; q < avctx->qmax; q++) {
920 int i = (q*ctx->m.mb_num) + mb;
921 unsigned score = ctx->mb_rc[i].bits * lambda +
922 ((unsigned) ctx->mb_rc[i].ssd << LAMBDA_FRAC_BITS);
929 bits += ctx->mb_rc[rc].bits;
930 ctx->mb_qscale[mb] = qscale;
931 ctx->mb_bits[mb] = ctx->mb_rc[rc].bits;
933 bits = (bits + 31) & ~31; // padding
934 if (bits > ctx->frame_bits)
937 // ff_dlog(ctx->m.avctx,
938 // "lambda %d, up %u, down %u, bits %d, frame %d\n",
939 // lambda, last_higher, last_lower, bits, ctx->frame_bits);
941 if (bits > ctx->frame_bits)
942 return AVERROR(EINVAL);
945 if (bits < ctx->frame_bits) {
946 last_lower = FFMIN(lambda, last_lower);
947 if (last_higher != 0)
948 lambda = (lambda+last_higher)>>1;
951 down_step = FFMIN((int64_t)down_step*5, INT_MAX);
952 up_step = 1<<LAMBDA_FRAC_BITS;
953 lambda = FFMAX(1, lambda);
954 if (lambda == last_lower)
957 last_higher = FFMAX(lambda, last_higher);
958 if (last_lower != INT_MAX)
959 lambda = (lambda+last_lower)>>1;
960 else if ((int64_t)lambda + up_step > INT_MAX)
961 return AVERROR(EINVAL);
964 up_step = FFMIN((int64_t)up_step*5, INT_MAX);
965 down_step = 1<<LAMBDA_FRAC_BITS;
968 //ff_dlog(ctx->m.avctx, "out lambda %d\n", lambda);
969 ctx->lambda = lambda;
973 static int dnxhd_find_qscale(DNXHDEncContext *ctx)
979 int last_lower = INT_MAX;
983 qscale = ctx->qscale;
986 ctx->qscale = qscale;
987 // XXX avoid recalculating bits
988 ctx->m.avctx->execute2(ctx->m.avctx, dnxhd_calc_bits_thread,
989 NULL, NULL, ctx->m.mb_height);
990 for (y = 0; y < ctx->m.mb_height; y++) {
991 for (x = 0; x < ctx->m.mb_width; x++)
992 bits += ctx->mb_rc[(qscale*ctx->m.mb_num) + (y*ctx->m.mb_width+x)].bits;
993 bits = (bits+31)&~31; // padding
994 if (bits > ctx->frame_bits)
997 // ff_dlog(ctx->m.avctx,
998 // "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n",
999 // ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits,
1000 // last_higher, last_lower);
1001 if (bits < ctx->frame_bits) {
1004 if (last_higher == qscale - 1) {
1005 qscale = last_higher;
1008 last_lower = FFMIN(qscale, last_lower);
1009 if (last_higher != 0)
1010 qscale = (qscale + last_higher) >> 1;
1012 qscale -= down_step++;
1017 if (last_lower == qscale + 1)
1019 last_higher = FFMAX(qscale, last_higher);
1020 if (last_lower != INT_MAX)
1021 qscale = (qscale + last_lower) >> 1;
1023 qscale += up_step++;
1025 if (qscale >= ctx->m.avctx->qmax)
1026 return AVERROR(EINVAL);
1029 //ff_dlog(ctx->m.avctx, "out qscale %d\n", qscale);
1030 ctx->qscale = qscale;
1034 #define BUCKET_BITS 8
1035 #define RADIX_PASSES 4
1036 #define NBUCKETS (1 << BUCKET_BITS)
1038 static inline int get_bucket(int value, int shift)
1041 value &= NBUCKETS - 1;
1042 return NBUCKETS - 1 - value;
1045 static void radix_count(const RCCMPEntry *data, int size,
1046 int buckets[RADIX_PASSES][NBUCKETS])
1049 memset(buckets, 0, sizeof(buckets[0][0]) * RADIX_PASSES * NBUCKETS);
1050 for (i = 0; i < size; i++) {
1051 int v = data[i].value;
1052 for (j = 0; j < RADIX_PASSES; j++) {
1053 buckets[j][get_bucket(v, 0)]++;
1058 for (j = 0; j < RADIX_PASSES; j++) {
1060 for (i = NBUCKETS - 1; i >= 0; i--)
1061 buckets[j][i] = offset -= buckets[j][i];
1062 av_assert1(!buckets[j][0]);
1066 static void radix_sort_pass(RCCMPEntry *dst, const RCCMPEntry *data,
1067 int size, int buckets[NBUCKETS], int pass)
1069 int shift = pass * BUCKET_BITS;
1071 for (i = 0; i < size; i++) {
1072 int v = get_bucket(data[i].value, shift);
1073 int pos = buckets[v]++;
1078 static void radix_sort(RCCMPEntry *data, RCCMPEntry *tmp, int size)
1080 int buckets[RADIX_PASSES][NBUCKETS];
1081 radix_count(data, size, buckets);
1082 radix_sort_pass(tmp, data, size, buckets[0], 0);
1083 radix_sort_pass(data, tmp, size, buckets[1], 1);
1084 if (buckets[2][NBUCKETS - 1] || buckets[3][NBUCKETS - 1]) {
1085 radix_sort_pass(tmp, data, size, buckets[2], 2);
1086 radix_sort_pass(data, tmp, size, buckets[3], 3);
1090 static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
1094 if ((ret = dnxhd_find_qscale(ctx)) < 0)
1096 for (y = 0; y < ctx->m.mb_height; y++) {
1097 for (x = 0; x < ctx->m.mb_width; x++) {
1098 int mb = y * ctx->m.mb_width + x;
1099 int rc = (ctx->qscale * ctx->m.mb_num ) + mb;
1101 ctx->mb_qscale[mb] = ctx->qscale;
1102 ctx->mb_bits[mb] = ctx->mb_rc[rc].bits;
1103 max_bits += ctx->mb_rc[rc].bits;
1105 delta_bits = ctx->mb_rc[rc].bits -
1106 ctx->mb_rc[rc + ctx->m.mb_num].bits;
1107 ctx->mb_cmp[mb].mb = mb;
1108 ctx->mb_cmp[mb].value =
1109 delta_bits ? ((ctx->mb_rc[rc].ssd -
1110 ctx->mb_rc[rc + ctx->m.mb_num].ssd) * 100) /
1112 : INT_MIN; // avoid increasing qscale
1115 max_bits += 31; // worst padding
1119 avctx->execute2(avctx, dnxhd_mb_var_thread,
1120 NULL, NULL, ctx->m.mb_height);
1121 radix_sort(ctx->mb_cmp, ctx->mb_cmp_tmp, ctx->m.mb_num);
1122 for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) {
1123 int mb = ctx->mb_cmp[x].mb;
1124 int rc = (ctx->qscale * ctx->m.mb_num ) + mb;
1125 max_bits -= ctx->mb_rc[rc].bits -
1126 ctx->mb_rc[rc + ctx->m.mb_num].bits;
1127 ctx->mb_qscale[mb] = ctx->qscale + 1;
1128 ctx->mb_bits[mb] = ctx->mb_rc[rc + ctx->m.mb_num].bits;
1134 static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame)
1138 for (i = 0; i < ctx->m.avctx->thread_count; i++) {
1139 ctx->thread[i]->m.linesize = frame->linesize[0] << ctx->interlaced;
1140 ctx->thread[i]->m.uvlinesize = frame->linesize[1] << ctx->interlaced;
1141 ctx->thread[i]->dct_y_offset = ctx->m.linesize *8;
1142 ctx->thread[i]->dct_uv_offset = ctx->m.uvlinesize*8;
1145 #if FF_API_CODED_FRAME
1146 FF_DISABLE_DEPRECATION_WARNINGS
1147 ctx->m.avctx->coded_frame->interlaced_frame = frame->interlaced_frame;
1148 FF_ENABLE_DEPRECATION_WARNINGS
1150 ctx->cur_field = frame->interlaced_frame && !frame->top_field_first;
1153 static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
1154 const AVFrame *frame, int *got_packet)
1156 DNXHDEncContext *ctx = avctx->priv_data;
1157 int first_field = 1;
1161 if ((ret = ff_alloc_packet2(avctx, pkt, ctx->frame_size, 0)) < 0)
1165 dnxhd_load_picture(ctx, frame);
1168 for (i = 0; i < 3; i++) {
1169 ctx->src[i] = frame->data[i];
1170 if (ctx->interlaced && ctx->cur_field)
1171 ctx->src[i] += frame->linesize[i];
1174 dnxhd_write_header(avctx, buf);
1176 if (avctx->mb_decision == FF_MB_DECISION_RD)
1177 ret = dnxhd_encode_rdo(avctx, ctx);
1179 ret = dnxhd_encode_fast(avctx, ctx);
1181 av_log(avctx, AV_LOG_ERROR,
1182 "picture could not fit ratecontrol constraints, increase qmax\n");
1186 dnxhd_setup_threads_slices(ctx);
1189 for (i = 0; i < ctx->m.mb_height; i++) {
1190 AV_WB32(ctx->msip + i * 4, offset);
1191 offset += ctx->slice_size[i];
1192 av_assert1(!(ctx->slice_size[i] & 3));
1195 avctx->execute2(avctx, dnxhd_encode_thread, buf, NULL, ctx->m.mb_height);
1197 av_assert1(ctx->data_offset + offset + 4 <= ctx->coding_unit_size);
1198 memset(buf + ctx->data_offset + offset, 0,
1199 ctx->coding_unit_size - 4 - offset - ctx->data_offset);
1201 AV_WB32(buf + ctx->coding_unit_size - 4, 0x600DC0DE); // EOF
1203 if (ctx->interlaced && first_field) {
1205 ctx->cur_field ^= 1;
1206 buf += ctx->coding_unit_size;
1207 goto encode_coding_unit;
1210 #if FF_API_CODED_FRAME
1211 FF_DISABLE_DEPRECATION_WARNINGS
1212 avctx->coded_frame->quality = ctx->qscale * FF_QP2LAMBDA;
1213 FF_ENABLE_DEPRECATION_WARNINGS
1216 ff_side_data_set_encoder_stats(pkt, ctx->qscale * FF_QP2LAMBDA, NULL, 0, AV_PICTURE_TYPE_I);
1218 pkt->flags |= AV_PKT_FLAG_KEY;
1223 static av_cold int dnxhd_encode_end(AVCodecContext *avctx)
1225 DNXHDEncContext *ctx = avctx->priv_data;
1226 int max_level = 1 << (ctx->cid_table->bit_depth + 2);
1229 av_free(ctx->vlc_codes - max_level * 2);
1230 av_free(ctx->vlc_bits - max_level * 2);
1231 av_freep(&ctx->run_codes);
1232 av_freep(&ctx->run_bits);
1234 av_freep(&ctx->mb_bits);
1235 av_freep(&ctx->mb_qscale);
1236 av_freep(&ctx->mb_rc);
1237 av_freep(&ctx->mb_cmp);
1238 av_freep(&ctx->mb_cmp_tmp);
1239 av_freep(&ctx->slice_size);
1240 av_freep(&ctx->slice_offs);
1242 av_freep(&ctx->qmatrix_c);
1243 av_freep(&ctx->qmatrix_l);
1244 av_freep(&ctx->qmatrix_c16);
1245 av_freep(&ctx->qmatrix_l16);
1247 for (i = 1; i < avctx->thread_count; i++)
1248 av_freep(&ctx->thread[i]);
1253 static const AVCodecDefault dnxhd_defaults[] = {
1254 { "qmax", "1024" }, /* Maximum quantization scale factor allowed for VC-3 */
1258 AVCodec ff_dnxhd_encoder = {
1260 .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
1261 .type = AVMEDIA_TYPE_VIDEO,
1262 .id = AV_CODEC_ID_DNXHD,
1263 .priv_data_size = sizeof(DNXHDEncContext),
1264 .init = dnxhd_encode_init,
1265 .encode2 = dnxhd_encode_picture,
1266 .close = dnxhd_encode_end,
1267 .capabilities = AV_CODEC_CAP_SLICE_THREADS,
1268 .pix_fmts = (const enum AVPixelFormat[]) {
1270 AV_PIX_FMT_YUV422P10,
1273 .priv_class = &dnxhd_class,
1274 .defaults = dnxhd_defaults,
1275 .profiles = NULL_IF_CONFIG_SMALL(ff_dnxhd_profiles),