diff options
author | Pierre-Anthony Lemieux <pal@palemieux.com> | 2022-08-06 16:35:19 -0700 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-08-12 18:54:19 +0200 |
commit | f2403d1530aaf0b1a2f3833aaa6917e02ce147ac (patch) | |
tree | db4135866f68ef61f194ef2d2b01fb188e185fb9 /libavformat/avformat.c | |
parent | 7158f1e64d9b76afea78537a35c465447df0cff8 (diff) |
avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()
Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299726.html
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/avformat.c')
-rw-r--r-- | libavformat/avformat.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 30d6ea6a49..19c7219471 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -235,6 +235,72 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src) return 0; } +/** + * Copy all stream parameters from source to destination stream, with the + * exception of the index field, which is usually set by avformat_new_stream(). + * + * @param dst pointer to destination AVStream + * @param src pointer to source AVStream + * @return >=0 on success, AVERROR code on error + */ +static int 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; + + av_packet_unref(&dst->attached_pic); + if (src->attached_pic.data) { + ret = av_packet_ref(&dst->attached_pic, &src->attached_pic); + if (ret < 0) + return ret; + } + + return 0; +} + +AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src) +{ + AVStream *st; + int ret; + + st = avformat_new_stream(dst_ctx, NULL); + if (!st) + return NULL; + + ret = stream_params_copy(st, src); + if (ret < 0) { + ff_remove_stream(dst_ctx, st); + return NULL; + } + + return st; +} + AVProgram *av_new_program(AVFormatContext *ac, int id) { AVProgram *program = NULL; |