2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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.
11 DCP-o-matic 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.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "compose.hpp"
23 #include "frame_interval_checker.h"
25 #include "j2k_image_proxy.h"
27 #include "raw_image_proxy.h"
28 #include "video_decoder.h"
35 using std::dynamic_pointer_cast;
36 using std::shared_ptr;
37 using namespace dcpomatic;
40 VideoDecoder::VideoDecoder (Decoder* parent, shared_ptr<const Content> c)
41 : DecoderPart (parent)
43 , _frame_interval_checker (new FrameIntervalChecker())
49 /** Called by decoder classes when they have a video frame ready */
51 VideoDecoder::emit(shared_ptr<const Film> film, shared_ptr<const ImageProxy> image, ContentTime time)
57 auto const afr = _content->active_video_frame_rate(film);
58 auto const vft = _content->video->frame_type();
60 /* Do some heuristics to try and spot the case where the user sets content to 3D
61 * when it is not. We try to tell this by looking at the differences in time between
62 * the first few frames. Real 3D content should have two frames for each timestamp.
64 if (_frame_interval_checker) {
65 _frame_interval_checker->feed(time, afr);
66 if (_frame_interval_checker->guess() == FrameIntervalChecker::PROBABLY_NOT_3D && vft == VideoFrameType::THREE_D) {
67 boost::throw_exception (
70 _("The content file %1 is set as 3D but does not appear to contain 3D images. Please set it to 2D. "
71 "You can still make a 3D DCP from this content by ticking the 3D option in the DCP video tab."),
78 if (_frame_interval_checker->guess() != FrameIntervalChecker::AGAIN) {
79 _frame_interval_checker.reset ();
84 case VideoFrameType::TWO_D:
85 Data(ContentVideo(image, time, Eyes::BOTH, Part::WHOLE));
87 case VideoFrameType::THREE_D:
89 auto eyes = Eyes::LEFT;
90 auto j2k = dynamic_pointer_cast<const J2KImageProxy>(image);
91 if (j2k && j2k->eye()) {
92 eyes = *j2k->eye() == dcp::Eye::LEFT ? Eyes::LEFT : Eyes::RIGHT;
95 Data(ContentVideo(image, time, eyes, Part::WHOLE));
98 case VideoFrameType::THREE_D_ALTERNATE:
101 if (_last_emitted_eyes) {
102 eyes = _last_emitted_eyes.get() == Eyes::LEFT ? Eyes::RIGHT : Eyes::LEFT;
104 /* We don't know what eye this frame is, so just guess */
105 auto frame = time.frames_round(_content->video_frame_rate().get_value_or(24));
106 eyes = (frame % 2) ? Eyes::RIGHT : Eyes::LEFT;
108 Data(ContentVideo(image, time, eyes, Part::WHOLE));
109 _last_emitted_eyes = eyes;
112 case VideoFrameType::THREE_D_LEFT_RIGHT:
113 Data(ContentVideo(image, time, Eyes::LEFT, Part::LEFT_HALF));
114 Data(ContentVideo(image, time, Eyes::RIGHT, Part::RIGHT_HALF));
116 case VideoFrameType::THREE_D_TOP_BOTTOM:
117 Data(ContentVideo(image, time, Eyes::LEFT, Part::TOP_HALF));
118 Data(ContentVideo(image, time, Eyes::RIGHT, Part::BOTTOM_HALF));
120 case VideoFrameType::THREE_D_LEFT:
121 Data(ContentVideo(image, time, Eyes::LEFT, Part::WHOLE));
123 case VideoFrameType::THREE_D_RIGHT:
124 Data(ContentVideo(image, time, Eyes::RIGHT, Part::WHOLE));
127 DCPOMATIC_ASSERT (false);
135 VideoDecoder::seek ()
137 _position = boost::none;
138 _last_emitted_eyes.reset ();
139 _frame_interval_checker.reset (new FrameIntervalChecker());