Supporters update.
[dcpomatic.git] / test / ffmpeg_encoder_test.cc
index 9edf2bdbd5880748b64155e13e79e07eed1b6d2d..dc57b473b48a3174ea080b8e2f3df545b680d260 100644 (file)
@@ -22,7 +22,9 @@
 #include "lib/audio_content.h"
 #include "lib/compose.hpp"
 #include "lib/config.h"
+#include "lib/constants.h"
 #include "lib/content_factory.h"
+#include "lib/cross.h"
 #include "lib/dcp_content.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/transcode_job.h"
 #include "lib/video_content.h"
 #include "test.h"
+#include <dcp/file.h>
+#include <dcp/raw_convert.h>
 #include <boost/test/unit_test.hpp>
 
 
-using std::string;
-using std::shared_ptr;
 using std::make_shared;
+using std::string;
+using std::vector;
 using namespace dcpomatic;
 
 
@@ -57,11 +61,14 @@ ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat f
                name += "h264";
                extension = "mp4";
                break;
-       case ExportFormat::PRORES:
-               name += "prores";
+       case ExportFormat::PRORES_4444:
+               name += "prores-444";
+               extension = "mov";
+               break;
+       case ExportFormat::PRORES_HQ:
+               name += "prores-hq";
                extension = "mov";
                break;
-       case ExportFormat::H264_PCM:
        case ExportFormat::SUBTITLES_DCP:
                BOOST_REQUIRE (false);
        }
@@ -87,28 +94,28 @@ ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat f
 /** Red / green / blue MP4 -> Prores */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test1)
 {
-       ffmpeg_content_test (1, "test/data/test.mp4", ExportFormat::PRORES);
+       ffmpeg_content_test (1, "test/data/test.mp4", ExportFormat::PRORES_HQ);
 }
 
 
 /** Dolby Aurora trailer VOB -> Prores */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test2)
 {
-       ffmpeg_content_test (2, TestPaths::private_data() / "dolby_aurora.vob", ExportFormat::PRORES);
+       ffmpeg_content_test (2, TestPaths::private_data() / "dolby_aurora.vob", ExportFormat::PRORES_HQ);
 }
 
 
 /** Sintel trailer -> Prores */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test3)
 {
-       ffmpeg_content_test (3, TestPaths::private_data() / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", ExportFormat::PRORES);
+       ffmpeg_content_test (3, TestPaths::private_data() / "Sintel_Trailer1.480p.DivX_Plus_HD.mkv", ExportFormat::PRORES_HQ);
 }
 
 
 /** Big Buck Bunny trailer -> Prores */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test4)
 {
-       ffmpeg_content_test (4, TestPaths::private_data() / "big_buck_bunny_trailer_480p.mov", ExportFormat::PRORES);
+       ffmpeg_content_test (4, TestPaths::private_data() / "big_buck_bunny_trailer_480p.mov", ExportFormat::PRORES_HQ);
 }
 
 
@@ -128,7 +135,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test5)
 
        film->write_metadata ();
        auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", ExportFormat::PRORES, false, false, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test5.mov", ExportFormat::PRORES_HQ, false, false, false, 23);
        encoder.go ();
 }
 
@@ -150,7 +157,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test6)
        film->write_metadata();
 
        auto job = make_shared<TranscodeJob> (film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", ExportFormat::PRORES, false, false, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test6.mov", ExportFormat::PRORES_HQ, false, false, false, 23);
        encoder.go ();
 }
 
@@ -175,7 +182,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
        s->only_text()->set_effect_colour (dcp::Colour (0, 255, 255));
 
        auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", ExportFormat::PRORES, false, false, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_test7.mov", ExportFormat::PRORES_HQ, false, false, false, 23);
        encoder.go ();
 }
 
@@ -319,7 +326,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
        film2->examine_and_add_content (ov);
        BOOST_REQUIRE (!wait_for_jobs());
        ov->set_reference_video (true);
-       auto subs = content_factory("test/data/subrip.srt").front();
+       auto subs = content_factory("test/data/subrip.srt")[0];
        film2->examine_and_add_content (subs);
        BOOST_REQUIRE (!wait_for_jobs());
        for (auto i: subs->text) {
@@ -366,6 +373,18 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test7)
 }
 
 
+BOOST_AUTO_TEST_CASE(ffmpeg_encoder_2d_content_in_3d_project)
+{
+       auto content = make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png");
+       auto film = new_test_film2("ffmpeg_encoder_2d_content_in_3d_project", { content });
+       film->set_three_d(true);
+
+       auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
+       FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_2d_content_in_3d_project.mp4", ExportFormat::H264_AAC, true, false, false, 23);
+       encoder.go();
+}
+
+
 /** Stereo project with mixdown-to-stereo set */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
 {
@@ -383,9 +402,9 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test8)
 /** 7.1/HI/VI (i.e. 12-channel) project */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test9)
 {
-       shared_ptr<Film> film = new_test_film ("ffmpeg_encoder_prores_test9");
-       film->set_name ("ffmpeg_encoder_prores_test9");
        auto c = make_shared<ImageContent>(TestPaths::private_data() / "bbc405.png");
+       auto film = new_test_film2("ffmpeg_encoder_prores_test9", { c });
+       film->set_name ("ffmpeg_encoder_prores_test9");
        film->set_container (Ratio::from_id ("185"));
        film->set_audio_channels (12);
 
@@ -411,7 +430,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_from_dcp_with_crop)
        film->write_metadata ();
 
        auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_from_dcp_with_crop.mov", ExportFormat::PRORES, false, false, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_from_dcp_with_crop.mov", ExportFormat::PRORES_HQ, false, false, false, 23);
        encoder.go ();
 }
 
