X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Freel_writer.cc;h=2631489028f22875aa26f5620f036277f49314df;hp=e34874a14ca91c7bed111c0c8759fcdb368d21d1;hb=ab0e8cdcafdcb83096012380f674b8280474e851;hpb=196de029044f4dbac5f74f68e08a89f778c3a236 diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index e34874a14..263148902 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -59,9 +60,11 @@ using boost::optional; using boost::dynamic_pointer_cast; using dcp::Data; using dcp::raw_convert; +using namespace dcpomatic; int const ReelWriter::_info_size = 48; +/** @param job Related job, or 0 */ ReelWriter::ReelWriter ( shared_ptr film, DCPTimePeriod period, shared_ptr job, int reel_index, int reel_count, optional content_summary ) @@ -97,7 +100,9 @@ ReelWriter::ReelWriter ( _film->internal_video_asset_dir() / _film->internal_video_asset_filename(_period) ); - job->sub (_("Checking existing image data")); + if (job) { + job->sub (_("Checking existing image data")); + } _first_nonexistant_frame = check_existing_picture_asset (); _picture_asset_writer = _picture_asset->start_write ( @@ -139,8 +144,9 @@ ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const } else { file = fopen_boost (info_file, "wb"); } + if (!file) { - throw OpenFileError (info_file, errno, read); + throw OpenFileError (info_file, errno, read ? OpenFileError::READ_WRITE : OpenFileError::WRITE); } dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET); checked_fwrite (&info.offset, sizeof (info.offset), file, info_file); @@ -362,9 +368,9 @@ maybe_add_text ( liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"; } - /* Add all the fonts to the subtitle content */ + /* Add the font to the subtitle content */ BOOST_FOREACH (shared_ptr j, fonts) { - asset->add_font (j->id(), j->file(FontFiles::NORMAL).get_value_or(liberation_normal)); + asset->add_font (j->id(), j->file().get_value_or(liberation_normal)); } if (dynamic_pointer_cast (asset)) { @@ -407,10 +413,10 @@ maybe_add_text ( } if (reel_asset) { - if (reel_asset->duration() != period_duration) { + if (reel_asset->actual_duration() != period_duration) { throw ProgrammingError ( __FILE__, __LINE__, - String::compose ("%1 vs %2", reel_asset->duration(), period_duration) + String::compose ("%1 vs %2", reel_asset->actual_duration(), period_duration) ); } reel->add (reel_asset); @@ -459,7 +465,7 @@ ReelWriter::create_reel (list const & refs, listduration() != period_duration) { throw ProgrammingError ( __FILE__, __LINE__, - String::compose ("%1 vs %2", reel_picture_asset->duration(), period_duration) + String::compose ("%1 vs %2", reel_picture_asset->actual_duration(), period_duration) ); } reel->add (reel_picture_asset); @@ -489,31 +495,50 @@ ReelWriter::create_reel (list const & refs, listduration() != period_duration) { + if (reel_sound_asset->actual_duration() != period_duration) { LOG_ERROR ( "Reel sound asset has length %1 but reel period is %2", - reel_sound_asset->duration(), + reel_sound_asset->actual_duration(), period_duration ); - if (reel_sound_asset->duration() != period_duration) { + if (reel_sound_asset->actual_duration() != period_duration) { throw ProgrammingError ( __FILE__, __LINE__, - String::compose ("%1 vs %2", reel_sound_asset->duration(), period_duration) + String::compose ("%1 vs %2", reel_sound_asset->actual_duration(), period_duration) ); } } reel->add (reel_sound_asset); - maybe_add_text (_subtitle_asset, reel_picture_asset->duration(), reel, refs, fonts, _film, _period); + maybe_add_text (_subtitle_asset, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period); for (map >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) { shared_ptr a = maybe_add_text ( - i->second, reel_picture_asset->duration(), reel, refs, fonts, _film, _period + i->second, reel_picture_asset->actual_duration(), reel, refs, fonts, _film, _period ); a->set_annotation_text (i->first.name); a->set_language (i->first.language); } + map markers = _film->markers (); + map reel_markers; + for (map::const_iterator i = markers.begin(); i != markers.end(); ++i) { + if (_period.contains(i->second)) { + reel_markers[i->first] = i->second; + } + } + + if (!reel_markers.empty ()) { + shared_ptr ma (new dcp::ReelMarkersAsset(dcp::Fraction(_film->video_frame_rate(), 1), 0)); + for (map::const_iterator i = reel_markers.begin(); i != reel_markers.end(); ++i) { + int h, m, s, f; + DCPTime relative = i->second - _period.from; + relative.split (_film->video_frame_rate(), h, m, s, f); + ma->set (i->first, dcp::Time(h, m, s, f, _film->video_frame_rate())); + } + reel->add (ma); + } + return reel; } @@ -566,19 +591,24 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, if (!asset) { string lang = _film->subtitle_language (); - if (lang.empty ()) { - lang = "Unknown"; - } if (_film->interop ()) { shared_ptr s (new dcp::InteropSubtitleAsset ()); s->set_movie_title (_film->name ()); - s->set_language (lang); + if (type == TEXT_OPEN_SUBTITLE) { + s->set_language (lang.empty() ? "Unknown" : lang); + } else { + s->set_language (track->language); + } s->set_reel_number (raw_convert (_reel_index + 1)); asset = s; } else { shared_ptr s (new dcp::SMPTESubtitleAsset ()); s->set_content_title_text (_film->name ()); - s->set_language (lang); + if (type == TEXT_OPEN_SUBTITLE && !lang.empty()) { + s->set_language (lang); + } else { + s->set_language (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 ()); @@ -614,8 +644,8 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, shared_ptr( new dcp::SubtitleImage( i.image->as_png(), - dcp::Time(period.from.seconds(), _film->video_frame_rate()), - dcp::Time(period.to.seconds(), _film->video_frame_rate()), + 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, dcp::Time(), dcp::Time() )