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