Mkvmerge drops frames on certain m2ts files at the start

Hello,

I think I have found a bug in mkvtoolnix’s m2ts parsing.
If a bluray m2ts stream starts with a timecode that contains 0x47 it will resync to that instead of the real sync byte.
This results in output files missing a few frames at the start, till it resync with the proper one again.
ffmpeg also shows this behavior but tsmuxer or DumpTS and (makemkv) can output files that have the entire video intact.

I have created this patch which seems to fix my issue:

I am of the Impression that i have identified the bug correctly and you can follow without a sample file. Due to the nature of the source i would not like to provide a sample, but am open to it if my fix or bug report does not make sense.

I did not use gitlab because i don’t want to verify phone number just for one bug report.

latest ffmpeg(4,5,6), mkvmerge v79.0 (‘Funeral Pyres’) 64-bit and mkvmerge-git were used.

Thanks
jsaowji

relevant part of log.

Debug> src/input/r_mpeg_ts.cpp:2538: resync: Start resync for data from 0
Debug> src/input/r_mpeg_ts.cpp:2558: resync: Re-established at 1
Debug> src/input/r_mpeg_ts.cpp:2538: resync: Start resync for data from 4993
Debug> src/input/r_mpeg_ts.cpp:2558: resync: Re-established at 4996

relevant packets

     transport_packet#0

             00  01  02  03  04  05  06  07    08  09  0A  0B  0C  0D  0E  0F
             ----------------------------------------------------------------
     000000  26  47  AC  28  47  40  00  10    00  00  B0  11  00  00  C1  00 | &G.(G@..........
     000010  00  00  00  E0  1F  00  01  E1    00  23  5A  AB  82  FF  FF  FF | .........#Z.....
     000020  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000030  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000040  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000050  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000060  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000070  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000080  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000090  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000A0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000B0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................

     transport_packet#25
             00  01  02  03  04  05  06  07    08  09  0A  0B  0C  0D  0E  0F
             ----------------------------------------------------------------
     000000  26  47  FE  C6  47  10  11  15    FF  FF  FF  FF  FF  FF  FF  FF | &G..G...........
     000010  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000020  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000030  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000040  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000050  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000060  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000070  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000080  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000090  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000A0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000B0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
    
    transport_packet#26
             00  01  02  03  04  05  06  07    08  09  0A  0B  0C  0D  0E  0F
             ----------------------------------------------------------------
     000000  26  48  02  14  47  10  11  16    FF  FF  FF  FF  FF  FF  FF  FF | &H..G...........
     000010  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000020  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000030  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000040  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000050  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000060  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000070  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000080  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     000090  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000A0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................
     0000B0  FF  FF  FF  FF  FF  FF  FF  FF    FF  FF  FF  FF  FF  FF  FF  FF | ................

Thanks. Please open an issue for it over on GitLab. Otherwise chances are I’ll forget about it again.