Somewhat hacky rearrangement to support multiple CPLs per DCP.
[libdcp.git] / examples / make_dcp.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file examples/make_dcp.cc
21  *  @brief Shows how to make a DCP from some JPEG2000 and WAV files.
22  */
23
24 #include <vector>
25 #include <string>
26 #include <sigc++/sigc++.h>
27
28 /* If you are using an installed libdcp, these #includes would need to be changed to
29 #include <libdcp/dcp.h>
30 #include <libdcp/picture_asset.h>
31 ... etc. ...
32 */
33
34 #include "dcp.h"
35 #include "picture_asset.h"
36 #include "sound_asset.h"
37 #include "reel.h"
38
39 /* This method returns the filename of the JPEG2000 file to use for a given frame.
40    In this example, we are using the same file for each frame, so we don't bother
41    looking at the frame parameter, but it will called with frame=0, frame=1, ...
42 */
43 std::string
44 video_frame (int /* frame */)
45 {
46         return "examples/help.j2c";
47 }
48
49 int
50 main ()
51 {
52         /* Make a DCP object.  "My Film DCP" is the directory name for the DCP */
53         libdcp::DCP dcp ("My Film DCP");
54         
55         /* Now make a CPL object.
56
57            "My Film" is the title that will be shown on the projector / TMS when the DCP is ingested.
58            FEATURE is the type that the projector will list the DCP as.
59            24 is the frame rate, and the DCP will be 48 frames long (ie 2 seconds at 24 fps).
60         */      
61         boost::shared_ptr<libdcp::CPL> cpl (new libdcp::CPL ("My Film DCP", "My Film", libdcp::FEATURE, 24, 48));
62
63         /* And add the CPL to the DCP */
64         dcp.add_cpl (cpl);
65
66         /* Now make a `picture asset'.  This is a collection of the JPEG2000 files that make up the picture, one per frame.
67            Here we're using a function (video_frame) to obtain the name of the JPEG2000 file for each frame.
68
69            The result will be an MXF file written to the directory "My Film DCP" (which should be the same as the DCP's
70            directory above) called "video.mxf".
71
72            The other parameters specify the entry_point (the frame at which the projector should start showing the picture),
73            the frame rate, the number of frames and the resolution of the frames; 1998x1080 is the DCI Flat specification
74            for 2K projectors.
75         */
76         boost::shared_ptr<libdcp::MonoPictureAsset> picture_asset (
77                 new libdcp::MonoPictureAsset (sigc::ptr_fun (&video_frame), "My Film DCP", "video.mxf", 0, 24, 48, 1998, 1080)
78                 );
79
80         /* Now we will create a `sound asset', which is made up of a WAV file for each channel of audio.  Here we're using
81            stereo, so we add two WAV files to a vector.
82
83            We could add more files here to use more channels; the file order is:
84                Left
85                Right
86                Centre
87                LFE (sub)
88                Left surround
89                Right surround
90         */
91         std::vector<std::string> sound_files;
92         sound_files.push_back ("examples/sine_440_-12dB.wav");
93         sound_files.push_back ("examples/sine_880_-12dB.wav");
94
95         /* Now we can create the sound asset using these files */
96         boost::shared_ptr<libdcp::SoundAsset> sound_asset (
97                 new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48)
98                 );
99
100         /* Now that we have the assets, we can create a Reel to put them in and add it to the CPL */
101         cpl->add_reel (
102                 boost::shared_ptr<libdcp::Reel> (
103                         new libdcp::Reel (picture_asset, sound_asset, boost::shared_ptr<libdcp::SubtitleAsset> ())
104                         )
105                 );
106
107         /* Finally, we call this to write the XML description files to the DCP.  After this, the DCP
108            is ready to ingest and play.
109         */
110         dcp.write_xml ();
111
112         return 0;
113 }