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 */
31 int video_trim_end, int video_length,
32 int audio_sample_rate,
33 float frames_per_second,
34 int dcp_frames_per_second
36 : AudioVideoProcessor (log)
37 , _video_start (video_trim_start)
38 , _video_end (video_length - video_trim_end)
42 FrameRateConversion frc (frames_per_second, dcp_frames_per_second);
47 } else if (frc.repeat) {
52 if (audio_sample_rate) {
53 _audio_start = video_frames_to_audio_frames (_video_start, audio_sample_rate, frames_per_second);
54 _audio_end = video_frames_to_audio_frames (_video_end, audio_sample_rate, frames_per_second);
59 Trimmer::process_video (shared_ptr<Image> image, bool same, shared_ptr<Subtitle> sub)
61 if (_video_in >= _video_start && _video_in <= _video_end) {
62 Video (image, same, sub);
69 Trimmer::process_audio (shared_ptr<AudioBuffers> audio)
71 int64_t offset = _audio_start - _audio_in;
72 if (offset > audio->frames()) {
73 _audio_in += audio->frames ();
81 int64_t length = _audio_end - max (_audio_in, _audio_start);
83 _audio_in += audio->frames ();
87 if (length > (audio->frames() - offset)) {
88 length = audio->frames () - offset;
91 _audio_in += audio->frames ();
93 if (offset != 0 || length != audio->frames ()) {
94 audio->move (offset, 0, length);
95 audio->set_frames (length);