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>
25 using boost::shared_ptr;
27 /** @param audio_sample_rate Audio sampling rate, or 0 if there is no audio */
33 int audio_sample_rate,
34 float frames_per_second,
35 int dcp_frames_per_second
37 : AudioVideoProcessor (log)
38 , _video_start (video_trim_start)
39 , _video_end (video_length - video_trim_end)
43 FrameRateConversion frc (frames_per_second, dcp_frames_per_second);
48 } else if (frc.repeat) {
53 if (audio_sample_rate) {
54 _audio_start = video_frames_to_audio_frames (_video_start, audio_sample_rate, frames_per_second);
55 _audio_end = video_frames_to_audio_frames (_video_end, audio_sample_rate, frames_per_second);
58 /* XXX: this is a hack; this flag means that no trim is happening at the end of the film, and I'm
59 using that to prevent audio trim being rounded to video trim, which breaks the current set
60 of regression tests. This could be removed if a) the regression tests are regenerated and b)
61 I can work out what DCP length should be.
63 _no_trim = (_video_start == 0) && (_video_end == (video_length - video_trim_end));
67 Trimmer::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub)
69 if (_no_trim || (_video_in >= _video_start && _video_in <= _video_end)) {
70 Video (image, same, sub);
77 Trimmer::process_audio (shared_ptr<const AudioBuffers> audio)
84 int64_t offset = _audio_start - _audio_in;
85 if (offset > audio->frames()) {
86 _audio_in += audio->frames ();
94 int64_t length = _audio_end - max (_audio_in, _audio_start);
96 _audio_in += audio->frames ();
100 if (length > (audio->frames() - offset)) {
101 length = audio->frames () - offset;
104 _audio_in += audio->frames ();
106 if (offset != 0 || length != audio->frames ()) {
107 shared_ptr<AudioBuffers> copy (new AudioBuffers (audio));
108 copy->move (offset, 0, length);
109 copy->set_frames (length);