Fix crash when exporting a 2D project containing 3D content (#1680).
authorCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 19:25:48 +0000 (20:25 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 19:37:49 +0000 (20:37 +0100)
src/lib/ffmpeg_encoder.cc
test/ffmpeg_encoder_test.cc

index 6c00616..19ab3b3 100644 (file)
@@ -153,7 +153,10 @@ FFmpegEncoder::go ()
 
                for (int j = 0; j < gets_per_frame; ++j) {
                        pair<shared_ptr<PlayerVideo>, DCPTime> v = _butler->get_video (true, 0);
-                       encoder->get(v.first->eyes())->video(v.first, v.second);
+                       shared_ptr<FFmpegFileEncoder> fe = encoder->get (v.first->eyes());
+                       if (fe) {
+                               fe->video(v.first, v.second);
+                       }
                }
 
                _history.event ();
@@ -247,6 +250,17 @@ FFmpegEncoder::FileEncoderSet::FileEncoderSet (
 shared_ptr<FFmpegFileEncoder>
 FFmpegEncoder::FileEncoderSet::get (Eyes eyes) const
 {
+       if (_encoders.size() == 1) {
+               /* We are doing a 2D export... */
+               if (eyes == EYES_LEFT) {
+                       /* ...but we got some 3D data; put the left eye into the output... */
+                       eyes = EYES_BOTH;
+               } else if (eyes == EYES_RIGHT) {
+                       /* ...and ignore the right eye.*/
+                       return shared_ptr<FFmpegFileEncoder>();
+               }
+       }
+
        map<Eyes, boost::shared_ptr<FFmpegFileEncoder> >::const_iterator i = _encoders.find (eyes);
        DCPOMATIC_ASSERT (i != _encoders.end());
        return i->second;
index d9a0261..1acfa96 100644 (file)
@@ -344,3 +344,35 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
                );
        encoder.go ();
 }
+
+/** Test export of a 3D DCP in a 2D project */
+BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
+{
+       shared_ptr<Film> film = new_test_film2 ("ffmpeg_encoder_h264_test7_data");
+       shared_ptr<Content> L (shared_ptr<ImageContent>(new ImageContent(private_data / "bbc405.png")));
+       film->examine_and_add_content (L);
+       shared_ptr<Content> R (shared_ptr<ImageContent>(new ImageContent(private_data / "bbc405.png")));
+       film->examine_and_add_content (R);
+       BOOST_REQUIRE (!wait_for_jobs());
+       L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
+       L->set_position (film, DCPTime());
+       R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
+       R->set_position (film, DCPTime());
+       film->set_three_d (true);
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       shared_ptr<Film> film2 = new_test_film2 ("ffmpeg_encoder_h264_test7_export");
+       shared_ptr<Content> dcp (new DCPContent(film->dir(film->dcp_name())));
+       film2->examine_and_add_content (dcp);
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       shared_ptr<Job> job (new TranscodeJob (film2));
+       FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test7.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+                              , optional<dcp::Key>(), optional<string>()
+#endif
+               );
+       encoder.go ();
+}
+