Don't seek before 0 in FFmpegDecoder; fixes errors on seek close to 0.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index b7516f6d2d7a7cb005e08dd617e4b0a7f370146f..4ca06329b116ae9561ddb3c61fa11a17416af9c2 100644 (file)
@@ -137,7 +137,7 @@ FFmpegDecoder::flush ()
 }
 
 bool
-FFmpegDecoder::pass (PassReason reason)
+FFmpegDecoder::pass ()
 {
        int r = av_read_frame (_format_context, &_packet);
 
@@ -160,12 +160,12 @@ FFmpegDecoder::pass (PassReason reason)
        int const si = _packet.stream_index;
        shared_ptr<const FFmpegContent> fc = _ffmpeg_content;
 
-       if (si == _video_stream && !_ignore_video && reason != PASS_REASON_SUBTITLE) {
+       if (si == _video_stream && !_ignore_video) {
                decode_video_packet ();
-       } else if (reason != PASS_REASON_SUBTITLE) {
-               decode_audio_packet ();
        } else if (fc->subtitle_stream() && fc->subtitle_stream()->uses_index (_format_context, si)) {
                decode_subtitle_packet ();
+       } else {
+               decode_audio_packet ();
        }
 
        av_free_packet (&_packet);
@@ -315,8 +315,11 @@ FFmpegDecoder::seek (ContentTime time, bool accurate)
           http://www.mjbshaw.com/2012/04/seeking-in-ffmpeg-know-your-timestamp.html
        */
        
-       ContentTime const u = time - _pts_offset;
-       av_seek_frame (_format_context, _video_stream, u.seconds() / av_q2d (_format_context->streams[_video_stream]->time_base), 0);
+       ContentTime u = time - _pts_offset;
+       if (u < ContentTime ()) {
+               u = ContentTime ();
+       }
+       av_seek_frame (_format_context, _video_stream, u.seconds() / av_q2d (_format_context->streams[_video_stream]->time_base), AVSEEK_FLAG_BACKWARD);
 
        avcodec_flush_buffers (video_codec_context());