Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common/lwlibav_video.c: fix incorrect seek for some mkv files
The issue is that somehow newer mkvmerge generates way less cue points than ffmpeg and older versions of mkvmerge. This makes av_seek_frame much less reliable. For the specific test case mentioned in #14, rap for frame 32 is frame 24, however, the best av_seek_frame can do is just seek to the very beginning of the video track. lsmas does not depend on fully reliable av_seek_frame, however, in this particular cases, because the mkv is using PTS as seeking method, lsmas will not attempt to call correct_current_frame_number to correct for the mis-seek, which means it will assume the current position (frame 0) as actually the rap (frame 24), then it follows that it will return frame 8 as frame 32. To fix this, we must call correct_current_frame_number even for SEEK_PTS_BASED formats. This fixes much of the issues, except for the first few frames. Then there is another issue lurking in correct_current_frame_number: when it finds that the current packet has a dts of AV_NOPTS_VALUE, it will always abort. Unfortunately, as frame 0 typically has such a dts, it will not correct the current frame number when the actual current is frame 0. We fix this by disregarding pkt->dts == AV_NOPTS_VALUE when the seek mode is not just SEEK_DTS_BASED (note that mkv has a seek mode of SEEK_DTS_BASED | SEEK_POS_CORRECTION, which means that we can reliably use the pkt->pos field to determine the current frame.) Fixes #14. Signed-off-by: akarin <[email protected]>
- Loading branch information