[FFmpeg-cvslog] avformat/img2enc: fix writing multiple streams in write_muxed_file

Marton Balint git at videolan.org
Fri Jan 3 19:12:20 EET 2020


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Thu Dec 26 23:33:26 2019 +0100| [d111a41f9d5c23856ddba61f65e35f7ba534288f] | committer: Marton Balint

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 at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d111a41f9d5c23856ddba61f65e35f7ba534288f
---

 libavformat/img2enc.c | 11 ++++++++---
 1 file 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;



More information about the ffmpeg-cvslog mailing list