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/picture_asset.cc
21 * @brief An asset made up of JPEG2000 files
28 #include <boost/filesystem.hpp>
30 #include "KM_fileio.h"
31 #include "picture_asset.h"
33 #include "exceptions.h"
36 using namespace boost;
37 using namespace libdcp;
39 PictureAsset::PictureAsset (
40 sigc::slot<string, int> get_path,
42 sigc::signal1<void, float>* progress,
47 : Asset (mxf_path, progress, fps, length)
54 PictureAsset::PictureAsset (
55 vector<string> const & files,
57 sigc::signal1<void, float>* progress,
62 : Asset (mxf_path, progress, fps, length)
66 construct (sigc::bind (sigc::mem_fun (*this, &PictureAsset::path_from_list), files));
70 PictureAsset::path_from_list (int f, vector<string> const & files) const
76 PictureAsset::construct (sigc::slot<string, int> get_path)
78 ASDCP::JP2K::CodestreamParser j2k_parser;
79 ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
80 if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) {
81 throw FileError ("could not open JPEG2000 file for reading", get_path (0));
84 ASDCP::JP2K::PictureDescriptor picture_desc;
85 j2k_parser.FillPictureDescriptor (picture_desc);
86 picture_desc.EditRate = ASDCP::Rational (_fps, 1);
88 ASDCP::WriterInfo writer_info;
89 fill_writer_info (&writer_info);
91 ASDCP::JP2K::MXFWriter mxf_writer;
92 if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, picture_desc))) {
93 throw FileError ("could not open MXF file for writing", _mxf_path);
96 for (int i = 0; i < _length; ++i) {
98 string const path = get_path (i);
100 if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) {
101 throw FileError ("could not open JPEG2000 file for reading", path);
104 /* XXX: passing 0 to WriteFrame ok? */
105 if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
106 throw MiscError ("error in writing video MXF");
109 (*_progress) (0.5 * float (i) / _length);
112 if (ASDCP_FAILURE (mxf_writer.Finalize())) {
113 throw MiscError ("error in finalising video MXF");
116 _digest = make_digest (_mxf_path, _progress);
120 PictureAsset::write_to_cpl (ostream& s) const
122 s << " <MainPicture>\n"
123 << " <Id>urn:uuid:" << _uuid << "</Id>\n"
124 << " <AnnotationText>" << filesystem::path(_mxf_path).filename().string() << "</AnnotationText>\n"
125 << " <EditRate>" << _fps << " 1</EditRate>\n"
126 << " <IntrinsicDuration>" << _length << "</IntrinsicDuration>\n"
127 << " <EntryPoint>0</EntryPoint>\n"
128 << " <Duration>" << _length << "</Duration>\n"
129 << " <FrameRate>" << _fps << " 1</FrameRate>\n"
130 << " <ScreenAspectRatio>" << _width << " " << _height << "</ScreenAspectRatio>\n"
131 << " </MainPicture>\n";