[FFmpeg-devel] [PATCH v4 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy()

Pierre-Anthony Lemieux pal at sandflow.com
Mon Aug 1 00:53:24 EEST 2022


On Sun, Jul 31, 2022 at 2:02 PM James Almer <jamrial at gmail.com> wrote:
>
> On 7/31/2022 5:37 PM, pal at sandflow.com wrote:
> > diff --git a/libavformat/avformat.c b/libavformat/avformat.c
> > index 30d6ea6a49..1d0ac5ab7e 100644
> > --- a/libavformat/avformat.c
> > +++ b/libavformat/avformat.c
> > @@ -235,6 +235,47 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src)
> >       return 0;
> >   }
> >
> > +int ff_stream_params_copy(AVStream *dst, const AVStream *src)
> > +{
> > +    int ret;
> > +
> > +    dst->id                  = src->id;
> > +    dst->time_base           = src->time_base;
> > +    dst->start_time          = src->start_time;
> > +    dst->duration            = src->duration;
> > +    dst->nb_frames           = src->nb_frames;
> > +    dst->disposition         = src->disposition;
> > +    dst->discard             = src->discard;
> > +    dst->sample_aspect_ratio = src->sample_aspect_ratio;
> > +    dst->avg_frame_rate      = src->avg_frame_rate;
> > +    dst->event_flags         = src->event_flags;
> > +    dst->r_frame_rate        = src->r_frame_rate;
> > +    dst->pts_wrap_bits       = src->pts_wrap_bits;
> > +
> > +    av_dict_free(&dst->metadata);
> > +    ret = av_dict_copy(&dst->metadata, src->metadata, 0);
> > +    if (ret < 0)
> > +        return ret;
> > +
> > +    ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
> > +    if (ret < 0)
> > +        return ret;
> > +
> > +    ret = ff_stream_side_data_copy(dst, src);
> > +    if (ret < 0)
> > +        return ret;
> > +
> > +    if (src->attached_pic.size > 0) {
> > +        ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
> > +        if (ret < 0)
> > +            return ret;
> > +    } else {
> > +        av_packet_unref(&dst->attached_pic);
>
> This would need to be called unconditionally, like you did for
> dst->metadata, and just if src->attached_pic is empty.

Thanks. I had incorrectly assumed that av_packet_ref() first unref'ed
the destination.

Addressed at v5:
http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299515.html



>
> > +    }
> > +
> > +    return 0;
> > +}
> > +
> >   AVProgram *av_new_program(AVFormatContext *ac, int id)
> >   {
> >       AVProgram *program = NULL;
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list