X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fffmpeg.cc;h=08349fba40c0008f01c96461221249c8af07d7d3;hb=61bafeda23d9e849f636ac416a745b0ab28bc103;hp=8505626df1013a980cf6d100fb4246cb147cc302;hpb=4616b19fb5241a54c9d57f7a91bb975f41aed14b;p=dcpomatic.git diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index 8505626df..08349fba4 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -22,20 +22,19 @@ extern "C" { #include #include } -#include #include "ffmpeg.h" #include "ffmpeg_content.h" #include "ffmpeg_audio_stream.h" +#include "ffmpeg_subtitle_stream.h" #include "exceptions.h" #include "util.h" +#include "raw_convert.h" #include "i18n.h" using std::string; using std::cout; -using std::stringstream; using boost::shared_ptr; -using dcp::raw_convert; boost::mutex FFmpeg::_mutex; @@ -106,7 +105,10 @@ FFmpeg::setup_general () for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { AVStream* s = _format_context->streams[i]; - if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + /* Files from iTunes sometimes have two video streams, one with the avg_frame_rate.num and .den set + to zero. Ignore these streams. + */ + if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO && s->avg_frame_rate.num > 0 && s->avg_frame_rate.den > 0) { _video_stream = i; } } @@ -149,7 +151,15 @@ FFmpeg::setup_decoders () AVCodec* codec = avcodec_find_decoder (context->codec_id); if (codec) { - if (avcodec_open2 (context, codec, 0) < 0) { + + /* This option disables decoding of DCA frame footers in our patched version + of FFmpeg. I believe these footers are of no use to us, and they can cause + problems when FFmpeg fails to decode them (mantis #352). + */ + AVDictionary* options = 0; + av_dict_set (&options, "disable_footer", "1", 0); + + if (avcodec_open2 (context, codec, &options) < 0) { throw DecodeError (N_("could not open decoder")); } } @@ -174,6 +184,16 @@ FFmpeg::audio_codec_context () const return _ffmpeg_content->audio_stream()->stream(_format_context)->codec; } +AVCodecContext * +FFmpeg::subtitle_codec_context () const +{ + if (!_ffmpeg_content->subtitle_stream ()) { + return 0; + } + + return _ffmpeg_content->subtitle_stream()->stream(_format_context)->codec; +} + int FFmpeg::avio_read (uint8_t* buffer, int const amount) {