#include "log.h"
#include "dcpomatic_log.h"
#include "digester.h"
-#include "font.h"
+#include "font_data.h"
#include "compose.hpp"
#include "config.h"
#include "audio_buffers.h"
#include <dcp/smpte_subtitle_asset.h>
#include <dcp/raw_convert.h>
#include <dcp/subtitle_image.h>
-#include <boost/foreach.hpp>
#include "i18n.h"
using std::cout;
using std::exception;
using std::map;
+using std::set;
using std::vector;
-using boost::shared_ptr;
+using std::shared_ptr;
+using std::make_shared;
using boost::optional;
-using boost::dynamic_pointer_cast;
+using std::dynamic_pointer_cast;
#if BOOST_VERSION >= 106100
using namespace boost::placeholders;
#endif
-using boost::weak_ptr;
+using std::weak_ptr;
using dcp::ArrayData;
using dcp::Data;
using dcp::raw_convert;
return meta;
}
-/** @param job Related job, or 0 */
+/** @param job Related job, or 0.
+ * @param text_only true to enable a special mode where the writer will expect only subtitles and closed captions to be written
+ * (no picture nor sound) and not give errors in that case. This is used by the hints system to check the potential sizes of
+ * subtitle / closed caption files.
+ */
ReelWriter::ReelWriter (
- weak_ptr<const Film> weak_film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count
+ weak_ptr<const Film> weak_film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count, bool text_only
)
: WeakConstFilm (weak_film)
, _period (period)
, _reel_count (reel_count)
, _content_summary (film()->content_summary(period))
, _job (job)
+ , _text_only (text_only)
{
/* Create or find our picture asset in a subdirectory, named
according to those film's parameters which affect the video
output. We will hard-link it into the DCP later.
*/
- dcp::Standard const standard = film()->interop() ? dcp::INTEROP : dcp::SMPTE;
+ dcp::Standard const standard = film()->interop() ? dcp::Standard::INTEROP : dcp::Standard::SMPTE;
boost::filesystem::path const asset =
film()->internal_video_asset_dir() / film()->internal_video_asset_filename(_period);
_picture_asset->set_file (asset);
_picture_asset_writer = _picture_asset->start_write (asset, _first_nonexistant_frame > 0);
- } else {
+ } else if (!text_only) {
/* We already have a complete picture asset that we can just re-use */
/* XXX: what about if the encryption key changes? */
if (film()->three_d()) {
DCPOMATIC_ASSERT (film()->directory());
vector<dcp::Channel> active;
- BOOST_FOREACH (int i, film()->mapped_audio_channels()) {
+ for (auto i: film()->mapped_audio_channels()) {
active.push_back (static_cast<dcp::Channel>(i));
}
film()->contains_atmos_content()
);
}
+
+ _default_font = dcp::ArrayData(default_font_file());
}
/** @param frame reel-relative frame */
}
void
-ReelWriter::finish ()
+ReelWriter::finish (boost::filesystem::path output_dcp)
{
if (_picture_asset_writer && !_picture_asset_writer->finalize ()) {
/* Nothing was written to the picture asset */
if (_picture_asset) {
DCPOMATIC_ASSERT (_picture_asset->file());
boost::filesystem::path video_from = _picture_asset->file().get();
- boost::filesystem::path video_to;
- video_to /= film()->dir(film()->dcp_name());
+ boost::filesystem::path video_to = output_dcp;
video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count, _content_summary);
/* There may be an existing "to" file if we are recreating a DCP in the same place without
changing any video.
/* Move the audio asset into the DCP */
if (_sound_asset) {
- boost::filesystem::path audio_to;
- audio_to /= film()->dir(film()->dcp_name ());
+ boost::filesystem::path audio_to = output_dcp;
string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary);
audio_to /= aaf;
if (_atmos_asset) {
_atmos_asset_writer->finalize ();
- boost::filesystem::path atmos_to;
- atmos_to /= film()->dir(film()->dcp_name());
+ boost::filesystem::path atmos_to = output_dcp;
string const aaf = atmos_asset_filename (_atmos_asset, _reel_index, _reel_count, _content_summary);
atmos_to /= aaf;
int64_t picture_duration,
shared_ptr<dcp::Reel> reel,
list<ReferencedReelAsset> const & refs,
- list<shared_ptr<Font> > const & fonts,
+ vector<FontData> const & fonts,
+ dcp::ArrayData default_font,
shared_ptr<const Film> film,
- DCPTimePeriod period
+ DCPTimePeriod period,
+ boost::filesystem::path output_dcp,
+ bool text_only
)
{
Frame const period_duration = period.duration().frames_round(film->video_frame_rate());
if (asset) {
/* Add the font to the subtitle content */
- BOOST_FOREACH (shared_ptr<Font> j, fonts) {
- asset->add_font (j->id(), j->file().get_value_or(default_font_file()));
+ for (auto const& j: fonts) {
+ asset->add_font (j.id, j.data.get_value_or(default_font));
}
if (dynamic_pointer_cast<dcp::InteropSubtitleAsset> (asset)) {
- boost::filesystem::path directory = film->dir (film->dcp_name ()) / asset->id ();
+ boost::filesystem::path directory = output_dcp / asset->id ();
boost::filesystem::create_directories (directory);
asset->write (directory / ("sub_" + asset->id() + ".xml"));
} else {
dynamic_pointer_cast<dcp::SMPTESubtitleAsset>(asset)->set_intrinsic_duration (picture_duration);
asset->write (
- film->dir(film->dcp_name()) / ("sub_" + asset->id() + ".mxf")
+ output_dcp / ("sub_" + asset->id() + ".mxf")
);
}
);
} else {
/* We don't have a subtitle asset of our own; hopefully we have one to reference */
- BOOST_FOREACH (ReferencedReelAsset j, refs) {
+ for (auto j: refs) {
shared_ptr<T> k = dynamic_pointer_cast<T> (j.asset);
if (k && j.period == period) {
reel_asset = k;
}
if (reel_asset) {
- if (reel_asset->actual_duration() != period_duration) {
+ if (!text_only && reel_asset->actual_duration() != period_duration) {
throw ProgrammingError (
__FILE__, __LINE__,
String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration)
} else {
LOG_GENERAL ("no picture asset of our own; look through %1", refs.size());
/* We don't have a picture asset of our own; hopefully we have one to reference */
- BOOST_FOREACH (ReferencedReelAsset j, refs) {
+ for (auto j: refs) {
shared_ptr<dcp::ReelPictureAsset> k = dynamic_pointer_cast<dcp::ReelPictureAsset> (j.asset);
if (k) {
LOG_GENERAL ("candidate picture asset period is %1-%2", j.period.from.get(), j.period.to.get());
} else {
LOG_GENERAL ("no sound asset of our own; look through %1", refs.size());
/* We don't have a sound asset of our own; hopefully we have one to reference */
- BOOST_FOREACH (ReferencedReelAsset j, refs) {
+ for (auto j: refs) {
shared_ptr<dcp::ReelSoundAsset> k = dynamic_pointer_cast<dcp::ReelSoundAsset> (j.asset);
if (k) {
LOG_GENERAL ("candidate sound asset period is %1-%2", j.period.from.get(), j.period.to.get());
void
-ReelWriter::create_reel_text (shared_ptr<dcp::Reel> reel, list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const& fonts, int64_t duration) const
+ReelWriter::create_reel_text (
+ shared_ptr<dcp::Reel> reel,
+ list<ReferencedReelAsset> const & refs,
+ vector<FontData> const& fonts,
+ int64_t duration,
+ boost::filesystem::path output_dcp,
+ bool ensure_subtitles,
+ set<DCPTextTrack> ensure_closed_captions
+ ) const
{
- shared_ptr<dcp::ReelSubtitleAsset> subtitle = maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, duration, reel, refs, fonts, film(), _period);
- if (subtitle && !film()->subtitle_languages().empty()) {
- subtitle->set_language (film()->subtitle_languages().front());
+ shared_ptr<dcp::ReelSubtitleAsset> subtitle = maybe_add_text<dcp::ReelSubtitleAsset> (
+ _subtitle_asset, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
+ );
+
+ if (subtitle) {
+ /* We have a subtitle asset that we either made or are referencing */
+ if (!film()->subtitle_languages().empty()) {
+ subtitle->set_language (film()->subtitle_languages().front());
+ }
+ } else if (ensure_subtitles) {
+ /* We had no subtitle asset, but we've been asked to make sure there is one */
+ subtitle = maybe_add_text<dcp::ReelSubtitleAsset>(
+ empty_text_asset(TEXT_OPEN_SUBTITLE, optional<DCPTextTrack>()),
+ duration,
+ reel,
+ refs,
+ fonts,
+ _default_font,
+ film(),
+ _period,
+ output_dcp,
+ _text_only
+ );
}
for (map<DCPTextTrack, shared_ptr<dcp::SubtitleAsset> >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) {
shared_ptr<dcp::ReelClosedCaptionAsset> a = maybe_add_text<dcp::ReelClosedCaptionAsset> (
- i->second, duration, reel, refs, fonts, film(), _period
+ i->second, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
);
- if (a) {
- a->set_annotation_text (i->first.name);
- if (!i->first.language.empty()) {
- a->set_language (dcp::LanguageTag(i->first.language));
- }
+ DCPOMATIC_ASSERT (a);
+ a->set_annotation_text (i->first.name);
+ if (!i->first.language.empty()) {
+ a->set_language (dcp::LanguageTag(i->first.language));
+ }
+
+ ensure_closed_captions.erase (i->first);
+ }
+
+ /* Make empty tracks for anything we've been asked to ensure but that we haven't added */
+ for (auto i: ensure_closed_captions) {
+ shared_ptr<dcp::ReelClosedCaptionAsset> a = maybe_add_text<dcp::ReelClosedCaptionAsset> (
+ empty_text_asset(TEXT_CLOSED_CAPTION, i), duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only
+ );
+ DCPOMATIC_ASSERT (a);
+ a->set_annotation_text (i.name);
+ if (!i.language.empty()) {
+ a->set_language (dcp::LanguageTag(i.language));
}
}
}
}
if (!reel_markers.empty ()) {
- shared_ptr<dcp::ReelMarkersAsset> ma (new dcp::ReelMarkersAsset(dcp::Fraction(film()->video_frame_rate(), 1), 0));
+ auto ma = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(film()->video_frame_rate(), 1), reel->duration(), 0);
for (map<dcp::Marker, DCPTime>::const_iterator i = reel_markers.begin(); i != reel_markers.end(); ++i) {
int h, m, s, f;
DCPTime relative = i->second - _period.from;
}
+/** @param ensure_subtitles true to make sure the reel has a subtitle asset.
+ * @param ensure_closed_captions make sure the reel has these closed caption tracks.
+ */
shared_ptr<dcp::Reel>
-ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const & fonts)
+ReelWriter::create_reel (
+ list<ReferencedReelAsset> const & refs,
+ vector<FontData> const & fonts,
+ boost::filesystem::path output_dcp,
+ bool ensure_subtitles,
+ set<DCPTextTrack> ensure_closed_captions
+ )
{
LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count);
shared_ptr<dcp::Reel> reel (new dcp::Reel());
- shared_ptr<dcp::ReelPictureAsset> reel_picture_asset = create_reel_picture (reel, refs);
- create_reel_sound (reel, refs);
- create_reel_text (reel, refs, fonts, reel_picture_asset->actual_duration());
- create_reel_markers (reel);
+
+ /* This is a bit of a hack; in the strange `_text_only' mode we have no picture, so we don't know
+ * how long the subtitle / CCAP assets should be. However, since we're only writing them to see
+ * how big they are, we don't care about that.
+ */
+ int64_t duration = 0;
+ if (!_text_only) {
+ shared_ptr<dcp::ReelPictureAsset> reel_picture_asset = create_reel_picture (reel, refs);
+ duration = reel_picture_asset->actual_duration ();
+ create_reel_sound (reel, refs);
+ create_reel_markers (reel);
+ }
+
+ create_reel_text (reel, refs, fonts, duration, output_dcp, ensure_subtitles, ensure_closed_captions);
if (_atmos_asset) {
reel->add (shared_ptr<dcp::ReelAtmosAsset>(new dcp::ReelAtmosAsset(_atmos_asset, 0)));
_sound_asset_writer->write (audio->data(), audio->frames());
}
+
+shared_ptr<dcp::SubtitleAsset>
+ReelWriter::empty_text_asset (TextType type, optional<DCPTextTrack> track) const
+{
+ shared_ptr<dcp::SubtitleAsset> asset;
+
+ vector<dcp::LanguageTag> lang = film()->subtitle_languages();
+ if (film()->interop()) {
+ shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
+ s->set_movie_title (film()->name());
+ if (type == TEXT_OPEN_SUBTITLE) {
+ s->set_language (lang.empty() ? "Unknown" : lang.front().to_string());
+ } else if (!track->language.empty()) {
+ s->set_language (track->language);
+ }
+ s->set_reel_number (raw_convert<string> (_reel_index + 1));
+ asset = s;
+ } else {
+ shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
+ s->set_content_title_text (film()->name());
+ s->set_metadata (mxf_metadata());
+ if (type == TEXT_OPEN_SUBTITLE && !lang.empty()) {
+ s->set_language (lang.front());
+ } else if (track && !track->language.empty()) {
+ 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);
+ s->set_time_code_rate (film()->video_frame_rate());
+ s->set_start_time (dcp::Time ());
+ if (film()->encrypted()) {
+ s->set_key (film()->key());
+ }
+ asset = s;
+ }
+
+ return asset;
+}
+
+
void
ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
{
}
if (!asset) {
- vector<dcp::LanguageTag> lang = film()->subtitle_languages();
- if (film()->interop()) {
- shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
- s->set_movie_title (film()->name());
- if (type == TEXT_OPEN_SUBTITLE) {
- s->set_language (lang.empty() ? "Unknown" : lang.front().to_string());
- } else if (!track->language.empty()) {
- s->set_language (track->language);
- }
- s->set_reel_number (raw_convert<string> (_reel_index + 1));
- asset = s;
- } else {
- shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
- s->set_content_title_text (film()->name());
- s->set_metadata (mxf_metadata());
- if (type == TEXT_OPEN_SUBTITLE && !lang.empty()) {
- s->set_language (lang.front());
- } else if (track && !track->language.empty()) {
- 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);
- s->set_time_code_rate (film()->video_frame_rate());
- s->set_start_time (dcp::Time ());
- if (film()->encrypted()) {
- s->set_key (film()->key());
- }
- asset = s;
- }
+ asset = empty_text_asset (type, track);
}
switch (type) {
DCPOMATIC_ASSERT (false);
}
- 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() - dcp::Time (_period.from.seconds(), i.in().tcr));
i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr));
asset->add (shared_ptr<dcp::Subtitle>(new dcp::SubtitleString(i)));
}
- BOOST_FOREACH (BitmapText i, subs.bitmap) {
+ for (auto i: subs.bitmap) {
asset->add (
shared_ptr<dcp::Subtitle>(
new dcp::SubtitleImage(
i.image->as_png(),
dcp::Time(period.from.seconds() - _period.from.seconds(), film()->video_frame_rate()),
dcp::Time(period.to.seconds() - _period.from.seconds(), film()->video_frame_rate()),
- i.rectangle.x, dcp::HALIGN_LEFT, i.rectangle.y, dcp::VALIGN_TOP,
+ i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP,
dcp::Time(), dcp::Time()
)
)