diff options
author | Marton Balint <cus@passwd.hu> | 2019-12-26 23:33:26 +0100 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2020-01-03 11:23:55 +0100 |
commit | d111a41f9d5c23856ddba61f65e35f7ba534288f (patch) | |
tree | 714e5b097c76f90ecd9f0d5bc194181f4f8e2c73 | |
parent | beb7f93b238f1b80ef0ad0e794a0f0ccc0625f03 (diff) | |
download | ffmpeg-d111a41f9d5c23856ddba61f65e35f7ba534288f.tar.gz |
avformat/img2enc: fix writing multiple streams in write_muxed_file
Maybe we should just reject multiple streams for the image2 muxer instead?
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r-- | libavformat/img2enc.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index 718c9929f7..39398f37a3 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -74,7 +74,7 @@ static int write_header(AVFormatContext *s) static int write_muxed_file(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) { VideoMuxData *img = s->priv_data; - AVCodecParameters *par = s->streams[0]->codecpar; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; AVStream *st; AVPacket pkt2 = {0}; AVFormatContext *fmt = NULL; @@ -93,12 +93,17 @@ static int write_muxed_file(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) fmt->pb = pb; - if ((ret = av_packet_ref(&pkt2, pkt)) < 0 || - (ret = avcodec_parameters_copy(st->codecpar, par)) < 0 || + ret = av_packet_ref(&pkt2, pkt); + if (ret < 0) + goto out; + pkt2.stream_index = 0; + + if ((ret = avcodec_parameters_copy(st->codecpar, par)) < 0 || (ret = avformat_write_header(fmt, NULL)) < 0 || (ret = av_interleaved_write_frame(fmt, &pkt2)) < 0 || (ret = av_write_trailer(fmt))) {} +out: av_packet_unref(&pkt2); avformat_free_context(fmt); return ret; |