From: Carl Hetherington Date: Sun, 4 Nov 2012 20:33:43 +0000 (+0000) Subject: Various range fixes. X-Git-Tag: v2.0.48~1571 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=555b4068ff0e1726519d720b055a9faaca01a1a1 Various range fixes. --- diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 1f93c6c60..5860f339e 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -232,30 +232,32 @@ Decoder::process_audio (uint8_t* data, int size) _delay_line->feed (audio); - /* Decode range in audio frames */ - pair required_range ( - video_frames_to_audio_frames (_film->dcp_trim_start()), - video_frames_to_audio_frames (_film->dcp_trim_start() + _film->dcp_length().get()) - ); - - /* Range of this block of data */ - pair this_range ( - _audio_frames_in, - _audio_frames_in + audio->frames() - ); - - /* Trim start */ - if (required_range.first >= this_range.first && required_range.first < this_range.second) { - int64_t const shift = this_range.first - required_range.first; - audio->move (shift, 0, audio->frames() - shift); - audio->set_frames (audio->frames() - shift); - } - - /* Trim end */ - if (required_range.second >= this_range.first && required_range.second < this_range.second) { - audio->set_frames (this_range.first - required_range.second); + if (_opt->decode_range) { + /* Decode range in audio frames */ + pair required_range ( + video_frames_to_audio_frames (_opt->decode_range.get().first), + video_frames_to_audio_frames (_opt->decode_range.get().second) + ); + + /* Range of this block of data */ + pair this_range ( + _audio_frames_in, + _audio_frames_in + audio->frames() + ); + + /* Trim start */ + if (required_range.first >= this_range.first && required_range.first < this_range.second) { + int64_t const shift = this_range.first - required_range.first; + audio->move (shift, 0, audio->frames() - shift); + audio->set_frames (audio->frames() - shift); + } + + /* Trim end */ + if (required_range.second >= this_range.first && required_range.second < this_range.second) { + audio->set_frames (this_range.first - required_range.second); + } } - + if (audio->frames()) { emit_audio (audio); } @@ -275,23 +277,22 @@ Decoder::emit_audio (shared_ptr audio) void Decoder::process_video (AVFrame* frame) { - assert (_film->length()); - if (_minimal) { ++_video_frames_in; return; } - /* Use Film::length here as our one may be wrong */ - if (_opt->decode_video_skip != 0 && (_video_frames_in % _opt->decode_video_skip) != 0) { ++_video_frames_in; return; } - if (_video_frames_in < _film->dcp_trim_start() || _video_frames_in > (_film->dcp_trim_start() + _film->length().get())) { - ++_video_frames_in; - return; + if (_opt->decode_range) { + pair r = _opt->decode_range.get(); + if (_video_frames_in < r.first || _video_frames_in >= r.second) { + ++_video_frames_in; + return; + } } shared_ptr graph; diff --git a/src/lib/film.cc b/src/lib/film.cc index cacd30764..26edc80b0 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -63,6 +63,7 @@ using std::ifstream; using std::ofstream; using std::setfill; using std::min; +using std::make_pair; using boost::shared_ptr; using boost::lexical_cast; using boost::to_upper_copy; @@ -257,6 +258,9 @@ Film::make_dcp (bool transcode) o->out_size = format()->dcp_size (); o->padding = format()->dcp_padding (shared_from_this ()); o->ratio = format()->ratio_as_float (shared_from_this ()); + if (dcp_length ()) { + o->decode_range = make_pair (dcp_trim_start(), dcp_trim_start() + dcp_length().get()); + } o->decode_subtitles = with_subtitles (); o->decode_video_skip = dcp_frame_rate (frames_per_second()).skip; diff --git a/src/lib/options.h b/src/lib/options.h index 043e3692f..68786c730 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -96,6 +96,10 @@ public: float ratio; ///< ratio of the wanted output image (not considering padding) int padding; ///< number of pixels of padding (in terms of the output size) each side of the image bool apply_crop; ///< true to apply cropping + + /** Range of video frames to decode */ + boost::optional > decode_range; + /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g. * 1 for every frame, 2 for every other frame, etc. */