diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-06-15 20:58:01 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-06-15 20:58:01 +0200 |
| commit | 115aa573e18f56a18a04a6e4c0c5f69fc335f8c9 (patch) | |
| tree | 230b1b24eeae1d9ed1b6638b77537640b01e8f48 | |
| parent | 831cd2e7fca8a4195a1a5fe2f161699b423d3d73 (diff) | |
Add --fade-{in,out} options to create CLI (#2613).
| -rw-r--r-- | src/lib/create_cli.cc | 25 | ||||
| -rw-r--r-- | src/lib/create_cli.h | 2 | ||||
| -rw-r--r-- | test/create_cli_test.cc | 25 |
3 files changed, 51 insertions, 1 deletions
diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc index af63f94fd..5f3d672bd 100644 --- a/src/lib/create_cli.cc +++ b/src/lib/create_cli.cc @@ -90,6 +90,8 @@ help() " --colorspace same as --colourspace\n" " --channel <channel> next piece of content should be mapped to audio channel L, R, C, Lfe, Ls, Rs, BsL, BsR, HI, VI\n" " --gain next piece of content should have the given audio gain (in dB)\n" + " --fade-in <seconds> next piece of content should have the given fade-in (in seconds)\n" + " --fade-out <seconds> next piece of content should have the given fade-out (in seconds)\n" " --cpl <id> CPL ID to use from the next piece of content (which is a DCP)\n" " --kdm <file> KDM for next piece of content\n"; } @@ -185,6 +187,8 @@ CreateCLI::CreateCLI(int argc, char* argv[]) auto next_auto_crop = false; optional<dcp::Channel> channel; optional<float> gain; + optional<float> fade_in; + optional<float> fade_out; optional<boost::filesystem::path> kdm; optional<string> cpl; @@ -298,6 +302,8 @@ CreateCLI::CreateCLI(int argc, char* argv[]) argument_option(i, argc, argv, "", "--channel", &claimed, &error, &channel, convert_channel); argument_option(i, argc, argv, "", "--gain", &claimed, &error, &gain); + argument_option(i, argc, argv, "", "--fade-in", &claimed, &error, &fade_in); + argument_option(i, argc, argv, "", "--fade-out", &claimed, &error, &fade_out); argument_option(i, argc, argv, "", "--kdm", &claimed, &error, &kdm, string_to_path); /* It shouldn't be necessary to use this string_to_string here, but using the other argument_option() * causes an odd compile error on Ubuntu 18.04. @@ -329,6 +335,8 @@ CreateCLI::CreateCLI(int argc, char* argv[]) c.colour_conversion = next_colour_conversion; c.channel = channel; c.gain = gain; + c.fade_in = fade_in; + c.fade_out = fade_out; c.kdm = kdm; c.cpl = cpl; content.push_back(c); @@ -337,6 +345,8 @@ CreateCLI::CreateCLI(int argc, char* argv[]) next_colour_conversion = {}; channel = {}; gain = {}; + fade_in = {}; + fade_out = {}; } } @@ -517,6 +527,7 @@ CreateCLI::make_film(function<void (string)> error) const for (auto film_content: film_content_list) { if (auto video = film_content->video) { + auto const video_frame_rate = film_content->video_frame_rate().get_value_or(24); video->set_frame_type(cli_content.frame_type); if (cli_content.auto_crop) { auto crop = guess_crop_by_brightness( @@ -527,7 +538,7 @@ CreateCLI::make_film(function<void (string)> error) const dcpomatic::ContentTime::from_seconds(1), dcpomatic::ContentTime::from_frames( video->length(), - film_content->video_frame_rate().get_value_or(24) + video_frame_rate ) ) ); @@ -546,6 +557,12 @@ CreateCLI::make_film(function<void (string)> error) const if (cli_content.colour_conversion) { video->set_colour_conversion(PresetColourConversion::from_id(*cli_content.colour_conversion).conversion); } + if (cli_content.fade_in) { + video->set_fade_in(dcpomatic::ContentTime::from_seconds(*cli_content.fade_in).frames_round(video_frame_rate)); + } + if (cli_content.fade_out) { + video->set_fade_out(dcpomatic::ContentTime::from_seconds(*cli_content.fade_out).frames_round(video_frame_rate)); + } } if (auto audio = film_content->audio) { if (cli_content.channel) { @@ -560,6 +577,12 @@ CreateCLI::make_film(function<void (string)> error) const if (cli_content.gain) { audio->set_gain(*cli_content.gain); } + if (cli_content.fade_in) { + audio->set_fade_in(dcpomatic::ContentTime::from_seconds(*cli_content.fade_in)); + } + if (cli_content.fade_out) { + audio->set_fade_out(dcpomatic::ContentTime::from_seconds(*cli_content.fade_out)); + } } } } diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h index 39024d786..4767b1aa7 100644 --- a/src/lib/create_cli.h +++ b/src/lib/create_cli.h @@ -45,6 +45,8 @@ public: boost::optional<std::string> colour_conversion; boost::optional<dcp::Channel> channel; boost::optional<float> gain; + boost::optional<float> fade_in; + boost::optional<float> fade_out; boost::optional<boost::filesystem::path> kdm; boost::optional<std::string> cpl; }; diff --git a/test/create_cli_test.cc b/test/create_cli_test.cc index 1209f9344..60d708eef 100644 --- a/test/create_cli_test.cc +++ b/test/create_cli_test.cc @@ -19,6 +19,7 @@ */ +#include "lib/audio_content.h" #include "lib/config.h" #include "lib/content.h" #include "lib/create_cli.h" @@ -297,6 +298,30 @@ BOOST_AUTO_TEST_CASE (create_cli_test) film = cc.make_film(error); BOOST_CHECK_EQUAL(film->audio_channels(), 16); BOOST_CHECK(collected_error.empty()); + + cc = run("dcpomatic2_create --channel L --fade-in 0.5 test/data/L.wav --channel R test/data/R.wav"); + BOOST_CHECK(!cc.error); + film = cc.make_film(error); + BOOST_REQUIRE_EQUAL(film->content().size(), 2U); + BOOST_REQUIRE(film->content()[0]->audio); + BOOST_REQUIRE(film->content()[1]->audio); + BOOST_CHECK(film->content()[0]->audio->fade_in() == dcpomatic::ContentTime::from_seconds(0.5)); + BOOST_CHECK(film->content()[0]->audio->fade_out() == dcpomatic::ContentTime{}); + BOOST_CHECK(film->content()[1]->audio->fade_in() == dcpomatic::ContentTime{}); + BOOST_CHECK(film->content()[1]->audio->fade_out() == dcpomatic::ContentTime{}); + BOOST_CHECK(collected_error.empty()); + + cc = run("dcpomatic2_create --fade-out 0.25 test/data/L.wav --fade-in 1 test/data/red_24.mp4"); + BOOST_CHECK(!cc.error); + film = cc.make_film(error); + BOOST_REQUIRE_EQUAL(film->content().size(), 2U); + BOOST_REQUIRE(film->content()[1]->audio); + BOOST_CHECK(film->content()[1]->audio->fade_in() == dcpomatic::ContentTime{}); + BOOST_CHECK(film->content()[1]->audio->fade_out() == dcpomatic::ContentTime::from_seconds(0.25)); + BOOST_REQUIRE(film->content()[0]->video); + BOOST_CHECK(film->content()[0]->video->fade_in() == 24); + BOOST_CHECK(film->content()[0]->video->fade_out() == 0); + BOOST_CHECK(collected_error.empty()); } |
