Various range fixes.
authorCarl Hetherington <cth@carlh.net>
Sun, 4 Nov 2012 20:33:43 +0000 (20:33 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Nov 2012 20:33:43 +0000 (20:33 +0000)
src/lib/decoder.cc
src/lib/film.cc
src/lib/options.h

index 1f93c6c609ed9d9cdecdbbb6e8ec4e8a47e4580f..5860f339ef650a6090b51e03c23e9d57e9974791 100644 (file)
@@ -232,30 +232,32 @@ Decoder::process_audio (uint8_t* data, int size)
 
        _delay_line->feed (audio);
 
-       /* Decode range in audio frames */
-       pair<int64_t, int64_t> 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<int64_t, int64_t> 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<int64_t, int64_t> 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<int64_t, int64_t> 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<AudioBuffers> 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<SourceFrame, SourceFrame> r = _opt->decode_range.get();
+               if (_video_frames_in < r.first || _video_frames_in >= r.second) {
+                       ++_video_frames_in;
+                       return;
+               }
        }
 
        shared_ptr<FilterGraph> graph;
index cacd307643363657b180ef348c0b37bc9a7b0682..26edc80b07a00bbd38d3d83af825cb56a88ebf38 100644 (file)
@@ -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;
 
index 043e3692f476ee1e23d711a91be753cf29e51798..68786c730cdd4b116f85ceb5f06534506ea5f5bb 100644 (file)
@@ -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<std::pair<SourceFrame, SourceFrame> > 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.
         */