Fix subtitle position.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 80c3d9906b48188d2057f34007f632ac4671c9dc..298284512371b87c53ba21edee018434f218d009 100644 (file)
@@ -367,13 +367,19 @@ FFmpegDecoder::seek_final_finished (int n, int done) const
 void
 FFmpegDecoder::seek_and_flush (ContentTime t)
 {
-       int64_t const initial_v = ((double (t) / TIME_HZ) - _video_pts_offset) /
+       int64_t s = ((double (t) / TIME_HZ) - _video_pts_offset) /
                av_q2d (_format_context->streams[_video_stream]->time_base);
        
-       int64_t const initial_a = ((double (t) / TIME_HZ) - _audio_pts_offset) /
-               av_q2d (_ffmpeg_content->audio_stream()->stream(_format_context)->time_base);
+       if (_ffmpeg_content->audio_stream ()) {
+               s = min (
+                       s, int64_t (
+                               ((double (t) / TIME_HZ) - _audio_pts_offset) /
+                               av_q2d (_ffmpeg_content->audio_stream()->stream(_format_context)->time_base)
+                               )
+                       );
+       }
 
-       av_seek_frame (_format_context, _video_stream, min (initial_v, initial_a), AVSEEK_FLAG_BACKWARD);
+       av_seek_frame (_format_context, _video_stream, s, AVSEEK_FLAG_BACKWARD);
 
        avcodec_flush_buffers (video_codec_context());
        if (audio_codec_context ()) {
@@ -556,8 +562,8 @@ FFmpegDecoder::decode_subtitle_packet ()
        double const packet_time = static_cast<double> (sub.pts) / AV_TIME_BASE;
        
        /* hence start time for this sub */
-       DCPTime const from = (packet_time + (double (sub.start_display_time) / 1e3)) * TIME_HZ;
-       DCPTime const to = (packet_time + (double (sub.end_display_time) / 1e3)) * TIME_HZ;
+       ContentTime const from = (packet_time + (double (sub.start_display_time) / 1e3)) * TIME_HZ;
+       ContentTime const to = (packet_time + (double (sub.end_display_time) / 1e3)) * TIME_HZ;
 
        AVSubtitleRect const * rect = sub.rects[0];