X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fmake_dcp_job.cc;h=37c9ca6206429d2a864e1f21e11c0c1f48805905;hb=f98c4cdec82fc2fbdcc4ca19748d09b0ea0556b4;hp=efd35ba444389f3d175c79ca2f72b7f0e43bece3;hpb=068bb5b95652c022419c64f3d29cc42c4610ae93;p=dcpomatic.git diff --git a/src/lib/make_dcp_job.cc b/src/lib/make_dcp_job.cc index efd35ba44..37c9ca620 100644 --- a/src/lib/make_dcp_job.cc +++ b/src/lib/make_dcp_job.cc @@ -21,6 +21,7 @@ * @brief A job to create DCPs. */ +#include #include #include #include @@ -30,21 +31,22 @@ extern "C" { #include } #include "make_dcp_job.h" -#include "film_state.h" #include "dcp_content_type.h" #include "exceptions.h" #include "options.h" #include "imagemagick_decoder.h" +#include "film.h" -using namespace std; -using namespace boost; +using std::string; +using std::cout; +using boost::shared_ptr; -/** @param s FilmState of the Film we are making the DCP for. +/** @param f Film we are making the DCP for. * @param o Options. - * @param l Log. */ -MakeDCPJob::MakeDCPJob (shared_ptr s, shared_ptr o, Log* l, shared_ptr req) - : Job (s, o, l, req) +MakeDCPJob::MakeDCPJob (shared_ptr f, shared_ptr o, shared_ptr req) + : Job (f, req) + , _opt (o) { } @@ -52,13 +54,15 @@ MakeDCPJob::MakeDCPJob (shared_ptr s, shared_ptr string MakeDCPJob::name () const { - return String::compose ("Make DCP for %1", _fs->name); + return String::compose ("Make DCP for %1", _film->name()); } +/** @param f DCP frame index */ string -MakeDCPJob::j2c_path (int f) const +MakeDCPJob::j2c_path (int f, int offset) const { - return _opt->frame_out_path (f, false); + SourceFrame const s = ((f + offset) * dcp_frame_rate(_film->frames_per_second()).skip) + _film->dcp_trim_start(); + return _opt->frame_out_path (s, false); } string @@ -70,64 +74,109 @@ MakeDCPJob::wav_path (libdcp::Channel c) const void MakeDCPJob::run () { - string const dcp_path = _fs->dir (_fs->dcp_name()); + if (!_film->dcp_length()) { + throw EncodeError ("cannot make a DCP when the source length is not known"); + } + + descend (0.9); + + string const dcp_path = _film->dir (_film->dcp_name()); /* Remove any old DCP */ - filesystem::remove_all (dcp_path); + boost::filesystem::remove_all (dcp_path); + + DCPFrameRate const dfr = dcp_frame_rate (_film->frames_per_second ()); int frames = 0; - switch (_fs->content_type ()) { + switch (_film->content_type ()) { case VIDEO: - frames = _fs->dcp_frames ? _fs->dcp_frames : _fs->length; + /* Source frames -> DCP frames */ + frames = _film->dcp_length().get() / dfr.skip; break; case STILL: - frames = _fs->still_duration * ImageMagickDecoder::static_frames_per_second (); + frames = _film->still_duration() * 24; break; } - - libdcp::DCP dcp (_fs->dir (_fs->dcp_name())); - dcp.Progress.connect (sigc::mem_fun (*this, &MakeDCPJob::dcp_progress)); - shared_ptr cpl (new libdcp::CPL (_fs->dir (_fs->dcp_name()), _fs->dcp_name(), _fs->dcp_content_type->libdcp_kind (), frames, rint (_fs->frames_per_second))); - dcp.add_cpl (cpl); + libdcp::DCP dcp (_film->dir (_film->dcp_name())); + dcp.Progress.connect (boost::bind (&MakeDCPJob::dcp_progress, this, _1)); - descend (0.9); - shared_ptr pa ( - new libdcp::MonoPictureAsset ( - sigc::mem_fun (*this, &MakeDCPJob::j2c_path), - _fs->dir (_fs->dcp_name()), - "video.mxf", - &dcp.Progress, - rint (_fs->frames_per_second), - frames, - _opt->out_size.width, - _opt->out_size.height - ) + shared_ptr cpl ( + new libdcp::CPL (_film->dir (_film->dcp_name()), _film->dcp_name(), _film->dcp_content_type()->libdcp_kind (), frames, dfr.frames_per_second) ); - ascend (); + dcp.add_cpl (cpl); - shared_ptr sa; + int frames_per_reel = 0; + if (_film->reel_size()) { + frames_per_reel = (_film->reel_size().get() / (_film->j2k_bandwidth() / 8)) * dfr.frames_per_second; + } else { + frames_per_reel = frames; + } - if (_fs->audio_channels > 0) { - descend (0.1); - sa.reset ( - new libdcp::SoundAsset ( - sigc::mem_fun (*this, &MakeDCPJob::wav_path), - _fs->dir (_fs->dcp_name()), - "audio.mxf", + int frames_done = 0; + int reel = 0; + + while (frames_done < frames) { + + descend (float (frames_per_reel) / frames); + + int this_time = std::min (frames_per_reel, (frames - frames_done)); + + descend (0.8); + + shared_ptr pa ( + new libdcp::MonoPictureAsset ( + boost::bind (&MakeDCPJob::j2c_path, this, _1, frames_done), + _film->dir (_film->dcp_name()), + String::compose ("video_%1.mxf", reel), &dcp.Progress, - rint (_fs->frames_per_second), - frames, - _fs->audio_channels + dfr.frames_per_second, + this_time, + _opt->out_size.width, + _opt->out_size.height, + _film->encrypted() ) ); + + ascend (); + + shared_ptr sa; + + if (_film->audio_channels() > 0) { + descend (0.1); + sa.reset ( + new libdcp::SoundAsset ( + boost::bind (&MakeDCPJob::wav_path, this, _1), + _film->dir (_film->dcp_name()), + String::compose ("audio_%1.mxf", reel), + &dcp.Progress, + dfr.frames_per_second, + this_time, + frames_done, + dcp_audio_channels (_film->audio_channels()), + _film->encrypted() + ) + ); + ascend (); + } + + descend (0.1); + cpl->add_reel (shared_ptr (new libdcp::Reel (pa, sa, shared_ptr ()))); + ascend (); + + frames_done += frames_per_reel; + ++reel; + ascend (); } - cpl->add_reel (shared_ptr (new libdcp::Reel (pa, sa, shared_ptr ()))); - dcp.write_xml (); + ascend (); + descend (0.1); + dcp.write_xml (); + ascend (); + set_progress (1); set_state (FINISHED_OK); }