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.
24 #include <boost/filesystem.hpp>
25 #include <libdcp/dcp.h>
26 #include <libdcp/picture_asset.h>
27 #include <libdcp/sound_asset.h>
28 #include <libdcp/reel.h>
30 #include <libavutil/pixdesc.h>
32 #include "make_dcp_job.h"
33 #include "dcp_content_type.h"
34 #include "exceptions.h"
36 #include "imagemagick_decoder.h"
40 using boost::shared_ptr;
42 /** @param f Film we are making the DCP for.
45 MakeDCPJob::MakeDCPJob (shared_ptr<Film> f, shared_ptr<const Options> o, shared_ptr<Job> req)
53 MakeDCPJob::name () const
55 return String::compose ("Make DCP for %1", _film->name());
58 /** @param f DCP frame index */
60 MakeDCPJob::j2c_path (int f) const
62 SourceFrame const s = (f * dcp_frame_rate(_film->frames_per_second()).skip) + _film->dcp_trim_start();
63 return _opt->frame_out_path (s, false);
67 MakeDCPJob::wav_path (libdcp::Channel c) const
69 return _opt->multichannel_audio_out_path (int (c), false);
75 if (!_film->dcp_length()) {
76 throw EncodeError ("cannot make a DCP when the source length is not known");
79 string const dcp_path = _film->dir (_film->dcp_name());
81 /* Remove any old DCP */
82 boost::filesystem::remove_all (dcp_path);
84 DCPFrameRate const dfr = dcp_frame_rate (_film->frames_per_second ());
87 switch (_film->content_type ()) {
89 /* Source frames -> DCP frames */
90 frames = _film->dcp_length().get() / dfr.skip;
93 frames = _film->still_duration() * ImageMagickDecoder::static_frames_per_second ();
97 libdcp::DCP dcp (_film->dir (_film->dcp_name()));
98 dcp.Progress.connect (boost::bind (&MakeDCPJob::dcp_progress, this, _1));
100 shared_ptr<libdcp::CPL> cpl (
101 new libdcp::CPL (_film->dir (_film->dcp_name()), _film->dcp_name(), _film->dcp_content_type()->libdcp_kind (), frames, dfr.frames_per_second)
107 shared_ptr<libdcp::MonoPictureAsset> pa (
108 new libdcp::MonoPictureAsset (
109 boost::bind (&MakeDCPJob::j2c_path, this, _1),
110 _film->dir (_film->dcp_name()),
113 dfr.frames_per_second,
115 _opt->out_size.width,
116 _opt->out_size.height
122 shared_ptr<libdcp::SoundAsset> sa;
124 if (_film->audio_channels() > 0) {
127 new libdcp::SoundAsset (
128 boost::bind (&MakeDCPJob::wav_path, this, _1),
129 _film->dir (_film->dcp_name()),
132 dfr.frames_per_second,
134 _film->audio_channels()
140 cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (pa, sa, shared_ptr<libdcp::SubtitleAsset> ())));
144 set_state (FINISHED_OK);
148 MakeDCPJob::dcp_progress (float p)