Adapt for changes to disable_forensic variable types in libdcp.
[dcpomatic.git] / src / lib / ffmpeg.cc
index 1f16514d7496b780b31d1ff5a4002d54c0f63923..ac179e1d62df8ffa0830056b36a39e09447d697e 100644 (file)
@@ -110,8 +110,6 @@ FFmpeg::ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl)
 void
 FFmpeg::setup_general ()
 {
-       av_register_all ();
-
        /* This might not work too well in some cases of multiple FFmpeg decoders,
           but it's probably good enough.
        */
@@ -131,8 +129,9 @@ FFmpeg::setup_general ()
        av_dict_set (&options, "analyzeduration", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
        av_dict_set (&options, "probesize", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
 
-       if (avformat_open_input (&_format_context, 0, 0, &options) < 0) {
-               throw OpenFileError (_ffmpeg_content->path(0).string ());
+       int e = avformat_open_input (&_format_context, 0, 0, &options);
+       if (e < 0) {
+               throw OpenFileError (_ffmpeg_content->path(0).string(), e, true);
        }
 
        if (avformat_find_stream_info (_format_context, 0) < 0) {
@@ -145,7 +144,7 @@ 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) {
+               if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO && avcodec_find_decoder(s->codec->codec_id)) {
                        if (s->avg_frame_rate.num > 0 && s->avg_frame_rate.den > 0) {
                                /* This is definitely our video stream */
                                _video_stream = i;
@@ -216,9 +215,12 @@ FFmpeg::setup_decoders ()
                        if (avcodec_open2 (context, codec, &options) < 0) {
                                throw DecodeError (N_("could not open decoder"));
                        }
+               } else {
+                       shared_ptr<Log> log = _ffmpeg_log.lock ();
+                       if (log) {
+                               log->log (String::compose ("No codec found for stream %1", i), LogEntry::TYPE_WARNING);
+                       }
                }
-
-               /* We are silently ignoring any failures to find suitable decoders here */
        }
 }
 
@@ -281,21 +283,27 @@ FFmpeg::subtitle_id (AVSubtitle const & sub)
        digester.add (sub.pts);
        for (unsigned int i = 0; i < sub.num_rects; ++i) {
                AVSubtitleRect* rect = sub.rects[i];
-               digester.add (rect->x);
-               digester.add (rect->y);
-               digester.add (rect->w);
-               digester.add (rect->h);
+               if (rect->type == SUBTITLE_BITMAP) {
+                       digester.add (rect->x);
+                       digester.add (rect->y);
+                       digester.add (rect->w);
+                       digester.add (rect->h);
 #ifdef DCPOMATIC_HAVE_AVSUBTITLERECT_PICT
-               int const line = rect->pict.linesize[0];
-               for (int j = 0; j < rect->h; ++j) {
-                       digester.add (rect->pict.data[0] + j * line, line);
-               }
+                       int const line = rect->pict.linesize[0];
+                       for (int j = 0; j < rect->h; ++j) {
+                               digester.add (rect->pict.data[0] + j * line, line);
+                       }
 #else
-               int const line = rect->linesize[0];
-               for (int j = 0; j < rect->h; ++j) {
-                       digester.add (rect->data[0] + j * line, line);
-               }
+                       int const line = rect->linesize[0];
+                       for (int j = 0; j < rect->h; ++j) {
+                               digester.add (rect->data[0] + j * line, line);
+                       }
 #endif
+               } else if (rect->type == SUBTITLE_TEXT) {
+                       digester.add (string (rect->text));
+               } else if (rect->type == SUBTITLE_ASS) {
+                       digester.add (string (rect->ass));
+               }
        }
        return digester.get ();
 }
@@ -374,7 +382,7 @@ FFmpeg::pts_offset (vector<shared_ptr<FFmpegAudioStream> > audio_streams, option
        /* Now adjust so that the video pts starts on a frame */
        if (first_video) {
                ContentTime const fvc = first_video.get() + po;
-               po += fvc.round_up (video_frame_rate) - fvc;
+               po += fvc.ceil (video_frame_rate) - fvc;
        }
 
        return po;