summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-06-03 20:07:57 +0200
committerCarl Hetherington <cth@carlh.net>2022-06-03 22:40:59 +0200
commit6fa6f0a7ca116c6cf5dc5b8d2e8ed3a0fd4a6127 (patch)
tree04c01959d9849967460a9c2e780009c2986299f3
parent12f089b89fff8409cd012cab1ba4eb8b619e554e (diff)
Make subtitle asset filename obey custom settings (#2260).
-rw-r--r--src/lib/reel_writer.cc28
-rw-r--r--src/lib/util.cc7
-rw-r--r--src/lib/util.h2
-rw-r--r--test/file_naming_test.cc40
4 files changed, 68 insertions, 9 deletions
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<dcp::SubtitleAsset> asset,
int64_t picture_duration,
shared_ptr<dcp::Reel> reel,
+ int reel_index,
+ int reel_count,
+ optional<string> content_summary,
list<ReferencedReelAsset> const & refs,
vector<FontData> const & fonts,
dcp::ArrayData default_font,
@@ -481,7 +484,7 @@ maybe_add_text (
if (auto interop = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(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> (
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> (
smpte,
@@ -643,7 +646,7 @@ ReelWriter::create_reel_text (
) const
{
auto subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
- _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<DCPTextTrack>(), 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<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
- 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<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
- 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
@@ -736,6 +736,13 @@ audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int ree
string
+subtitle_asset_filename (shared_ptr<dcp::SubtitleAsset> asset, int reel_index, int reel_count, optional<string> summary)
+{
+ return asset_filename(asset, "sub", reel_index, reel_count, summary);
+}
+
+
+string
atmos_asset_filename (shared_ptr<dcp::AtmosAsset> asset, int reel_index, int reel_count, optional<string> summary)
{
return asset_filename(asset, "atmos", reel_index, reel_count, 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<std::string, std::string> split_get_request (std::string url);
extern std::string video_asset_filename (std::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
extern std::string audio_asset_filename (std::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
+extern std::string subtitle_asset_filename (std::shared_ptr<dcp::SubtitleAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
extern std::string atmos_asset_filename (std::shared_ptr<dcp::AtmosAsset> asset, int reel_index, int reel_count, boost::optional<std::string> 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 <boost/locale.hpp>
@@ -38,9 +39,9 @@
#include <boost/regex.hpp>
-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);
+}
+