X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fsubtitle_encoder.cc;h=61c4dc3ae660774adc8badf312c47cd2c6beae73;hp=a94b9106ab5266ab4e3f45e9f6c385c8a2485f5c;hb=4347d97b703cfddcd322051092ccfcd5b5a6b941;hpb=9f294327cb59fce307c3a439f044d79b081376b0 diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index a94b9106a..61c4dc3ae 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -40,8 +40,11 @@ using boost::shared_ptr; using boost::optional; using dcp::raw_convert; -/** @param include_font true to refer to and export any font file (for Interop; ignored for SMPTE) */ -SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr job, boost::filesystem::path output, bool split_reels, bool include_font) +/** @param output Directory, if there will be multiple output files, or a filename. + * @param initial_name Hint that may be used to create filenames, if @ref output is a directory. + * @param include_font true to refer to and export any font file (for Interop; ignored for SMPTE). + */ +SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr job, boost::filesystem::path output, string initial_name, bool split_reels, bool include_font) : Encoder (film, job) , _split_reels (split_reels) , _include_font (include_font) @@ -53,20 +56,23 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr j _player->set_ignore_audio (); _player->Text.connect (boost::bind(&SubtitleEncoder::text, this, _1, _2, _3, _4)); + string const extension = film->interop() ? ".xml" : ".mxf"; + int const files = split_reels ? film->reels().size() : 1; for (int i = 0; i < files; ++i) { boost::filesystem::path filename = output; - string extension = boost::filesystem::extension (filename); - filename = boost::filesystem::change_extension (filename, ""); - - if (files > 1) { - /// TRANSLATORS: _reel%1 here is to be added to an export filename to indicate - /// which reel it is. Preserve the %1; it will be replaced with the reel number. - filename = filename.string() + String::compose(_("_reel%1"), i + 1); + if (boost::filesystem::is_directory(filename)) { + if (files > 1) { + /// TRANSLATORS: _reel%1 here is to be added to an export filename to indicate + /// which reel it is. Preserve the %1; it will be replaced with the reel number. + filename /= String::compose("%1_reel%2", initial_name, i + 1); + } else { + filename /= initial_name; + } } - _assets.push_back (make_pair(shared_ptr(), boost::filesystem::change_extension(filename, ".xml"))); + _assets.push_back (make_pair(shared_ptr(), boost::filesystem::change_extension(filename, extension))); } BOOST_FOREACH (dcpomatic::DCPTimePeriod i, film->reels()) { @@ -124,20 +130,20 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr if (!_assets[_reel_index].first) { shared_ptr asset; - string lang = _film->subtitle_language (); + vector lang = _film->subtitle_languages (); if (_film->interop ()) { shared_ptr s (new dcp::InteropSubtitleAsset()); s->set_movie_title (_film->name()); - s->set_language (lang.empty() ? "Unknown" : lang); + s->set_language (lang.empty() ? "Unknown" : lang.front().to_string()); s->set_reel_number (raw_convert(_reel_index + 1)); _assets[_reel_index].first = s; } else { shared_ptr s (new dcp::SMPTESubtitleAsset()); s->set_content_title_text (_film->name()); if (!lang.empty()) { - s->set_language (lang); + s->set_language (lang.front()); } else { - s->set_language (track->language); + s->set_language (dcp::LanguageTag(track->language)); } s->set_edit_rate (dcp::Fraction (_film->video_frame_rate(), 1)); s->set_reel_number (_reel_index + 1);