From patchwork Mon Mar 27 18:08:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 3132 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp283133vss; Mon, 27 Mar 2017 11:16:04 -0700 (PDT) X-Received: by 10.223.134.173 with SMTP id 42mr8636177wrx.130.1490638564230; Mon, 27 Mar 2017 11:16:04 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 59si1683048wrn.36.2017.03.27.11.16.03; Mon, 27 Mar 2017 11:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 98C99688378; Mon, 27 Mar 2017 21:15:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA2C26805E1 for ; Mon, 27 Mar 2017 21:15:32 +0300 (EEST) Received: by mail-wr0-f195.google.com with SMTP id w43so12782158wrb.1 for ; Mon, 27 Mar 2017 11:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=KVKiBKv0pQ8KalgjqQGOe6DL3yH6HaZlfJA+2uduyow=; b=CjvjMEQ1MnirN2Ghti1YQfq4lEV5g2w9Va7HQNM3FE22XirZfPHXenOXV9fnlRHpmE UhyGQfsjtCuabfmPgy47uffU8yJmzHyWoEcCKopqTsSwdMvdmx1sXZAQhaMWb3ATc99W DdUh+4u3ZHPCbYuQw2Louz36kiVq5gQJDKf7IbpAslTIVpuLJ+mAcKq/jRCUwL6YmzGT k97+5zcgq2+Uih9AZnsEGwu8Xmwlo9Dmwtb9HG/zTklFxOTN/RmhWDAMQtpmC458PX6P esOIZhGegxzXg2j9P6UcAYJ0wTUGv7prAeXgF2k3Qp+EHS2MxMGxEnzBxruejs2yu5LP XfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=KVKiBKv0pQ8KalgjqQGOe6DL3yH6HaZlfJA+2uduyow=; b=jwb7mwRFzZhT0ZWLxarPAVnyWhyVpHVLB9LLLWGqksqDcIu7pHsoaIYLsuZptz4PBF 16YfXufT6uuoEgQPapzflBXYYg8ofmb/RvkGU67uC5zk4H3P5nOpN2MTbWwn9wmGZWhc 003R9whyqcwTrr5pLREXJBmHHYYKS37gtWggwOEzbrfF5vnPg7XGfD6ywJttqtfLvkkb Ec9JPWuRDd9t9GLjP1DkS0zegtu5MUh36xSr/FmHQxLnYMGGW+uhwULKlDAzsNk5x7+i 2EwnS+hcnVK8Fiy31u3XdISN4MpOaINJQUk/+sp53eosW4rFTWxgl949ADfFSfFjvULi LboA== X-Gm-Message-State: AFeK/H3cm6+DDViN0tCcSgBw5HY6QLSBi+gmfVYZJ+6P5tli776tI1nAzy7XT2yUeOOlZA== X-Received: by 10.223.130.102 with SMTP id 93mr15782226wrb.59.1490638135881; Mon, 27 Mar 2017 11:08:55 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id v108sm1629871wrc.41.2017.03.27.11.08.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 11:08:55 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Mar 2017 20:08:35 +0200 Message-Id: <20170327180835.25486-1-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avcodec/dnxhdenc: DNxHR 444 and HQX support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/dnxhdenc.c | 227 +++++++++++++++++++++++++++++++++++--------------- libavcodec/dnxhdenc.h | 6 +- 2 files changed, 163 insertions(+), 70 deletions(-) diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 33f25fb..6716b74 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -23,6 +23,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define ASSERT_LEVEL 10 + #include "libavutil/attributes.h" #include "libavutil/internal.h" #include "libavutil/opt.h" @@ -112,6 +114,37 @@ void dnxhd_10bit_get_pixels_8x4_sym(int16_t *av_restrict block, memcpy(block + 4 * 8, pixels + 3 * line_size, 8 * sizeof(*block)); } +static int dnxhd_10bit_dct_quantize_444(MpegEncContext *ctx, int16_t *block, + int n, int qscale, int *overflow) +{ + const uint8_t *scantable= ctx->intra_scantable.scantable; + const int *qmat = n<4 ? ctx->q_intra_matrix[qscale] : ctx->q_chroma_intra_matrix[qscale]; + int last_non_zero = 0; + int i; + + ctx->fdsp.fdct(block); + + // Divide by 4 with rounding, to compensate scaling of DCT coefficients + block[0] = (block[0] + 2) >> 2; + + for (i = 1; i < 64; ++i) { + int j = scantable[i]; + int sign = FF_SIGNBIT(block[j]); + int level = (block[j] ^ sign) - sign; + level = level * qmat[j] >> 16; + block[j] = (level ^ sign) - sign; + if (level) + last_non_zero = i; + } + + /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ + if (ctx->idsp.perm_type != FF_IDCT_PERM_NONE) + ff_block_permute(block, ctx->idsp.idct_permutation, + scantable, last_non_zero); + + return last_non_zero; +} + static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block, int n, int qscale, int *overflow) { @@ -146,7 +179,7 @@ static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block, static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx) { int i, j, level, run; - int max_level = 1 << (ctx->cid_table->bit_depth + 2); + int max_level = 1 << (ctx->bit_depth + 2); FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level, 4 * sizeof(*ctx->vlc_codes), fail); @@ -223,7 +256,7 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) (ctx->m.avctx->qmax + 1), 64 * 2 * sizeof(uint16_t), fail); - if (ctx->cid_table->bit_depth == 8) { + if (ctx->bit_depth == 8) { for (i = 1; i < 64; i++) { int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]]; weight_matrix[j] = ctx->cid_table->luma_weight[i]; @@ -309,17 +342,20 @@ static int dnxhd_get_hr_frame_size(const CIDEntry* profile, int mb_num) result = (result + 2048) / 4096 * 4096; return FFMAX(result, 8192); } + static av_cold int dnxhd_encode_init(AVCodecContext *avctx) { DNXHDEncContext *ctx = avctx->priv_data; - int i, index, bit_depth, ret; + int i, index, ret; switch (avctx->pix_fmt) { case AV_PIX_FMT_YUV422P: - bit_depth = 8; + ctx->bit_depth = 8; break; case AV_PIX_FMT_YUV422P10: - bit_depth = 10; + case AV_PIX_FMT_YUV444P10: + case AV_PIX_FMT_GBRP10: + ctx->bit_depth = 10; break; default: av_log(avctx, AV_LOG_ERROR, @@ -327,15 +363,32 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (ctx->profile == FF_PROFILE_DNXHR_444 || - ctx->profile == FF_PROFILE_DNXHR_HQX) { - avpriv_report_missing_feature(avctx, - "dnxhr_444 or dnxhr_hqx profile"); - return AVERROR_PATCHWELCOME; + if ((ctx->profile == FF_PROFILE_DNXHR_444 && (avctx->pix_fmt != AV_PIX_FMT_YUV444P10 && + avctx->pix_fmt != AV_PIX_FMT_GBRP10)) || + (ctx->profile != FF_PROFILE_DNXHR_444 && (avctx->pix_fmt == AV_PIX_FMT_YUV444P10 || + avctx->pix_fmt == AV_PIX_FMT_GBRP10))) { + av_log(avctx, AV_LOG_ERROR, + "pixel format is incompatible with DNxHD profile\n"); + return AVERROR(EINVAL); + } + + if (ctx->profile == FF_PROFILE_DNXHR_HQX && avctx->pix_fmt != AV_PIX_FMT_YUV422P10) { + av_log(avctx, AV_LOG_ERROR, + "pixel format is incompatible with DNxHR HQX profile\n"); + return AVERROR(EINVAL); + } + + if ((ctx->profile == FF_PROFILE_DNXHR_LB || + ctx->profile == FF_PROFILE_DNXHR_SQ || + ctx->profile == FF_PROFILE_DNXHR_HQ) && avctx->pix_fmt != AV_PIX_FMT_YUV422P) { + av_log(avctx, AV_LOG_ERROR, + "pixel format is incompatible with DNxHR LB/SQ/HQ profile\n"); + return AVERROR(EINVAL); } + ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444; avctx->profile = ctx->profile; - ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth); + ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth); if (!ctx->cid) { av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD. Valid DNxHD profiles:\n"); @@ -362,7 +415,7 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) ctx->m.mb_intra = 1; ctx->m.h263_aic = 1; - avctx->bits_per_raw_sample = ctx->cid_table->bit_depth; + avctx->bits_per_raw_sample = ctx->bit_depth; ff_blockdsp_init(&ctx->bdsp, avctx); ff_fdctdsp_init(&ctx->m.fdsp, avctx); @@ -372,12 +425,16 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) ff_dct_encode_init(&ctx->m); if (ctx->profile != FF_PROFILE_DNXHD) - ff_videodsp_init(&ctx->m.vdsp, bit_depth); + ff_videodsp_init(&ctx->m.vdsp, ctx->bit_depth); if (!ctx->m.dct_quantize) ctx->m.dct_quantize = ff_dct_quantize_c; - if (ctx->cid_table->bit_depth == 10) { + if (ctx->is_444 || ctx->profile == FF_PROFILE_DNXHR_HQX) { + ctx->m.dct_quantize = dnxhd_10bit_dct_quantize_444; + ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym; + ctx->block_width_l2 = 4; + } else if (ctx->bit_depth == 10) { ctx->m.dct_quantize = dnxhd_10bit_dct_quantize; ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym; ctx->block_width_l2 = 4; @@ -490,10 +547,10 @@ static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf) AV_WB16(buf + 0x1a, avctx->width); // SPL AV_WB16(buf + 0x1d, avctx->height >> ctx->interlaced); // NAL - buf[0x21] = ctx->cid_table->bit_depth == 10 ? 0x58 : 0x38; + buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38; buf[0x22] = 0x88 + (ctx->interlaced << 2); AV_WB32(buf + 0x28, ctx->cid); // CID - buf[0x2c] = ctx->interlaced ? 0 : 0x80; + buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10); buf[0x5f] = 0x01; // UDL @@ -554,8 +611,13 @@ void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n, int level; int i; - weight_matrix = (n & 2) ? ctx->cid_table->chroma_weight - : ctx->cid_table->luma_weight; + if (ctx->is_444) { + weight_matrix = ((n % 6) < 2) ? ctx->cid_table->luma_weight + : ctx->cid_table->chroma_weight; + } else { + weight_matrix = (n & 2) ? ctx->cid_table->chroma_weight + : ctx->cid_table->luma_weight; + } for (i = 1; i <= last_index; i++) { int j = ctx->m.intra_scantable.permutated[i]; @@ -563,7 +625,7 @@ void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n, if (level) { if (level < 0) { level = (1 - 2 * level) * qscale * weight_matrix[i]; - if (ctx->cid_table->bit_depth == 10) { + if (ctx->bit_depth == 10) { if (weight_matrix[i] != 8) level += 8; level >>= 4; @@ -575,7 +637,7 @@ void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n, level = -level; } else { level = (2 * level + 1) * qscale * weight_matrix[i]; - if (ctx->cid_table->bit_depth == 10) { + if (ctx->bit_depth == 10) { if (weight_matrix[i] != 8) level += 8; level >>= 4; @@ -630,9 +692,9 @@ void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs + 1); const uint8_t *ptr_u = ctx->thread[0]->src[1] + - ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs); + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs + ctx->is_444); const uint8_t *ptr_v = ctx->thread[0]->src[2] + - ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs); + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs + ctx->is_444); PixblockDSPContext *pdsp = &ctx->m.pdsp; VideoDSPContext *vdsp = &ctx->m.vdsp; @@ -640,9 +702,9 @@ void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) (mb_y << 4) + 16 > ctx->m.avctx->height)) { int y_w = ctx->m.avctx->width - (mb_x << 4); int y_h = ctx->m.avctx->height - (mb_y << 4); - int uv_w = (y_w + 1) / 2; + int uv_w = ctx->is_444 ? y_w : (y_w + 1) / 2; int uv_h = y_h; - linesize = 16; + linesize = 8 + 8 * !ctx->is_444; uvlinesize = 8; vdsp->emulated_edge_mc(&ctx->edge_buf_y[0], ptr_y, @@ -665,48 +727,72 @@ void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) ptr_v = &ctx->edge_buf_uv[1][0]; } - pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize); - pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize); - pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize); - pdsp->get_pixels(ctx->blocks[3], ptr_v, uvlinesize); - - if (mb_y + 1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) { - if (ctx->interlaced) { - ctx->get_pixels_8x4_sym(ctx->blocks[4], - ptr_y + dct_y_offset, - linesize); - ctx->get_pixels_8x4_sym(ctx->blocks[5], - ptr_y + dct_y_offset + bw, - linesize); - ctx->get_pixels_8x4_sym(ctx->blocks[6], - ptr_u + dct_uv_offset, - uvlinesize); - ctx->get_pixels_8x4_sym(ctx->blocks[7], - ptr_v + dct_uv_offset, - uvlinesize); + if (!ctx->is_444) { + pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize); + pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize); + pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize); + pdsp->get_pixels(ctx->blocks[3], ptr_v, uvlinesize); + + if (mb_y + 1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) { + if (ctx->interlaced) { + ctx->get_pixels_8x4_sym(ctx->blocks[4], + ptr_y + dct_y_offset, + linesize); + ctx->get_pixels_8x4_sym(ctx->blocks[5], + ptr_y + dct_y_offset + bw, + linesize); + ctx->get_pixels_8x4_sym(ctx->blocks[6], + ptr_u + dct_uv_offset, + uvlinesize); + ctx->get_pixels_8x4_sym(ctx->blocks[7], + ptr_v + dct_uv_offset, + uvlinesize); + } else { + ctx->bdsp.clear_block(ctx->blocks[4]); + ctx->bdsp.clear_block(ctx->blocks[5]); + ctx->bdsp.clear_block(ctx->blocks[6]); + ctx->bdsp.clear_block(ctx->blocks[7]); + } } else { - ctx->bdsp.clear_block(ctx->blocks[4]); - ctx->bdsp.clear_block(ctx->blocks[5]); - ctx->bdsp.clear_block(ctx->blocks[6]); - ctx->bdsp.clear_block(ctx->blocks[7]); + pdsp->get_pixels(ctx->blocks[4], + ptr_y + dct_y_offset, linesize); + pdsp->get_pixels(ctx->blocks[5], + ptr_y + dct_y_offset + bw, linesize); + pdsp->get_pixels(ctx->blocks[6], + ptr_u + dct_uv_offset, uvlinesize); + pdsp->get_pixels(ctx->blocks[7], + ptr_v + dct_uv_offset, uvlinesize); } } else { - pdsp->get_pixels(ctx->blocks[4], - ptr_y + dct_y_offset, linesize); - pdsp->get_pixels(ctx->blocks[5], - ptr_y + dct_y_offset + bw, linesize); - pdsp->get_pixels(ctx->blocks[6], - ptr_u + dct_uv_offset, uvlinesize); - pdsp->get_pixels(ctx->blocks[7], - ptr_v + dct_uv_offset, uvlinesize); + pdsp->get_pixels(ctx->blocks[0], ptr_y, linesize); + pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, linesize); + pdsp->get_pixels(ctx->blocks[6], ptr_y + dct_y_offset, linesize); + pdsp->get_pixels(ctx->blocks[7], ptr_y + dct_y_offset + bw, linesize); + + pdsp->get_pixels(ctx->blocks[2], ptr_u, uvlinesize); + pdsp->get_pixels(ctx->blocks[3], ptr_u + bw, uvlinesize); + pdsp->get_pixels(ctx->blocks[8], ptr_u + dct_uv_offset, uvlinesize); + pdsp->get_pixels(ctx->blocks[9], ptr_u + dct_uv_offset + bw, uvlinesize); + + pdsp->get_pixels(ctx->blocks[4], ptr_v, uvlinesize); + pdsp->get_pixels(ctx->blocks[5], ptr_v + bw, uvlinesize); + pdsp->get_pixels(ctx->blocks[10], ptr_v + dct_uv_offset, uvlinesize); + pdsp->get_pixels(ctx->blocks[11], ptr_v + dct_uv_offset + bw, uvlinesize); } } static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i) { - const static uint8_t component[8]={0,0,1,2,0,0,1,2}; - return component[i]; + int x; + + if (ctx->is_444) { + x = (i >> 1) % 3; + } else { + const static uint8_t component[8]={0,0,1,2,0,0,1,2}; + x = component[i]; + } + return x; } static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, @@ -720,7 +806,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, ctx->m.last_dc[0] = ctx->m.last_dc[1] = - ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2); + ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2); for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { unsigned mb = mb_y * ctx->m.mb_width + mb_x; @@ -731,13 +817,14 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, dnxhd_get_blocks(ctx, mb_x, mb_y); - for (i = 0; i < 8; i++) { + for (i = 0; i < 8 + 4 * ctx->is_444; i++) { int16_t *src_block = ctx->blocks[i]; int overflow, nbits, diff, last_index; int n = dnxhd_switch_matrix(ctx, i); memcpy(block, src_block, 64 * sizeof(*block)); - last_index = ctx->m.dct_quantize(&ctx->m, block, 4 & (2*i), + last_index = ctx->m.dct_quantize(&ctx->m, block, + ctx->is_444 ? 4 * (n > 0): 4 & (2*i), qscale, &overflow); ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index); @@ -747,7 +834,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, else nbits = av_log2_16bit(2 * diff); - av_assert1(nbits < ctx->cid_table->bit_depth + 4); + av_assert1(nbits < ctx->bit_depth + 4); dc_bits += ctx->cid_table->dc_bits[nbits] + nbits; ctx->m.last_dc[n] = block[0]; @@ -760,7 +847,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, } ctx->mb_rc[(qscale * ctx->m.mb_num) + mb].ssd = ssd; ctx->mb_rc[(qscale * ctx->m.mb_num) + mb].bits = ac_bits + dc_bits + 12 + - 8 * ctx->vlc_bits[0]; + (1 + ctx->is_444) * 8 * ctx->vlc_bits[0]; } return 0; } @@ -776,20 +863,22 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, ctx->m.last_dc[0] = ctx->m.last_dc[1] = - ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2); + ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2); for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { unsigned mb = mb_y * ctx->m.mb_width + mb_x; int qscale = ctx->mb_qscale[mb]; int i; - put_bits(&ctx->m.pb, 12, qscale << 1); + put_bits(&ctx->m.pb, 11, qscale); + put_bits(&ctx->m.pb, 1, avctx->pix_fmt == AV_PIX_FMT_YUV444P10); dnxhd_get_blocks(ctx, mb_x, mb_y); - for (i = 0; i < 8; i++) { + for (i = 0; i < 8 + 4 * ctx->is_444; i++) { int16_t *block = ctx->blocks[i]; int overflow, n = dnxhd_switch_matrix(ctx, i); - int last_index = ctx->m.dct_quantize(&ctx->m, block, 4 & (2*i), + int last_index = ctx->m.dct_quantize(&ctx->m, block, + ctx->is_444 ? (((i >> 1) % 3) < 1 ? 0 : 4): 4 & (2*i), qscale, &overflow); // START_TIMER; dnxhd_encode_block(ctx, block, last_index, n); @@ -830,7 +919,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, ((avctx->height >> ctx->interlaced) & 0xF); ctx = ctx->thread[threadnr]; - if (ctx->cid_table->bit_depth == 8) { + if (ctx->bit_depth == 8) { uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize); for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) { unsigned mb = mb_y * ctx->m.mb_width + mb_x; @@ -1214,7 +1303,7 @@ FF_ENABLE_DEPRECATION_WARNINGS static av_cold int dnxhd_encode_end(AVCodecContext *avctx) { DNXHDEncContext *ctx = avctx->priv_data; - int max_level = 1 << (ctx->cid_table->bit_depth + 2); + int max_level = 1 << (ctx->bit_depth + 2); int i; av_free(ctx->vlc_codes - max_level * 2); @@ -1259,6 +1348,8 @@ AVCodec ff_dnxhd_encoder = { .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, + AV_PIX_FMT_YUV444P10, + AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE }, .priv_class = &dnxhd_class, diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h index eb9da12..3005a00 100644 --- a/libavcodec/dnxhdenc.h +++ b/libavcodec/dnxhdenc.h @@ -46,6 +46,8 @@ typedef struct DNXHDEncContext { int cid; int profile; + int bit_depth; + int is_444; const CIDEntry *cid_table; uint8_t *msip; ///< Macroblock Scan Indexes Payload uint32_t *slice_size; @@ -70,9 +72,9 @@ typedef struct DNXHDEncContext { unsigned min_padding; int intra_quant_bias; - DECLARE_ALIGNED(16, int16_t, blocks)[8][64]; + DECLARE_ALIGNED(16, int16_t, blocks)[12][64]; DECLARE_ALIGNED(16, uint8_t, edge_buf_y)[256]; - DECLARE_ALIGNED(16, uint8_t, edge_buf_uv)[2][128]; + DECLARE_ALIGNED(16, uint8_t, edge_buf_uv)[2][256]; int (*qmatrix_c) [64]; int (*qmatrix_l) [64];