Use make_dcp example in documentation.
[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, "My Film" is the title
53            that will be shown on the projector / TMS when the DCP is ingested.
54
55            FEATURE is the type that the projector will list the DCP as.
56
57            24 is the frame rate, and the DCP will be 48 frames long (ie 2 seconds at 24 fps).
58         */
59         libdcp::DCP dcp ("My Film DCP", "My Film", libdcp::FEATURE, 24, 48);
60
61         /* Now make a `picture asset'.  This is a collection of the JPEG2000 files that make up the picture, one per frame.
62            Here we're using a function (video_frame) to obtain the name of the JPEG2000 file for each frame.
63
64            The result will be an MXF file written to the directory "My Film DCP" (which should be the same as the DCP's
65            directory above) called "video.mxf".
66
67            The other parameters specify the entry_point (the frame at which the projector should start showing the picture),
68            the frame rate, the number of frames and the resolution of the frames; 1998x1080 is the DCI Flat specification
69            for 2K projectors.
70         */
71         boost::shared_ptr<libdcp::MonoPictureAsset> picture_asset (
72                 new libdcp::MonoPictureAsset (sigc::ptr_fun (&video_frame), "My Film DCP", "video.mxf", 0, 24, 48, 1998, 1080)
73                 );
74
75         /* Now we will create a `sound asset', which is made up of a WAV file for each channel of audio.  Here we're using
76            stereo, so we add two WAV files to a vector.
77
78            We could add more files here to use more channels; the file order is:
79                Left
80                Right
81                Centre
82                LFE (sub)
83                Left surround
84                Right surround
85         */
86         std::vector<std::string> sound_files;
87         sound_files.push_back ("examples/sine_440_-12dB.wav");
88         sound_files.push_back ("examples/sine_880_-12dB.wav");
89
90         /* Now we can create the sound asset using these files */
91         boost::shared_ptr<libdcp::SoundAsset> sound_asset (
92                 new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48)
93                 );
94
95         /* Now that we have the assets, we can create a Reel to put them in and add it to the DCP */
96         dcp.add_reel (
97                 boost::shared_ptr<libdcp::Reel> (
98                         new libdcp::Reel (picture_asset, sound_asset, boost::shared_ptr<libdcp::SubtitleAsset> ())
99                         )
100                 );
101
102         /* Finally, we call this to write the XML description files to the DCP.  After this, the DCP
103            is ready to ingest and play.
104         */
105         dcp.write_xml ();
106
107         return 0;
108 }