diff mbox

[FFmpeg-devel] avformat: close parser if codec changed

Message ID 3f06de83-f054-4b7a-18e1-3ce1234c04d9@googlemail.com
State Superseded
Headers show

Commit Message

Andreas Cadhalpun Oct. 17, 2016, 6:49 p.m. UTC
The parser depends on the codec and thus must not be used with a different one.
If it is, the 'avctx->codec_id == s->parser->codec_ids[0] ...' assert in
av_parser_parse2 gets triggered.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
---
 libavformat/utils.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Andreas Cadhalpun Oct. 21, 2016, 6 p.m. UTC | #1
On 17.10.2016 20:49, Andreas Cadhalpun wrote:
> The parser depends on the codec and thus must not be used with a different one.
> If it is, the 'avctx->codec_id == s->parser->codec_ids[0] ...' assert in
> av_parser_parse2 gets triggered.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  libavformat/utils.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

Ping.

Best regards,
Andreas
Michael Niedermayer Oct. 21, 2016, 10:18 p.m. UTC | #2
On Mon, Oct 17, 2016 at 08:49:23PM +0200, Andreas Cadhalpun wrote:
> The parser depends on the codec and thus must not be used with a different one.
> If it is, the 'avctx->codec_id == s->parser->codec_ids[0] ...' assert in
> av_parser_parse2 gets triggered.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  libavformat/utils.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

This changes the audio output from
http://samples.ffmpeg.org/MPEG2/vid_0x80.ts

is that intended ?


[...]
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8a51aea..a581994 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -480,6 +480,12 @@  static int update_stream_avctx(AVFormatContext *s)
         if (!st->internal->need_context_update)
             continue;
 
+        /* close parser, because it depends on the codec */
+        if (st->parser) {
+            av_parser_close(st->parser);
+            st->parser = NULL;
+        }
+
         /* update internal codec context, for the parser */
         ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
         if (ret < 0)
@@ -1515,6 +1521,12 @@  static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 st->info->found_decoder = 0;
             }
 
+            /* close parser, because it depends on the codec */
+            if (st->parser) {
+                av_parser_close(st->parser);
+                st->parser = NULL;
+            }
+
             ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
             if (ret < 0)
                 return ret;