2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include "lib/ffmpeg_content.h"
23 #include <boost/test/unit_test.hpp>
27 using boost::shared_ptr;
29 BOOST_AUTO_TEST_CASE (ffmpeg_time_calculation_test)
31 shared_ptr<Film> film = new_test_film ("ffmpeg_time_calculation_test");
33 string const xml = "<Content>"
35 "<Path>/home/c.hetherington/DCP/clapperboard.mp4</Path>"
36 "<Digest>2760e03c7251480f7f02c01a907792673784335</Digest>"
37 "<Position>0</Position>"
38 "<TrimStart>0</TrimStart>"
39 "<TrimEnd>0</TrimEnd>"
40 "<VideoLength>1353600</VideoLength>"
41 "<VideoWidth>1280</VideoWidth>"
42 "<VideoHeight>720</VideoHeight>"
43 "<VideoFrameRate>25</VideoFrameRate>"
44 "<VideoFrameType>0</VideoFrameType>"
45 "<LeftCrop>0</LeftCrop>"
46 "<RightCrop>0</RightCrop>"
47 "<TopCrop>0</TopCrop>"
48 "<BottomCrop>0</BottomCrop>"
53 "<InputTransferFunction>"
54 "<Type>ModifiedGamma</Type>"
55 "<Power>2.222222222222222</Power>"
56 "<Threshold>0.081</Threshold>"
59 "</InputTransferFunction>"
62 "<GreenX>0.3</GreenX>"
63 "<GreenY>0.6</GreenY>"
66 "<WhiteX>0.3127</WhiteX>"
67 "<WhiteY>0.329</WhiteY>"
68 "<OutputGamma>2.6</OutputGamma>"
71 "<FadeOut>0</FadeOut>"
72 "<AudioGain>0</AudioGain>"
73 "<AudioDelay>0</AudioDelay>"
74 "<UseSubtitles>0</UseSubtitles>"
75 "<SubtitleXOffset>0</SubtitleXOffset>"
76 "<SubtitleYOffset>0</SubtitleYOffset>"
77 "<SubtitleXScale>1</SubtitleXScale>"
78 "<SubtitleYScale>1</SubtitleYScale>"
79 "<SubtitleLanguage></SubtitleLanguage>"
81 "<Selected>1</Selected>"
82 "<Name>und; 2 channels</Name>"
84 "<FrameRate>44100</FrameRate>"
85 "<Channels>2</Channels>"
86 "<FirstAudio>0</FirstAudio>"
88 "<InputChannels>2</InputChannels>"
89 "<OutputChannels>12</OutputChannels>"
90 "<Gain Content=\"0\" DCP=\"0\">1</Gain>"
91 "<Gain Content=\"0\" DCP=\"1\">0</Gain>"
92 "<Gain Content=\"0\" DCP=\"2\">0</Gain>"
93 "<Gain Content=\"0\" DCP=\"3\">0</Gain>"
94 "<Gain Content=\"0\" DCP=\"4\">0</Gain>"
95 "<Gain Content=\"0\" DCP=\"5\">0</Gain>"
96 "<Gain Content=\"0\" DCP=\"6\">0</Gain>"
97 "<Gain Content=\"0\" DCP=\"7\">0</Gain>"
98 "<Gain Content=\"0\" DCP=\"8\">0</Gain>"
99 "<Gain Content=\"0\" DCP=\"9\">0</Gain>"
100 "<Gain Content=\"0\" DCP=\"10\">0</Gain>"
101 "<Gain Content=\"0\" DCP=\"11\">0</Gain>"
102 "<Gain Content=\"1\" DCP=\"0\">0</Gain>"
103 "<Gain Content=\"1\" DCP=\"1\">1</Gain>"
104 "<Gain Content=\"1\" DCP=\"2\">0</Gain>"
105 "<Gain Content=\"1\" DCP=\"3\">0</Gain>"
106 "<Gain Content=\"1\" DCP=\"4\">0</Gain>"
107 "<Gain Content=\"1\" DCP=\"5\">0</Gain>"
108 "<Gain Content=\"1\" DCP=\"6\">0</Gain>"
109 "<Gain Content=\"1\" DCP=\"7\">0</Gain>"
110 "<Gain Content=\"1\" DCP=\"8\">0</Gain>"
111 "<Gain Content=\"1\" DCP=\"9\">0</Gain>"
112 "<Gain Content=\"1\" DCP=\"10\">0</Gain>"
113 "<Gain Content=\"1\" DCP=\"11\">0</Gain>"
116 "<FirstVideo>0</FirstVideo>"
119 shared_ptr<cxml::Document> doc (new cxml::Document);
120 doc->read_string (xml);
123 shared_ptr<FFmpegContent> content (new FFmpegContent (film, doc, film->state_version(), notes));
125 /* 25fps content, 25fps DCP */
126 film->set_video_frame_rate (25);
127 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
128 /* 25fps content, 24fps DCP; length should be increased */
129 film->set_video_frame_rate (24);
130 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 24.0));
131 /* 25fps content, 30fps DCP; length should be decreased */
132 film->set_video_frame_rate (30);
133 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 30.0));
134 /* 25fps content, 50fps DCP; length should be the same */
135 film->set_video_frame_rate (50);
136 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() / 25.0));
137 /* 25fps content, 60fps DCP; length should be decreased */
138 film->set_video_frame_rate (60);
139 BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds (content->video_length() * (50.0 / 60) / 25.0));
142 /* XXX much more stuff to test */