diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-03-19 22:38:15 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-03-19 22:38:15 +0100 |
| commit | bec175cf2eb7d288c6f11df751ec969f92e077db (patch) | |
| tree | 0d4cb53c9591d41887199b6768d71516aec771d9 | |
| parent | a259b250cadf7bdeb7c56d214f69fee94ae50ab4 (diff) | |
Add --colourspace opton to create CLI (#2967).
| -rw-r--r-- | src/lib/create_cli.cc | 30 | ||||
| -rw-r--r-- | src/lib/create_cli.h | 1 | ||||
| -rw-r--r-- | test/create_cli_test.cc | 14 |
3 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc index 2db61f147..6698e593c 100644 --- a/src/lib/create_cli.cc +++ b/src/lib/create_cli.cc @@ -54,6 +54,13 @@ static string help() { + string colour_conversions = ""; + for (auto const& conversion: PresetColourConversion::all()) { + colour_conversions += conversion.id + ", "; + } + DCPOMATIC_ASSERT(colour_conversions.length() > 2); + colour_conversions = colour_conversions.substr(0, colour_conversions.length() - 2); + return string("\nSyntax: %1 [OPTION] <CONTENT> [OPTION] [<CONTENT> ...]\n") + variant::insert_dcpomatic(" -v, --version show %1 version\n") + " -h, --help show this help\n" @@ -79,6 +86,8 @@ help() " --left-eye next piece of content is for the left eye\n" " --right-eye next piece of content is for the right eye\n" " --auto-crop next piece of content should be auto-cropped\n" + " --colourspace next piece of content is in the given colourspace: " + colour_conversions + "\n" + " --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" " --cpl <id> CPL ID to use from the next piece of content (which is a DCP)\n" @@ -171,6 +180,7 @@ CreateCLI::CreateCLI(int argc, char* argv[]) string template_name_string; int64_t video_bit_rate_int = 0; optional<int> audio_channels; + optional<string> next_colour_conversion; auto next_frame_type = VideoFrameType::TWO_D; auto next_auto_crop = false; optional<dcp::Channel> channel; @@ -255,6 +265,8 @@ CreateCLI::CreateCLI(int argc, char* argv[]) argument_option(i, argc, argv, "", "--video-bit-rate", &claimed, &error, &video_bit_rate_int); /* Similar to below, not using string_to_int here causes on add compile error on Ubuntu 1{6,8}.04 */ argument_option(i, argc, argv, "-a", "--audio-channels", &claimed, &error, &audio_channels, string_to_int); + argument_option(i, argc, argv, "" , "--colourspace", &claimed, &error, &next_colour_conversion, string_to_string); + argument_option(i, argc, argv, "" , "--colorspace", &claimed, &error, &next_colour_conversion, string_to_string); std::function<optional<dcp::Channel> (string)> convert_channel = [](string channel) -> optional<dcp::Channel>{ if (channel == "L") { @@ -297,10 +309,24 @@ CreateCLI::CreateCLI(int argc, char* argv[]) error = String::compose("%1: unrecognised option '%2'", argv[0], a) + String::compose(help(), argv[0]); return; } else { + if (next_colour_conversion) { + auto colour_conversions = PresetColourConversion::all(); + if (!std::any_of( + colour_conversions.begin(), + colour_conversions.end(), + [next_colour_conversion](PresetColourConversion const& conversion) { + return conversion.id == *next_colour_conversion; + })) { + error = fmt::format("{}: {} is not a recognised colourspace", argv[0], *next_colour_conversion); + return; + } + } + Content c; c.path = a; c.frame_type = next_frame_type; c.auto_crop = next_auto_crop; + c.colour_conversion = next_colour_conversion; c.channel = channel; c.gain = gain; c.kdm = kdm; @@ -308,6 +334,7 @@ CreateCLI::CreateCLI(int argc, char* argv[]) content.push_back(c); next_frame_type = VideoFrameType::TWO_D; next_auto_crop = false; + next_colour_conversion = {}; channel = {}; gain = {}; } @@ -516,6 +543,9 @@ CreateCLI::make_film(function<void (string)> error) const film_content->video->set_crop(crop); } + if (cli_content.colour_conversion) { + film_content->video->set_colour_conversion(PresetColourConversion::from_id(*cli_content.colour_conversion).conversion); + } } if (film_content->audio && cli_content.channel) { for (auto stream: film_content->audio->streams()) { diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h index 108466afd..39024d786 100644 --- a/src/lib/create_cli.h +++ b/src/lib/create_cli.h @@ -42,6 +42,7 @@ public: boost::filesystem::path path; VideoFrameType frame_type = VideoFrameType::TWO_D; bool auto_crop = false; + boost::optional<std::string> colour_conversion; boost::optional<dcp::Channel> channel; boost::optional<float> gain; boost::optional<boost::filesystem::path> kdm; diff --git a/test/create_cli_test.cc b/test/create_cli_test.cc index 5831e6b6f..1209f9344 100644 --- a/test/create_cli_test.cc +++ b/test/create_cli_test.cc @@ -177,6 +177,18 @@ BOOST_AUTO_TEST_CASE (create_cli_test) BOOST_CHECK_EQUAL (cc.content[1].frame_type, VideoFrameType::THREE_D_RIGHT); BOOST_CHECK_EQUAL(cc._fourk, false); + cc = run ("dcpomatic2_create --colourspace rec1886 test/data/flat_red.png"); + BOOST_REQUIRE_EQUAL(cc.content.size(), 1U); + BOOST_CHECK_EQUAL(cc.content[0].colour_conversion.get_value_or(""), "rec1886"); + BOOST_CHECK(!cc.error); + auto film = cc.make_film(error); + BOOST_REQUIRE_EQUAL(film->content().size(), 1U); + BOOST_REQUIRE(static_cast<bool>(film->content()[0]->video->colour_conversion())); + BOOST_REQUIRE(film->content()[0]->video->colour_conversion() == PresetColourConversion::from_id("rec1886").conversion); + + cc = run ("dcpomatic2_create --colourspace ostrobogulous foo.mp4"); + BOOST_CHECK_EQUAL(cc.error.get_value_or(""), "dcpomatic2_create: ostrobogulous is not a recognised colourspace"); + cc = run ("dcpomatic2_create --twok foo.mp4"); BOOST_REQUIRE_EQUAL (cc.content.size(), 1U); BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4"); @@ -210,7 +222,7 @@ BOOST_AUTO_TEST_CASE (create_cli_test) auto pillarbox = TestPaths::private_data() / "pillarbox.png"; cc = run("dcpomatic2_create --auto-crop " + pillarbox.string()); - auto film = cc.make_film(error); + film = cc.make_film(error); BOOST_CHECK_EQUAL(film->content().size(), 1U); BOOST_CHECK(film->content()[0]->video->actual_crop() == Crop(113, 262, 0, 0)); BOOST_CHECK_EQUAL(collected_error, fmt::format("Cropped {} to 113 left, 262 right, 0 top and 0 bottom", pillarbox.string())); |
