]> granicus.if.org Git - handbrake/commit
decavcodec: fix error when ffmpeg parser changes the codec_id
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 10 Feb 2019 20:04:21 +0000 (13:04 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 11 Feb 2019 14:26:45 +0000 (06:26 -0800)
commit28934d9f0ba1a0e4adc76bcf90a3762429169ea8
treefbffe2bc53c52309df895ab728e3cbf055911ebd
parent58a15a0dc83afb10dcd48eb428b707e268e320e8
decavcodec: fix error when ffmpeg parser changes the codec_id

The ffmpeg mpeg2 parser changes AVCodecContext.codec_id on the fly based
on what it parses. Normally this results in correct switching of decoders
internally in ffmpeg. Due to some unfortunate ordering of how we initialize
things when HandBrake is using our own demuxers, avcodec_open gets called
with the original AVCodec and the AVCodecContext.codec_id that was changed
by the parser resulting in an error.

Further explanation... When using our own demuxers, there are some codecs that
we have to parse out the extradata for _prior_ to calling avcodec_open.
avcodec_open fails if extradata isn't initialized for these codecs prior to
the call. To initialize the extradata, we use parser->parser->split. I.e. the
parser must be initialized and used prior to calling avcodec_open. When
avcodec_open is called, it is using the original AVCodec that was used with
avcodec_alloc_context3 (it will fail if AVCodec is not the same between
avcodec_alloc_context3 and avccodec_open). The call to avcodec_open fails with
"Codec type or id mismatches" since AVCodecContext.codec_id no longer matches
AVCodec.id due to the parser changing the codec_id.

The solution is to reset AVCodec and reallocate the context when we
detect that the parser has changed codec_id on us.
libhb/decavcodec.c