X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubtitle_encoder.cc;h=2331eb52a8871241ba3ce58a87a3a99348a7aebf;hb=182b9d2e2feb6545592868606aaf0f0146095481;hp=5e76f5e738d294449c7a33e5bb0e970be7c50cbd;hpb=e519feaca11005d330e7b8403b948d4ad9cc3ae8;p=dcpomatic.git diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index 5e76f5e73..2331eb52a 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington + Copyright (C) 2019-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,28 +18,33 @@ */ -#include "font.h" -#include "subtitle_encoder.h" -#include "player.h" + #include "compose.hpp" #include "job.h" +#include "player.h" +#include "subtitle_encoder.h" #include #include #include -#include #include -#include +#include #include "i18n.h" -using std::string; + using std::make_pair; +using std::make_shared; using std::pair; +using std::shared_ptr; +using std::string; using std::vector; -using boost::shared_ptr; using boost::optional; +#if BOOST_VERSION >= 106100 +using namespace boost::placeholders; +#endif using dcp::raw_convert; + /** @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). @@ -75,11 +80,14 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr j _assets.push_back (make_pair(shared_ptr(), boost::filesystem::change_extension(filename, extension))); } - BOOST_FOREACH (dcpomatic::DCPTimePeriod i, film->reels()) { + for (auto i: film->reels()) { _reels.push_back (i); } + + _default_font = dcp::ArrayData (default_font_file()); } + void SubtitleEncoder::go () { @@ -94,56 +102,59 @@ SubtitleEncoder::go () while (!_player->pass()) {} int reel = 0; - for (vector, boost::filesystem::path> >::iterator i = _assets.begin(); i != _assets.end(); ++i) { - if (!i->first) { + for (auto& i: _assets) { + if (!i.first) { /* No subtitles arrived for this asset; make an empty one so we write something to the output */ if (_film->interop()) { - shared_ptr s (new dcp::InteropSubtitleAsset()); + auto s = make_shared(); s->set_movie_title (_film->name()); s->set_reel_number (raw_convert(reel + 1)); - i->first = s; + i.first = s; } else { - shared_ptr s (new dcp::SMPTESubtitleAsset()); + auto s = make_shared(); s->set_content_title_text (_film->name()); s->set_reel_number (reel + 1); - i->first = s; + i.first = s; } } if (!_film->interop() || _include_font) { - BOOST_FOREACH (shared_ptr j, _player->get_subtitle_fonts()) { - i->first->add_font (j->id(), default_font_file()); + for (auto j: _player->get_subtitle_fonts()) { + i.first->add_font(j->id(), j->data().get_value_or(_default_font)); } } - i->first->write (i->second); + i.first->write (i.second); ++reel; } } + void SubtitleEncoder::text (PlayerText subs, TextType type, optional track, dcpomatic::DCPTimePeriod period) { - if (type != TEXT_OPEN_SUBTITLE) { + if (type != TextType::OPEN_SUBTITLE) { return; } if (!_assets[_reel_index].first) { shared_ptr asset; - vector lang = _film->subtitle_languages (); + auto lang = _film->subtitle_languages (); if (_film->interop ()) { - shared_ptr s (new dcp::InteropSubtitleAsset()); + auto s = make_shared(); s->set_movie_title (_film->name()); - s->set_language (lang.empty() ? "Unknown" : lang.front().to_string()); + if (lang.first) { + s->set_language (lang.first->to_string()); + } s->set_reel_number (raw_convert(_reel_index + 1)); _assets[_reel_index].first = s; } else { - shared_ptr s (new dcp::SMPTESubtitleAsset()); + auto s = make_shared(); s->set_content_title_text (_film->name()); - if (!lang.empty()) { - s->set_language (lang.front().to_string()); - } else { - s->set_language (track->language); + if (lang.first) { + s->set_language (*lang.first); + } else if (track->language) { + s->set_language (track->language.get()); } s->set_edit_rate (dcp::Fraction (_film->video_frame_rate(), 1)); s->set_reel_number (_reel_index + 1); @@ -156,14 +167,14 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr } } - BOOST_FOREACH (StringText i, subs.string) { + for (auto i: subs.string) { /* XXX: couldn't / shouldn't we use period here rather than getting time from the subtitle? */ i.set_in (i.in()); i.set_out (i.out()); if (_film->interop() && !_include_font) { i.unset_font (); } - _assets[_reel_index].first->add (shared_ptr(new dcp::SubtitleString(i))); + _assets[_reel_index].first->add (make_shared(i)); } if (_split_reels && (_reel_index < int(_reels.size()) - 1) && period.from > _reels[_reel_index].from) { @@ -172,12 +183,13 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr _last = period.from; - shared_ptr job = _job.lock (); + auto job = _job.lock (); if (job) { job->set_progress (float(period.from.get()) / _length.get()); } } + Frame SubtitleEncoder::frames_done () const {