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