2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/make_dcp_job.cc
21 * @brief A job to create DCPs.
25 #include <boost/filesystem.hpp>
26 #include <libdcp/dcp.h>
27 #include <libdcp/picture_asset.h>
28 #include <libdcp/sound_asset.h>
29 #include <libdcp/reel.h>
31 #include <libavutil/pixdesc.h>
33 #include "make_dcp_job.h"
34 #include "dcp_content_type.h"
35 #include "exceptions.h"
37 #include "imagemagick_decoder.h"
42 using boost::shared_ptr;
44 /** @param f Film we are making the DCP for.
47 MakeDCPJob::MakeDCPJob (shared_ptr<Film> f, shared_ptr<const EncodeOptions> o, shared_ptr<Job> req)
55 MakeDCPJob::name () const
57 return String::compose ("Make DCP for %1", _film->name());
60 /** @param f DCP frame index */
62 MakeDCPJob::j2c_path (int f, int offset) const
64 SourceFrame const s = ((f + offset) * dcp_frame_rate(_film->frames_per_second()).skip) + _film->dcp_trim_start();
65 return _opt->frame_out_path (s, false);
69 MakeDCPJob::wav_path (libdcp::Channel c) const
71 return _opt->multichannel_audio_out_path (int (c), false);
77 if (!_film->dcp_length()) {
78 throw EncodeError ("cannot make a DCP when the source length is not known");
83 string const dcp_path = _film->dir (_film->dcp_name());
85 /* Remove any old DCP */
86 boost::filesystem::remove_all (dcp_path);
88 DCPFrameRate const dfr = dcp_frame_rate (_film->frames_per_second ());
91 switch (_film->content_type ()) {
93 /* Source frames -> DCP frames */
94 frames = _film->dcp_length().get() / dfr.skip;
97 frames = _film->still_duration() * 24;
101 libdcp::DCP dcp (_film->dir (_film->dcp_name()));
102 dcp.Progress.connect (boost::bind (&MakeDCPJob::dcp_progress, this, _1));
104 shared_ptr<libdcp::CPL> cpl (
105 new libdcp::CPL (_film->dir (_film->dcp_name()), _film->dcp_name(), _film->dcp_content_type()->libdcp_kind (), frames, dfr.frames_per_second)
110 int frames_per_reel = 0;
111 if (_film->reel_size()) {
112 frames_per_reel = (_film->reel_size().get() / (_film->j2k_bandwidth() / 8)) * dfr.frames_per_second;
114 frames_per_reel = frames;
120 while (frames_done < frames) {
122 descend (float (frames_per_reel) / frames);
124 int this_time = std::min (frames_per_reel, (frames - frames_done));
128 shared_ptr<libdcp::MonoPictureAsset> pa (
129 new libdcp::MonoPictureAsset (
130 boost::bind (&MakeDCPJob::j2c_path, this, _1, frames_done),
131 _film->dir (_film->dcp_name()),
132 String::compose ("video_%1.mxf", reel),
134 dfr.frames_per_second,
136 _opt->out_size.width,
137 _opt->out_size.height,
144 shared_ptr<libdcp::SoundAsset> sa;
146 if (_film->audio_channels() > 0) {
149 new libdcp::SoundAsset (
150 boost::bind (&MakeDCPJob::wav_path, this, _1),
151 _film->dir (_film->dcp_name()),
152 String::compose ("audio_%1.mxf", reel),
154 dfr.frames_per_second,
157 dcp_audio_channels (_film->audio_channels()),
165 cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (pa, sa, shared_ptr<libdcp::SubtitleAsset> ())));
168 frames_done += frames_per_reel;
181 set_state (FINISHED_OK);
185 MakeDCPJob::dcp_progress (float p)