X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fsubtitle_encoder.cc;h=2331eb52a8871241ba3ce58a87a3a99348a7aebf;hp=b61876ad6568f0fada6deb82d304a556f3c987aa;hb=5a820bb8fae34591be5ac6d19a73461b9dab532a;hpb=e0a70cd5cfb11fc2de167f3146acdd437a6faa82 diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index b61876ad6..2331eb52a 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019-2020 Carl Hetherington + Copyright (C) 2019-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,11 +18,11 @@ */ -#include "font_data.h" -#include "subtitle_encoder.h" -#include "player.h" + #include "compose.hpp" #include "job.h" +#include "player.h" +#include "subtitle_encoder.h" #include #include #include @@ -31,6 +31,7 @@ #include "i18n.h" + using std::make_pair; using std::make_shared; using std::pair; @@ -43,6 +44,7 @@ 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). @@ -85,6 +87,7 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr j _default_font = dcp::ArrayData (default_font_file()); } + void SubtitleEncoder::go () { @@ -99,33 +102,34 @@ 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) { for (auto j: _player->get_subtitle_fonts()) { - i->first->add_font (j.id, _default_font); + 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) { @@ -149,8 +153,8 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr s->set_content_title_text (_film->name()); if (lang.first) { s->set_language (*lang.first); - } else if (!track->language.empty()) { - s->set_language (dcp::LanguageTag(track->language)); + } 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); @@ -170,7 +174,7 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr 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) { @@ -179,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 {