*/
#include <boost/filesystem.hpp>
+#include <libdcp/dcp.h>
extern "C" {
#include <libavutil/pixdesc.h>
}
#include "film_state.h"
#include "dcp_content_type.h"
#include "exceptions.h"
+#include "options.h"
+#include "imagemagick_decoder.h"
using namespace std;
using namespace boost;
* @param l Log.
*/
MakeDCPJob::MakeDCPJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
- : ShellCommandJob (s, o, l)
+ : Job (s, o, l)
{
}
return s.str ();
}
+string
+MakeDCPJob::j2c_path (int f) const
+{
+ return _opt->frame_out_path (f, false);
+}
+
+string
+MakeDCPJob::wav_path (libdcp::Channel c) const
+{
+ return _opt->multichannel_audio_out_path (int (c), false);
+}
+
void
MakeDCPJob::run ()
{
- set_progress_unknown ();
-
string const dcp_path = _fs->dir (_fs->name);
-
- /* Check that we have our prerequisites */
-
- if (!filesystem::exists (filesystem::path (_fs->file ("video.mxf")))) {
- throw EncodeError ("missing video.mxf");
- }
-
- bool const have_audio = filesystem::exists (filesystem::path (_fs->file ("audio.mxf")));
/* Remove any old DCP */
filesystem::remove_all (dcp_path);
- /* Re-make the DCP directory */
- _fs->dir (_fs->name);
-
- stringstream c;
- c << "cd \"" << dcp_path << "\" && "
- << " opendcp_xml -d -a \"" << _fs->name << "\""
- << " -t \"" << _fs->name << "\""
- << " -k " << _fs->dcp_content_type->opendcp_name()
- << " --reel \"" << _fs->file ("video.mxf") << "\"";
-
- if (have_audio) {
- c << " \"" << _fs->file ("audio.mxf") << "\"";
+ int frames = 0;
+ switch (_fs->content_type ()) {
+ case VIDEO:
+ frames = _fs->dcp_frames ? _fs->dcp_frames : _fs->length;
+ break;
+ case STILL:
+ frames = _fs->still_duration * ImageMagickDecoder::static_frames_per_second ();
+ break;
}
+
+ libdcp::DCP dcp (_fs->dir (_fs->name), _fs->name, _fs->dcp_content_type->libdcp_kind (), rint (_fs->frames_per_second), frames);
+ dcp.Progress.connect (sigc::mem_fun (*this, &MakeDCPJob::dcp_progress));
- command (c.str ());
+ descend (0.9);
+ dcp.add_picture_asset (sigc::mem_fun (*this, &MakeDCPJob::j2c_path), _opt->out_size.width, _opt->out_size.height);
+ ascend ();
- filesystem::rename (filesystem::path (_fs->file ("video.mxf")), filesystem::path (dcp_path + "/video.mxf"));
- if (have_audio) {
- filesystem::rename (filesystem::path (_fs->file ("audio.mxf")), filesystem::path (dcp_path + "/audio.mxf"));
+ if (_fs->audio_channels > 0) {
+ descend (0.1);
+ dcp.add_sound_asset (sigc::mem_fun (*this, &MakeDCPJob::wav_path), _fs->audio_channels);
+ ascend ();
}
+ dcp.write_xml ();
+
set_progress (1);
+ set_state (FINISHED_OK);
+}
+
+void
+MakeDCPJob::dcp_progress (float p)
+{
+ set_progress (p);
}