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));
69 PictureAsset::PictureAsset (string mxf_path, int fps, int length, int width, int height)
70 : Asset (mxf_path, 0, fps, length)
78 PictureAsset::path_from_list (int f, vector<string> const & files) const
84 PictureAsset::construct (sigc::slot<string, int> get_path)
86 ASDCP::JP2K::CodestreamParser j2k_parser;
87 ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
88 if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) {
89 throw FileError ("could not open JPEG2000 file for reading", get_path (0));
92 ASDCP::JP2K::PictureDescriptor picture_desc;
93 j2k_parser.FillPictureDescriptor (picture_desc);
94 picture_desc.EditRate = ASDCP::Rational (_fps, 1);
96 ASDCP::WriterInfo writer_info;
97 fill_writer_info (&writer_info);
99 ASDCP::JP2K::MXFWriter mxf_writer;
100 if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, picture_desc))) {
101 throw FileError ("could not open MXF file for writing", _mxf_path);
104 for (int i = 0; i < _length; ++i) {
106 string const path = get_path (i);
108 if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) {
109 throw FileError ("could not open JPEG2000 file for reading", path);
112 /* XXX: passing 0 to WriteFrame ok? */
113 if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
114 throw MiscError ("error in writing video MXF");
117 (*_progress) (0.5 * float (i) / _length);
120 if (ASDCP_FAILURE (mxf_writer.Finalize())) {
121 throw MiscError ("error in finalising video MXF");
124 _digest = make_digest (_mxf_path, _progress);
128 PictureAsset::write_to_cpl (ostream& s) const
130 s << " <MainPicture>\n"
131 << " <Id>urn:uuid:" << _uuid << "</Id>\n"
132 #if BOOST_FILESYSTEM_VERSION == 3
133 << " <AnnotationText>" << filesystem::path(_mxf_path).filename().string() << "</AnnotationText>\n"
135 << " <AnnotationText>" << filesystem::path(_mxf_path).filename() << "</AnnotationText>\n"
137 << " <EditRate>" << _fps << " 1</EditRate>\n"
138 << " <IntrinsicDuration>" << _length << "</IntrinsicDuration>\n"
139 << " <EntryPoint>0</EntryPoint>\n"
140 << " <Duration>" << _length << "</Duration>\n"
141 << " <FrameRate>" << _fps << " 1</FrameRate>\n"
142 << " <ScreenAspectRatio>" << _width << " " << _height << "</ScreenAspectRatio>\n"
143 << " </MainPicture>\n";