From: Carl Hetherington Date: Fri, 3 Jun 2022 18:07:57 +0000 (+0200) Subject: Make subtitle asset filename obey custom settings (#2260). X-Git-Tag: v2.16.14~41 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=6fa6f0a7ca116c6cf5dc5b8d2e8ed3a0fd4a6127 Make subtitle asset filename obey custom settings (#2260). --- diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 94920b95b..d64cfb81a 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -459,6 +459,9 @@ maybe_add_text ( shared_ptr asset, int64_t picture_duration, shared_ptr reel, + int reel_index, + int reel_count, + optional content_summary, list const & refs, vector const & fonts, dcp::ArrayData default_font, @@ -481,7 +484,7 @@ maybe_add_text ( if (auto interop = dynamic_pointer_cast(asset)) { auto directory = output_dcp / interop->id (); boost::filesystem::create_directories (directory); - interop->write (directory / ("sub_" + interop->id() + ".xml")); + interop->write (directory / subtitle_asset_filename(asset, reel_index, reel_count, content_summary)); reel_asset = make_shared ( interop, dcp::Fraction(film->video_frame_rate(), 1), @@ -496,7 +499,7 @@ maybe_add_text ( */ smpte->set_intrinsic_duration(picture_duration); smpte->write ( - output_dcp / ("sub_" + asset->id() + ".mxf") + output_dcp / subtitle_asset_filename(asset, reel_index, reel_count, content_summary) ); reel_asset = make_shared ( smpte, @@ -643,7 +646,7 @@ ReelWriter::create_reel_text ( ) const { auto subtitle = maybe_add_text ( - _subtitle_asset, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only ); if (subtitle) { @@ -657,6 +660,9 @@ ReelWriter::create_reel_text ( empty_text_asset(TextType::OPEN_SUBTITLE, optional(), true), duration, reel, + _reel_index, + _reel_count, + _content_summary, refs, fonts, _default_font, @@ -669,7 +675,7 @@ ReelWriter::create_reel_text ( for (auto const& i: _closed_caption_assets) { auto a = maybe_add_text ( - i.second, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only ); DCPOMATIC_ASSERT (a); a->set_annotation_text (i.first.name); @@ -683,7 +689,19 @@ ReelWriter::create_reel_text ( /* Make empty tracks for anything we've been asked to ensure but that we haven't added */ for (auto i: ensure_closed_captions) { auto a = maybe_add_text ( - empty_text_asset(TextType::CLOSED_CAPTION, i, true), duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + empty_text_asset(TextType::CLOSED_CAPTION, i, true), + duration, + reel, + _reel_index, + _reel_count, + _content_summary, + refs, + fonts, + _default_font, + film(), + _period, + output_dcp, + _text_only ); DCPOMATIC_ASSERT (a); a->set_annotation_text (i.name); diff --git a/src/lib/util.cc b/src/lib/util.cc index e1eb7323c..2c38257b4 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -735,6 +735,13 @@ audio_asset_filename (shared_ptr asset, int reel_index, int ree } +string +subtitle_asset_filename (shared_ptr asset, int reel_index, int reel_count, optional summary) +{ + return asset_filename(asset, "sub", reel_index, reel_count, summary); +} + + string atmos_asset_filename (shared_ptr asset, int reel_index, int reel_count, optional summary) { diff --git a/src/lib/util.h b/src/lib/util.h index 233b3cb2a..cd5a1c2c5 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -49,6 +49,7 @@ namespace dcp { class PictureAsset; class SoundAsset; + class SubtitleAsset; } /** The maximum number of audio channels that we can have in a DCP */ @@ -107,6 +108,7 @@ extern void set_backtrace_file (boost::filesystem::path); extern std::map split_get_request (std::string url); extern std::string video_asset_filename (std::shared_ptr asset, int reel_index, int reel_count, boost::optional content_summary); extern std::string audio_asset_filename (std::shared_ptr asset, int reel_index, int reel_count, boost::optional content_summary); +extern std::string subtitle_asset_filename (std::shared_ptr asset, int reel_index, int reel_count, boost::optional content_summary); extern std::string atmos_asset_filename (std::shared_ptr asset, int reel_index, int reel_count, boost::optional content_summary); extern float relaxed_string_to_float (std::string); extern std::string careful_string_filter (std::string); diff --git a/test/file_naming_test.cc b/test/file_naming_test.cc index 0b76952a8..4f6d66fe6 100644 --- a/test/file_naming_test.cc +++ b/test/file_naming_test.cc @@ -27,9 +27,10 @@ #include "test.h" #include "lib/config.h" -#include "lib/film.h" -#include "lib/ffmpeg_content.h" +#include "lib/content_factory.h" #include "lib/dcp_content_type.h" +#include "lib/ffmpeg_content.h" +#include "lib/film.h" #include "lib/video_content.h" #ifdef DCPOMATIC_WINDOWS #include @@ -38,9 +39,9 @@ #include -using std::string; -using std::shared_ptr; using std::make_shared; +using std::shared_ptr; +using std::string; class Keep @@ -170,3 +171,34 @@ BOOST_AUTO_TEST_CASE (file_naming_test2) BOOST_CHECK (got[i] == 2); } } + + +BOOST_AUTO_TEST_CASE (subtitle_file_naming) +{ + Keep keep; + + Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c")); + + auto content = content_factory("test/data/15s.srt"); + auto film = new_test_film2("subtitle_file_naming", { content.front() }); + film->set_interop(false); + + make_and_verify_dcp ( + film, + { + dcp::VerificationNote::Code::MISSING_CPL_METADATA, + dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE, + dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME, + }); + + int got = 0; + + for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) { + if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) { + ++got; + } + } + + BOOST_CHECK_EQUAL(got, 1); +} +