[FFmpeg-devel] [PATCH 17/30] lavc: support AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE in all no-delay encoders
James Almer
jamrial at gmail.com
Sun Nov 27 22:00:01 EET 2022
On 11/27/2022 2:03 PM, Anton Khirnov wrote:
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index 7e2d54ae9b..e4270b6c34 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -220,6 +220,18 @@ int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
> avpkt->duration = ff_samples_to_time_base(avctx,
> frame->nb_samples);
> }
> +
> + avctx->reordered_opaque = frame->reordered_opaque;
> + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
> + avpkt->opaque = frame->opaque;
> + if (frame->opaque_ref) {
> + avpkt->opaque_ref = av_buffer_ref(frame->opaque_ref);
> + if (!avpkt->opaque_ref) {
> + ret = AVERROR(ENOMEM);
> + goto unref;
> + }
> + }
You could simplify this to simply
ret = av_buffer_replace(&avpkt->opaque_ref, frame->opaque_ref);
if (ret < 0)
return ret;
Here and elsewhere you did the same thing. No need to check for
frame->opaque_ref since av_buffer_replace() can handle NULL src, in
which case for this scenario (where avpkt->opaque_ref is always NULL) it
will be a no-op.
> + }
> }
>
> // dts equals pts unless there is reordering
More information about the ffmpeg-devel
mailing list