libdcp
make_dcp.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
6  libdcp is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  libdcp is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with libdcp. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
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 <dcp/dcp.h>
29 #include <dcp/cpl.h>
30 #include <dcp/mono_picture_asset.h>
31 ... etc. ...
32 */
33 
34 #include "dcp.h"
35 #include "cpl.h"
36 #include "mono_picture_asset.h"
38 #include "sound_asset.h"
39 #include "sound_asset_writer.h"
40 #include "reel.h"
42 #include "reel_sound_asset.h"
43 #include <cmath>
44 
45 int
46 main ()
47 {
48  /* Set up libdcp */
49  dcp::init();
50 
51  /* Create a directory to put the DCP in */
52  boost::filesystem::create_directory("DCP");
53 
54  /* Make a picture asset. This is a file which combines JPEG2000 files together to make
55  up the video of the DCP. First, create the object, specifying a frame rate of 24 frames
56  per second.
57  */
58 
59  auto picture_asset = std::make_shared<dcp::MonoPictureAsset>(dcp::Fraction(24, 1), dcp::Standard::SMPTE);
60 
61  /* Start off a write to it */
62  auto picture_writer = picture_asset->start_write("DCP/picture.mxf", false);
63 
64  /* Write 24 frames of the same JPEG2000 file */
65  dcp::ArrayData picture("examples/help.j2c");
66  for (int i = 0; i < 24; ++i) {
67  picture_writer->write (picture);
68  }
69 
70  /* And finish off */
71  picture_writer->finalize();
72 
73  /* Now create a sound MXF. As before, create an object and a writer.
74  When creating the object we specify the sampling rate (48kHz) and the number of channels (2).
75  */
76  auto sound_asset = std::make_shared<dcp::SoundAsset>(dcp::Fraction(24, 1), 48000, 2, dcp::LanguageTag("en-GB"), dcp::Standard::SMPTE);
77  auto sound_writer = sound_asset->start_write("DCP/sound.mxf");
78 
79  /* Write some sine waves */
80  std::array<float, 48000> left;
81  std::array<float, 48000> right;
82  for (int i = 0; i < 48000; ++i) {
83  left[i] = sin (2 * M_PI * i * 440 / 48000) * 0.25;
84  right[i] = sin (2 * M_PI * i * 880 / 48000) * 0.25;
85  }
86  std::array<float*, 2> audio;
87  audio[0] = left.data();
88  audio[1] = right.data();
89  sound_writer->write (audio.data(), 48000);
90 
91  /* And finish off */
92  sound_writer->finalize ();
93 
94  /* Now create a reel */
95  auto reel = std::make_shared<dcp::Reel>();
96 
97  /* Add picture and sound to it. The zeros are the `entry points', i.e. the first
98  (video) frame from the assets that the reel should play.
99  */
100  reel->add(std::make_shared<dcp::ReelMonoPictureAsset>(picture_asset, 0));
101  reel->add(std::make_shared<dcp::ReelSoundAsset>(sound_asset, 0));
102 
103  /* Make a CPL with this reel */
104  auto cpl = std::make_shared<dcp::CPL>("My film", dcp::ContentKind::FEATURE, dcp::Standard::SMPTE);
105  cpl->add(reel);
106 
107  /* Write the DCP */
108  dcp::DCP dcp ("DCP");
109  dcp.add (cpl);
110  dcp.write_xml ();
111 
112  return 0;
113 }
Class to hold an arbitrary block of data.
Definition: array_data.h:55
A class to create or read a DCP.
Definition: dcp.h:83
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:214
CPL class.
DCP class.
MonoPictureAssetWriter class.
Namespace for everything in libdcp.
Definition: array_data.h:50
void init(boost::optional< boost::filesystem::path > resources_directory=boost::optional< boost::filesystem::path >())
ReelMonoPictureAsset class.
ReelSoundAsset class.
SoundAsset class.
SoundAssetWriter class.