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>
This commit is contained in:
Marton Balint 2019-12-26 23:33:26 +01:00
parent beb7f93b23
commit d111a41f9d
1 changed files with 8 additions and 3 deletions

View File

@ -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;