Merge master.
[dcpomatic.git] / src / lib / ffmpeg.cc
index 8505626df1013a980cf6d100fb4246cb147cc302..4fe1c04484ab38527db8bf67a051904e8fb60eee 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 #include "ffmpeg.h"
 #include "ffmpeg_content.h"
 #include "ffmpeg_audio_stream.h"
+#include "ffmpeg_subtitle_stream.h"
 #include "exceptions.h"
 #include "util.h"
 
@@ -33,7 +34,6 @@ extern "C" {
 
 using std::string;
 using std::cout;
-using std::stringstream;
 using boost::shared_ptr;
 using dcp::raw_convert;
 
@@ -106,7 +106,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;
                }
        }
@@ -174,6 +177,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)
 {