Skip to content

Commit

Permalink
common/lwlibav_video.c: fix incorrect seeking in some mkvs, again
Browse files Browse the repository at this point in the history
It turns out not only the first frame could have invalid DTS, there
are mkv files in the wild that contains first few frames with an
invalid DTS. It's beyond me how mkvmerge could have created such a
file given that mkv are supposed to be seeking by DTS.

Next time, if you face such a mkv, you can:
1. mkvextract the video and then remux with mkvmerge to force it to
   recreate cue points for all IDR..
2. add `--cue 0:all` to mkvmerge and remux the broken mkv to fix it.

Fixes #14.

Signed-off-by: akarin <[email protected]>
  • Loading branch information
AkarinVS committed Apr 17, 2023
1 parent dffecae commit d73d2dc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion common/lwlibav_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ static uint32_t correct_current_frame_number
uint32_t goal
)
{
#define MATCH_DTS( j ) (info[j].dts == pkt->dts)
// It's possible that the first few encoded frames all have DTS AV_NOPTS_VALUE, so we really
// shouldn't stop when dts matches: at least we should fallback to checking POS if allowed.
// Also note that `j` might contain side-effects, must always evaluate it exactly once!
#define MATCH_DTS( j ) (info[j].dts == pkt->dts && (pkt->dts != AV_NOPTS_VALUE || ((vdhp->lw_seek_flags & SEEK_POS_CORRECTION) == 0)))
#define MATCH_POS( j ) ((vdhp->lw_seek_flags & SEEK_POS_CORRECTION) && info[j].file_offset == pkt->pos)
order_converter_t *oc = vdhp->order_converter;
video_frame_info_t *info = vdhp->frame_list;
Expand Down

0 comments on commit d73d2dc

Please sign in to comment.