[FFmpeg-devel] [PATCH 7/8] avformat/img2enc: fix writing multiple streams in write_muxed_file

Marton Balint cus at passwd.hu
Fri Dec 27 23:14:10 EET 2019


Maybe we should just reject multiple streams for the image2 muxer instead?

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 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;
-- 
2.16.4



More information about the ffmpeg-devel mailing list