2 Copyright (C) 2012-2014 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 /* If you are using an installed libdcp, these #includes would need to be changed to
21 #include <libdcp/dcp.h>
22 #include <libdcp/picture_mxf.h>
29 #include "reel_picture_asset.h"
30 #include "mono_picture_frame.h"
31 #include "mono_picture_mxf.h"
32 #include "stereo_picture_mxf.h"
33 #include "sound_mxf.h"
34 #include "subtitle_content.h"
35 #include "argb_frame.h"
38 /** @file examples/read_dcp.cc
39 * @brief Shows how to read a DCP.
45 /* Create a DCP, specifying where our existing data is */
46 dcp::DCP dcp ("/home/carl/diagonal.com/APPASSIONATA_TLR_F_UK-DEFR_CH_51_2K_LOK_20121115_DGL_OV");
47 /* Read the DCP to find out about it */
50 if (dcp.encrypted ()) {
51 std::cout << "DCP is encrypted.\n";
53 std::cout << "DCP is not encrypted.\n";
56 std::cout << "DCP has " << dcp.cpls().size() << " CPLs.\n";
57 std::list<boost::shared_ptr<dcp::Asset> > assets = dcp.assets ();
58 std::cout << "DCP has " << assets.size() << " assets.\n";
59 for (std::list<boost::shared_ptr<dcp::Asset> >::const_iterator i = assets.begin(); i != assets.end(); ++i) {
60 if (boost::dynamic_pointer_cast<dcp::MonoPictureMXF> (*i)) {
61 std::cout << "2D picture\n";
62 } else if (boost::dynamic_pointer_cast<dcp::StereoPictureMXF> (*i)) {
63 std::cout << "3D picture\n";
64 } else if (boost::dynamic_pointer_cast<dcp::SoundMXF> (*i)) {
65 std::cout << "Sound\n";
66 } else if (boost::dynamic_pointer_cast<dcp::SubtitleContent> (*i)) {
67 std::cout << "Subtitle\n";
68 } else if (boost::dynamic_pointer_cast<dcp::CPL> (*i)) {
71 std::cout << "\t" << (*i)->file().leaf().string() << "\n";
74 /* Take the first CPL */
75 boost::shared_ptr<dcp::CPL> cpl = dcp.cpls().front ();
77 /* Get the MXF of the picture asset in the first reel */
78 boost::shared_ptr<dcp::MonoPictureMXF> picture_mxf = boost::dynamic_pointer_cast<dcp::MonoPictureMXF> (cpl->reels().front()->main_picture()->mxf ());
80 /* Get the 1000th frame of it */
81 boost::shared_ptr<const dcp::MonoPictureFrame> picture_frame_j2k = picture_mxf->get_frame(999);
83 /* Get a ARGB copy of it */
84 boost::shared_ptr<dcp::ARGBFrame> picture_frame_rgb = picture_frame_j2k->argb_frame ();
86 Magick::Image image (picture_frame_rgb->size().width, picture_frame_rgb->size().height, "BGRA", Magick::CharPixel, picture_frame_rgb->data ());
87 image.write ("frame.png");