Detect soft 2:3 pulldown (telecine) files and decode them at 23.976.
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index f4e4beba923cf4aed67b634831dc334c97ca74d2..6383fe58b6736a56c67c696c085c146383517c99 100644 (file)
@@ -324,6 +324,18 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
        if (examiner->has_video ()) {
                set_default_colour_conversion ();
        }
+
+       if (examiner->has_video() && examiner->pulldown() && video_frame_rate() && fabs(*video_frame_rate() - 29.97) < 0.001) {
+               /* FFmpeg has detected this file as 29.97 and the examiner thinks it is using "soft" 2:3 pulldown (telecine).
+                * This means we can treat it as a 23.976fps file.
+                */
+               set_video_frame_rate (24000.0 / 1001);
+               video->set_length (video->length() * 24.0 / 30);
+       }
+
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+       _id = examiner->id ();
+#endif
 }
 
 string
@@ -405,14 +417,17 @@ FFmpegContent::full_length (shared_ptr<const Film> film) const
                return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
        }
 
-       DCPOMATIC_ASSERT (audio);
-
-       DCPTime longest;
-       BOOST_FOREACH (AudioStreamPtr i, audio->streams ()) {
-               longest = max (longest, DCPTime::from_frames (llrint (i->length() / frc.speed_up), i->frame_rate()));
+       if (audio) {
+               DCPTime longest;
+               BOOST_FOREACH (AudioStreamPtr i, audio->streams()) {
+                       longest = max (longest, DCPTime::from_frames(llrint(i->length() / frc.speed_up), i->frame_rate()));
+               }
+               return longest;
        }
 
-       return longest;
+       /* XXX: subtitle content? */
+
+       return DCPTime();
 }
 
 DCPTime
@@ -507,7 +522,7 @@ FFmpegContent::set_default_colour_conversion ()
 void
 FFmpegContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
 {
-       Content::add_properties (p);
+       Content::add_properties (film, p);
 
        if (video) {
                video->add_properties (p);