Use audio length in FFmpegContent if there is no video.
authorCarl Hetherington <cth@carlh.net>
Tue, 10 May 2016 22:41:55 +0000 (23:41 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
src/lib/ffmpeg_content.cc
test/time_calculation_test.cc

index bb9795f25d0909a138b2fb46c58deab3d3cf01c5..32c2dee8b6d27662d6671cf9636e93c720ca7561 100644 (file)
@@ -311,7 +311,12 @@ DCPTime
 FFmpegContent::full_length () const
 {
        FrameRateChange const frc (active_video_frame_rate (), film()->video_frame_rate ());
-       return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
+       if (video) {
+               return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
+       }
+
+       DCPOMATIC_ASSERT (audio);
+       return DCPTime::from_frames (llrint (audio->stream()->length() / frc.speed_up), audio->stream()->frame_rate());
 }
 
 void
index 5e5c6211b6f3582477ba9eae4b9c6e26e6d97760..e9aa37f1e34b3149e581d2b93c25c66a14779f7b 100644 (file)
@@ -83,6 +83,7 @@ static string const xml = "<Content>"
        "<Name>und; 2 channels</Name>"
        "<Id>2</Id>"
        "<FrameRate>44100</FrameRate>"
+       "<Length>44100</Length>"
        "<Channels>2</Channels>"
        "<FirstAudio>0</FirstAudio>"
        "<Mapping>"
@@ -142,6 +143,31 @@ BOOST_AUTO_TEST_CASE (ffmpeg_time_calculation_test)
        /* 25fps content, 60fps DCP; length should be decreased */
        film->set_video_frame_rate (60);
        BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video->length() * (50.0 / 60) / 25.0));
+
+       /* Make the content audio-only */
+       content->video.reset ();
+
+       /* 24fps content, 24fps DCP */
+       film->set_video_frame_rate (24);
+       content->set_video_frame_rate (24);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 25fps DCP */
+       film->set_video_frame_rate (25);
+       content->set_video_frame_rate (25);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 24fps DCP; length should be increased */
+       film->set_video_frame_rate (24);
+       BOOST_CHECK_SMALL (abs (content->full_length().get() - DCPTime::from_seconds(25.0 / 24).get()), 2);
+       /* 25fps content, 30fps DCP; length should be decreased */
+       film->set_video_frame_rate (30);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (25.0 / 30));
+       /* 25fps content, 50fps DCP; length should be the same */
+       film->set_video_frame_rate (50);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (1));
+       /* 25fps content, 60fps DCP; length should be decreased */
+       film->set_video_frame_rate (60);
+       BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (50.0 / 60));
+
 }
 
 /** Test Player::dcp_to_content_video */