@@ -434,8 +453,8 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_from_dcp_with_crop)
 /** Export to H264 with reels */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_with_reels)
 {
-       auto content1 = content_factory("test/data/flat_red.png").front();
-       auto content2 = content_factory("test/data/flat_red.png").front();
+       auto content1 = content_factory("test/data/flat_red.png")[0];
+       auto content2 = content_factory("test/data/flat_red.png")[0];
        auto film = new_test_film2 ("ffmpeg_encoder_h264_with_reels", { content1, content2 });
        film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
        content1->video->set_length (240);
@@ -446,7 +465,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_with_reels)
        encoder.go ();
 
        auto check = [](boost::filesystem::path path) {
-               auto reel = std::dynamic_pointer_cast<FFmpegContent>(content_factory(path).front());
+               auto reel = std::dynamic_pointer_cast<FFmpegContent>(content_factory(path)[0]);
                BOOST_REQUIRE (reel);
                FFmpegExaminer examiner(reel);
                BOOST_CHECK_EQUAL (examiner.video_length(), 240U);
@@ -460,28 +479,77 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_with_reels)
 /** Regression test for "Error during decoding: Butler finished" (#2097) */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_regression_1)
 {
-       auto content = content_factory(TestPaths::private_data() / "arrietty_JP-EN.mkv").front();
+       Cleanup cl;
+
+       auto content = content_factory(TestPaths::private_data() / "arrietty_JP-EN.mkv")[0];
        auto film = new_test_film2 ("ffmpeg_encoder_prores_regression_1", { content });
 
        auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_regression_1.mov", ExportFormat::PRORES, false, true, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_regression_1.mov", ExportFormat::PRORES_HQ, false, true, false, 23);
        encoder.go ();
+
+       cl.add("build/test/ffmpeg_encoder_prores_regression_1.mov");
+       cl.run();
 }
 
 
 /** Regression test for Butler video buffers reached 480 frames (audio is 0) (#2101) */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_regression_2)
 {
+       Cleanup cl;
+
        auto logs = dcpomatic_log->types();
        dcpomatic_log->set_types(logs | LogEntry::TYPE_DEBUG_PLAYER);
 
-       auto content = content_factory(TestPaths::private_data() / "tge_clip.mkv").front();
+       auto content = content_factory(TestPaths::private_data() / "tge_clip.mkv")[0];
        auto film = new_test_film2 ("ffmpeg_encoder_prores_regression_2", { content });
 
        auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_regression_2.mov", ExportFormat::PRORES, false, true, false, 23);
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_prores_regression_2.mov", ExportFormat::PRORES_HQ, false, true, false, 23);
        encoder.go ();
 
        dcpomatic_log->set_types(logs);
+
+       cl.add("build/test/ffmpeg_encoder_prores_regression_2.mov");
+       cl.run();
+}
+
+
+BOOST_AUTO_TEST_CASE(ffmpeg_encoder_missing_frame_at_end)
+{
+       auto content = content_factory(TestPaths::private_data() / "1s1f.mov");
+       auto film = new_test_film2("ffmpeg_encoder_missing_frame_at_end", content);
+
+       boost::filesystem::path output("build/test/ffmpeg_encoder_missing_frame_at_end.mov");
+       boost::filesystem::path log("build/test/ffmpeg_encoder_missing_frame_at_end.log");
+
+       auto job = make_shared<TranscodeJob>(film, TranscodeJob::ChangedBehaviour::IGNORE);
+       FFmpegEncoder encoder(film, job, output, ExportFormat::PRORES_HQ, false, true, false, 23);
+       encoder.go();
+
+       run_ffprobe(output, log, false, "-show_frames -show_format -show_streams -select_streams v:0");
+
+       dcp::File read_log(log, "r");
+       BOOST_REQUIRE(read_log);
+
+       int nb_read_frames = 0;
+       int nb_frames = 0;
+       char buffer[256];
+
+       while (!read_log.eof()) {
+               read_log.gets(buffer, sizeof(buffer));
+               vector<string> parts;
+               boost::algorithm::split(parts, buffer, boost::is_any_of("="));
+               if (parts.size() == 2) {
+                       if (parts[0] == "nb_read_frames") {
+                               nb_read_frames = dcp::raw_convert<int>(parts[1]);
+                       } else if (parts[0] == "nb_frames") {
+                               nb_frames = dcp::raw_convert<int>(parts[1]);
+                       }
+               }
+       }
+
+       BOOST_CHECK_EQUAL(nb_frames, 26);
+       BOOST_CHECK_EQUAL(nb_read_frames, 26);
 }