Skip to content

Embedded subtitles out of sync in time-cropped video #16422

Open
@forthrin

Description

@forthrin

mpv Information

mpv   : git-2025-06-06-v0.40.0-dev-g6b178e4f5
FFmpeg: git 2025-06-05 18:24:07 17729aa8
System: macOS 15.5 (24F74)
Model : MacBookAir10,1

Sample Files

xy.zip

Reproduction Steps

#!/bin/bash

mpv --config=no --sub-auto=no /tmp/x.m4v # RIGHT
mpv --config=no --sub-auto=no /tmp/y.m4v # WRONG: shows subtitle for 10s at 8s
open -a 'QuickTime Player' /tmp/y.m4v # RIGHT

Expected Behavior

Subtitles in sync

Actual Behavior

Subtitles out of sync

Image

(Blocky screenshot of subtitle might be a separate issue with Retina displays.)

Log File

Issue might be related to keyframes.

#!/usr/bin/env ruby

%w[x y].each do |f|
  base = { 'video' => 16_384, 'subtitle' => 1_000_000 }
  info = base.transform_values { [] }
  `ffprobe -v error -show_entries packet=codec_type,pts,flags -of csv /tmp/#{f}.m4v | grep K`.lines(chomp: true).each do |item|
    _, type, pts = item.split(',')
    info[type] << (pts.to_f / base[type])
  end
  pp info
end
{"video" => [0.0, 10.0], "subtitle" => [0.0, 5.0, 10.0]}
{"video" => [0.0, 7.0], "subtitle" => [-5.0, 0.0, 5.0]}

Other Information

To create variants with different timings for debugging/testing:

#!/usr/bin/env ruby

def ts(sec)
  ms = sec * 1000
  format '%02d:%02d:%02d,%03d', *([1000, 60, 60, 100].map { |f| ms.tap { ms /= f } % f }).reverse
end

(0..15).step(5).each_cons(2).with_index do |(a, b), i|
  printf "%s\n%s --> %s\n%s / %s\n\n", i + 1, ts(a), ts(b), ts(a), a
end
#!/bin/bash

for t in $(seq 0 12); do
  magick null: -background '#8c8' -extent 320x240 -pointsize 40 -gravity center -annotate +0+0 "$t" "/tmp/$t.png"
done

ffmpeg -r 1 -i /tmp/%d.png -i /tmp/sub.srt -pix_fmt yuv420p -c:s mov_text -y /tmp/x.m4v
ffmpeg -ss 3 -i /tmp/x.m4v -c:s mov_text -y /tmp/y.m4v

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions