Various fixes to FFmpeg decoder, including a couple of tests.
[dcpomatic.git] / src / lib / ffmpeg_examiner.cc
index e439566a10367ee105f9bbc5311098191931f38a..72db9bce1a3cd9abf1b3c2191eb5ed1f0180d10a 100644 (file)
@@ -102,14 +102,14 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c)
        }
 }
 
-optional<double>
+optional<ContentTime>
 FFmpegExaminer::frame_time (AVStream* s) const
 {
-       optional<double> t;
+       optional<ContentTime> t;
        
        int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
        if (bet != AV_NOPTS_VALUE) {
-               t = bet * av_q2d (s->time_base);
+               t = ContentTime::from_seconds (bet * av_q2d (s->time_base));
        }
 
        return t;
@@ -118,13 +118,11 @@ FFmpegExaminer::frame_time (AVStream* s) const
 float
 FFmpegExaminer::video_frame_rate () const
 {
-       AVStream* s = _format_context->streams[_video_stream];
-
-       if (s->avg_frame_rate.num && s->avg_frame_rate.den) {
-               return av_q2d (s->avg_frame_rate);
-       }
-
-       return av_q2d (s->r_frame_rate);
+       /* This use of r_frame_rate is debateable; there's a few different
+        * frame rates in the format context, but this one seems to be the most
+        * reliable.
+        */
+       return av_q2d (av_stream_get_r_frame_rate (_format_context->streams[_video_stream]));
 }
 
 dcp::Size
@@ -133,12 +131,12 @@ FFmpegExaminer::video_size () const
        return dcp::Size (video_codec_context()->width, video_codec_context()->height);
 }
 
-/** @return Length (in video frames) according to our content's header */
-VideoFrame
+/** @return Length according to our content's header */
+ContentTime
 FFmpegExaminer::video_length () const
 {
-       VideoFrame const length = (double (_format_context->duration) / AV_TIME_BASE) * video_frame_rate();
-       return max (1, length);
+       ContentTime const length = ContentTime::from_seconds (double (_format_context->duration) / AV_TIME_BASE);
+       return ContentTime (max (int64_t (1), length.get ()));
 }
 
 string