From e0de84ad2e25632b9a2f402f9e71a222c00567bb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 22 Mar 2024 20:49:33 +0100 Subject: [PATCH] lavc/encode: map AVCodecContext.decoded_side_data to coded_side_data This way it can be automagically propagated through the encoder to muxing. --- libavcodec/encode.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 7fc9737e93..46e46a055e 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -782,6 +782,29 @@ int ff_encode_preinit(AVCodecContext *avctx) return AVERROR(ENOMEM); } + for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) { + const enum AVPacketSideDataType type_packet = ff_sd_global_map[i].packet; + const enum AVFrameSideDataType type_frame = ff_sd_global_map[i].frame; + const AVFrameSideData *sd_frame; + AVPacketSideData *sd_packet; + + sd_frame = av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + type_frame); + if (!sd_frame || + av_packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data, + type_packet)) + + continue; + + sd_packet = av_packet_side_data_new(&avctx->coded_side_data, &avctx->nb_coded_side_data, + type_packet, sd_frame->size, 0); + if (!sd_packet) + return AVERROR(ENOMEM); + + memcpy(sd_packet->data, sd_frame->data, sd_frame->size); + } + if (CONFIG_FRAME_THREAD_ENCODER) { ret = ff_frame_thread_encoder_init(avctx); if (ret < 0)