Replace Time::frames with Time::frames_round and Time::frames_floor.
[dcpomatic.git] / src / lib / ffmpeg_examiner.cc
index 16a89faa75a580e1ef55aa1a595d0e46fbc43d14..78d97d21e52e4b4b9f5a12ed052ef33e711701d2 100644 (file)
@@ -20,6 +20,8 @@
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
+#include <libavutil/pixfmt.h>
+#include <libavutil/pixdesc.h>
 }
 #include "ffmpeg_examiner.h"
 #include "ffmpeg_content.h"
@@ -137,7 +139,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context)
                if (_need_video_length) {
                        _video_length = frame_time (
                                _format_context->streams[_video_stream]
-                               ).get_value_or (ContentTime ()).frames (video_frame_rate().get ());
+                               ).get_value_or (ContentTime ()).frames_round (video_frame_rate().get ());
                }
        }
 }
@@ -189,7 +191,7 @@ FFmpegExaminer::frame_time (AVStream* s) const
        return t;
 }
 
-optional<float>
+optional<double>
 FFmpegExaminer::video_frame_rate () const
 {
        /* This use of r_frame_rate is debateable; there's a few different
@@ -212,15 +214,15 @@ FFmpegExaminer::video_length () const
        return max (Frame (1), _video_length);
 }
 
-optional<float>
+optional<double>
 FFmpegExaminer::sample_aspect_ratio () const
 {
        AVRational sar = av_guess_sample_aspect_ratio (_format_context, _format_context->streams[_video_stream], 0);
        if (sar.num == 0) {
                /* I assume this means that we don't know */
-               return optional<float> ();
+               return optional<double> ();
        }
-       return float (sar.num) / sar.den;
+       return double (sar.num) / sar.den;
 }
 
 string
@@ -275,3 +277,9 @@ FFmpegExaminer::stream_name (AVStream* s) const
 
        return n.str ();
 }
+
+int
+FFmpegExaminer::bits_per_pixel () const
+{
+       return av_get_bits_per_pixel (av_pix_fmt_desc_get (video_codec_context()->pix_fmt));
+}