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 "film_state.h"
34 #include "dcp_content_type.h"
35 #include "exceptions.h"
37 #include "imagemagick_decoder.h"
40 using namespace boost;
42 /** @param s FilmState of the Film we are making the DCP for.
46 MakeDCPJob::MakeDCPJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l, shared_ptr<Job> req)
53 MakeDCPJob::name () const
55 return String::compose ("Make DCP for %1", _fs->name);
59 MakeDCPJob::j2c_path (int f) const
61 return _opt->frame_out_path (f, false);
65 MakeDCPJob::wav_path (libdcp::Channel c) const
67 return _opt->multichannel_audio_out_path (int (c), false);
73 string const dcp_path = _fs->dir (_fs->name);
75 /* Remove any old DCP */
76 filesystem::remove_all (dcp_path);
79 switch (_fs->content_type ()) {
81 frames = _fs->dcp_frames ? _fs->dcp_frames : _fs->length;
84 frames = _fs->still_duration * ImageMagickDecoder::static_frames_per_second ();
88 libdcp::DCP dcp (_fs->dir (_fs->name));
89 dcp.Progress.connect (sigc::mem_fun (*this, &MakeDCPJob::dcp_progress));
91 shared_ptr<libdcp::CPL> cpl (new libdcp::CPL (_fs->dir (_fs->name), _fs->name, _fs->dcp_content_type->libdcp_kind (), frames, rint (_fs->frames_per_second)));
95 shared_ptr<libdcp::MonoPictureAsset> pa (
96 new libdcp::MonoPictureAsset (
97 sigc::mem_fun (*this, &MakeDCPJob::j2c_path),
101 rint (_fs->frames_per_second),
103 _opt->out_size.width,
104 _opt->out_size.height
110 shared_ptr<libdcp::SoundAsset> sa;
112 if (_fs->audio_channels > 0) {
115 new libdcp::SoundAsset (
116 sigc::mem_fun (*this, &MakeDCPJob::wav_path),
117 _fs->dir (_fs->name),
120 rint (_fs->frames_per_second),
128 cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (pa, sa, shared_ptr<libdcp::SubtitleAsset> ())));
132 set_state (FINISHED_OK);
136 MakeDCPJob::dcp_progress (float p)