X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fffmpeg.cc;h=4bf9415234e3d54b844e8881e56a75dd30558492;hb=015fe447cfe25babc55cf8ed282bb909e4713aa0;hp=e85a2c44e4912200bf5ebf2013a454b44ddc1e22;hpb=f0be0f0e060e40d9a0da1b44429ef41901b8a536;p=dcpomatic.git diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index e85a2c44e..4bf941523 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -62,7 +62,7 @@ FFmpeg::~FFmpeg () } } - avcodec_free_frame (&_frame); + av_frame_free (&_frame); avformat_close_input (&_format_context); } @@ -118,7 +118,25 @@ FFmpeg::setup_general () throw DecodeError (N_("could not find video stream")); } - _frame = avcodec_alloc_frame (); + /* Hack: if the AVStreams have zero IDs, put some in. We + use the IDs so that we can cope with VOBs, in which streams + move about in index but remain with the same ID in different + VOBs. However, some files have all-zero IDs, hence this hack. + */ + + uint32_t i = 0; + while (i < _format_context->nb_streams && _format_context->streams[i]->id == 0) { + ++i; + } + + if (i == _format_context->nb_streams) { + /* Put in our own IDs */ + for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { + _format_context->streams[i]->id = i; + } + } + + _frame = av_frame_alloc (); if (_frame == 0) { throw DecodeError (N_("could not allocate frame")); } @@ -173,6 +191,10 @@ FFmpeg::video_codec_context () const AVCodecContext * FFmpeg::audio_codec_context () const { + if (!_ffmpeg_content->audio_stream ()) { + return 0; + } + return _ffmpeg_content->audio_stream()->stream(_format_context)->codec; }