From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH v2 11/11] avcodec/libsvtav1: implement dolby vision coding Date: Tue, 9 Apr 2024 14:57:31 +0200 Message-ID: <20240409125914.61149-12-ffmpeg@haasn.xyz> (raw) In-Reply-To: <20240409125914.61149-1-ffmpeg@haasn.xyz> From: Niklas Haas <git@haasn.dev> --- libavcodec/libsvtav1.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 105c3369c0f..cd62103dba4 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; int ret; if (!frame) { @@ -524,6 +535,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_av1_enc_send_picture(svt_enc->svt_handle, headerPtr); return 0; @@ -644,11 +673,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; } @@ -695,6 +726,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}, }; -- 2.44.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2024-04-09 13:00 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-09 12:57 [FFmpeg-devel] [PATCH v2 00/11] avcodec: add Dolby Vision encoding Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 01/11] avcodec/dovi_rpu: store entire config record Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 02/11] avcodec/dovi_rpu: properly replace context header Niklas Haas 2024-04-09 15:36 ` Andreas Rheinhardt 2024-04-09 16:02 ` Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 03/11] avcodec/dovi_rpu: clarify error on missing RPU VDR Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 04/11] avcodec/dovi_rpu: clarify semantics of guess_profile() Niklas Haas 2024-04-09 15:37 ` Andreas Rheinhardt 2024-04-09 16:01 ` Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 05/11] avcodec/dovi_rpu: add ff_dovi_configure() Niklas Haas 2024-04-09 16:00 ` Andreas Rheinhardt 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 06/11] avcodec/dovi_rpu: make `enable` also affect decoding Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 07/11] avcodec/dovi_rpu: add ff_dovi_rpu_generate() Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 08/11] avformat/movenc: warn if dovi cfg ignored Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 09/11] avcodec/libaomenc: implement dolby vision coding Niklas Haas 2024-04-09 12:57 ` [FFmpeg-devel] [PATCH v2 10/11] avcodec/libx265: " Niklas Haas 2024-04-09 12:57 ` Niklas Haas [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240409125914.61149-12-ffmpeg@haasn.xyz \ --to=ffmpeg@haasn.xyz \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=git@haasn.dev \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git