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