ffmpeg | branch: master | Niklas Haas <g...@haasn.dev> | Tue Apr 9 14:00:41 2024 +0200| [2f3c1e1641af319b5c33e405e796f47e62cb0149] | committer: Niklas Haas
avcodec/libsvtav1: implement dolby vision coding > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2f3c1e1641af319b5c33e405e796f47e62cb0149 --- configure | 1 + libavcodec/libsvtav1.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/configure b/configure index 20499e7643..b101ed9256 100755 --- a/configure +++ b/configure @@ -3534,6 +3534,7 @@ libspeex_decoder_deps="libspeex" libspeex_encoder_deps="libspeex" libspeex_encoder_select="audio_frame_queue" libsvtav1_encoder_deps="libsvtav1" +libsvtav1_encoder_select="dovi_rpueenc" libtheora_encoder_deps="libtheora" libtwolame_encoder_deps="libtwolame" libuavs3d_decoder_deps="libuavs3d" diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 6ff893cf10..9bc165f0cf 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -23,6 +23,7 @@ #include <stdint.h> #include <EbSvtAv1ErrorCodes.h> #include <EbSvtAv1Enc.h> +#include <EbSvtAv1Metadata.h> #include "libavutil/common.h" #include "libavutil/frame.h" @@ -35,6 +36,7 @@ #include "libavutil/avassert.h" #include "codec_internal.h" +#include "dovi_rpu.h" #include "encode.h" #include "packet_internal.h" #include "avcodec.h" @@ -62,6 +64,8 @@ typedef struct SvtContext { EOS_STATUS eos_flag; + DOVIContext dovi; + // User options. AVDictionary *svtav1_opts; int enc_mode; @@ -418,6 +422,7 @@ static int read_in_data(EbSvtAv1EncConfiguration *param, const AVFrame *frame, in_data->cr_stride = AV_CEIL_RSHIFT(frame->linesize[2], bytes_shift); header_ptr->n_filled_len = frame_size; + svt_metadata_array_free(&header_ptr->metadata); return 0; } @@ -451,6 +456,11 @@ static av_cold int eb_enc_init(AVCodecContext *avctx) return svt_print_error(avctx, svt_ret, "Error initializing encoder"); } + svt_enc->dovi.logctx = avctx; + ret = ff_dovi_configure(&svt_enc->dovi, avctx); + if (ret < 0) + return ret; + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { EbBufferHeaderType *headerPtr = NULL; @@ -486,6 +496,7 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame) { SvtContext *svt_enc = avctx->priv_data; EbBufferHeaderType *headerPtr = svt_enc->in_buf; + AVFrameSideData *sd; EbErrorType svt_ret; int ret; @@ -525,6 +536,24 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame) if (avctx->gop_size == 1) headerPtr->pic_type = EB_AV1_KEY_PICTURE; + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DOVI_METADATA); + if (svt_enc->dovi.cfg.dv_profile && sd) { + const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data; + uint8_t *t35; + int size; + if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, &t35, &size)) < 0) + return ret; + ret = svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, t35, size); + av_free(t35); + if (ret < 0) + return AVERROR(ENOMEM); + } else if (svt_enc->dovi.cfg.dv_profile) { + av_log(avctx, AV_LOG_ERROR, "Dolby Vision enabled, but received frame " + "without AV_FRAME_DATA_DOVI_METADATA\n"); + return AVERROR_INVALIDDATA; + } + + svt_ret = svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr); if (svt_ret != EB_ErrorNone) return svt_print_error(avctx, svt_ret, "Error sending a frame to encoder"); @@ -649,11 +678,13 @@ static av_cold int eb_enc_close(AVCodecContext *avctx) } if (svt_enc->in_buf) { av_free(svt_enc->in_buf->p_buffer); + svt_metadata_array_free(&svt_enc->in_buf->metadata); av_freep(&svt_enc->in_buf); } av_buffer_pool_uninit(&svt_enc->pool); av_frame_free(&svt_enc->frame); + ff_dovi_ctx_unref(&svt_enc->dovi); return 0; } @@ -700,6 +731,9 @@ static const AVOption options[] = { AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE }, { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE }, + { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" }, + { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags = VE, .unit = "dovi" }, + {NULL}, }; _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".