Don't seek before 0 in FFmpegDecoder; fixes errors on seek close to 0.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 6f91922eb90e8faa786c3b8758a285277a3f3cc2..4ca06329b116ae9561ddb3c61fa11a17416af9c2 100644 (file)
@@ -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());