2 Copyright (C) 2013 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.
20 #include <boost/shared_ptr.hpp>
26 using boost::shared_ptr;
28 /** @param audio_sample_rate Audio sampling rate, or 0 if there is no audio */
34 int audio_sample_rate,
35 float frames_per_second,
36 int dcp_frames_per_second
38 : AudioVideoProcessor (log)
39 , _video_start (video_trim_start)
40 , _video_end (video_length - video_trim_end)
44 FrameRateConversion frc (frames_per_second, dcp_frames_per_second);
49 } else if (frc.repeat) {
54 if (audio_sample_rate) {
55 _audio_start = video_frames_to_audio_frames (_video_start, audio_sample_rate, frames_per_second);
56 _audio_end = video_frames_to_audio_frames (_video_end, audio_sample_rate, frames_per_second);
59 /* XXX: this is a hack; if there is no trim at the end, set
60 the audio end point to infinity so that
61 shorter-video-than-audio does not trim audio (which breaks
62 the current set of regression tests). This could be
63 removed if a) the regression tests are regenerated and b) I
64 can work out what DCP length should be.
66 if (video_trim_end == 0) {
67 _audio_end = INT64_MAX;
72 Trimmer::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub)
74 if (_video_in >= _video_start && _video_in < _video_end) {
75 Video (image, same, sub);
82 Trimmer::process_audio (shared_ptr<const AudioBuffers> audio)
84 int64_t offset = _audio_start - _audio_in;
85 if (offset > audio->frames()) {
86 /* we haven't reached the start of the untrimmed section yet */
87 _audio_in += audio->frames ();
95 int64_t length = _audio_end - max (_audio_in, _audio_start);
97 _audio_in += audio->frames ();
101 if (length > (audio->frames() - offset)) {
102 length = audio->frames () - offset;
105 _audio_in += audio->frames ();
107 if (offset != 0 || length != audio->frames ()) {
108 shared_ptr<AudioBuffers> copy (new AudioBuffers (audio));
109 copy->move (offset, 0, length);
110 copy->set_frames (length);