Use AV_ prefixes on some FFmpeg bits.
[dcpomatic.git] / src / lib / ffmpeg_examiner.cc
index 6173e041529444ed9e2c6cf9e0c8ec305d554bf5..4fd1b6fe8a8495ed9d326036ef07d712fb8efb8a 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
 #include "ffmpeg_subtitle_stream.h"
 #include "util.h"
 #include "safe_stringstream.h"
+#include <boost/foreach.hpp>
 #include <iostream>
 
 #include "i18n.h"
@@ -75,13 +76,14 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
        _need_video_length = _format_context->duration == AV_NOPTS_VALUE;
        if (!_need_video_length) {
                _video_length = (double (_format_context->duration) / AV_TIME_BASE) * video_frame_rate().get ();
-       } else if (job) {
-               job->sub (_("Finding length"));
-               job->set_progress_unknown ();
        }
 
        if (job) {
-               job->sub (_("Finding subtitles"));
+               if (_need_video_length) {
+                       job->sub (_("Finding length and subtitles"));
+               } else {
+                       job->sub (_("Finding subtitles"));
+               }
        }
 
        /* Run through until we find:
@@ -94,6 +96,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
         * so they are ok).
         */
 
+       int64_t const len = _file_group.length ();
        while (true) {
                int r = av_read_frame (_format_context, &_packet);
                if (r < 0) {
@@ -101,7 +104,11 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
                }
 
                if (job) {
-                       job->set_progress_unknown ();
+                       if (len > 0) {
+                               job->set_progress (float (_format_context->pb->pos) / len);
+                       } else {
+                               job->set_progress_unknown ();
+                       }
                }
 
                AVCodecContext* context = _format_context->streams[_packet.stream_index]->codec;
@@ -145,6 +152,16 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
                                );
                }
        }
+
+       /* We just added subtitles to our streams without taking the PTS offset into account;
+          this is because we might not know the PTS offset when the first subtitle is seen.
+          Now we know the PTS offset so we can apply it to those subtitles.
+       */
+       if (video_frame_rate()) {
+               BOOST_FOREACH (shared_ptr<FFmpegSubtitleStream> i, _subtitle_streams) {
+                       i->add_offset (pts_offset (_audio_streams, _first_video, video_frame_rate().get()));
+               }
+       }
 }
 
 void