AkarinVS / L-SMASH-Works

Works based on L-SMASH project; This repo focuses on the common portion and the VapourSynth plugin. AviSynth users please use https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works. ffmpeg 5.0+ please use ffmpeg-4.5 branch.
47 stars 11 forks source link

incorrect seek for mkv lacking complete cuepoints for all IDR frames #14

Closed AkarinVS closed 1 year ago

AkarinVS commented 2 years ago

lsmas fails the seek test miserably for some mkvs muxed by mkvmerge v51. For one certain mkv, seeking to frame 32 will consistently return frame 8.

initial investigation showed that simply remux with ffmpeg -i input.mkv -c copy out.mkv would fix the issue. ffms2 2.40 built with the same ffmpeg revision does not exhibit this issue.

Update: turns out it's because newer mkvmerge no longer generate a cuepoint for each IDR frame. Not sure why this change is made as it should affect players seeking mkv video as well.

Update 2: turns out it's not a regression introduced by mkvmerge v51. When remuxing mp4 to mkv, it seems mkvmerge will not recreate the cuepoints by parsing the video track, so if the input mp4 somehow does not contain full cuepoints, the mkv will exhibit the issue.

AkarinVS commented 1 year ago

Found another reproducer. nyaa 1660840, frame 72. (seek-test fails for just a remux first 72 frames. mkvmerge --cue 0:all remux fixes the issue).

frame 72 is actually an IDR, but it's not one of the mkv's cue points, so ffmpeg will seek to frame 0.

Index=0,POS=5583,PTS=0,DTS=-9223372036854775808,EDI=0
Key=1,Pic=1,POC=0,Repeat=1,Field=0
Index=0,POS=108034,PTS=83,DTS=-9223372036854775808,EDI=0
Key=0,Pic=2,POC=4,Repeat=1,Field=0

Unfortunately, the first two frames both have DTS AV_NOPTS_VALUE, so it confuses correct_current_frame_number and made it think ffmpeg has sought to the 2nd encoded frame, which is clearly impossible (not even I frame).