mpegts.js icon indicating copy to clipboard operation
mpegts.js copied to clipboard

sync_byte error freezes demuxer

Open dbussert opened this issue 3 years ago • 4 comments

If the demuxer hits a sync_byte that is not 0x47 it will freeze the video and be unable to progress demuxing the next packets. This is what's seen in chrome dev console. The MPEG-TS source is doing some weird stuff to the stream, padding/fragmenting the UDP payload to not be exactly a multiple of 188 bytes.

image

In a scenario where this.first_parse_ is false, then offset is 0 but this code will break and return a 0 offset, and the demuxer will be stuck trying to read the sync_byte that is not 0x47 infinitely.

if (sync_byte !== 0x47) {
                Log.e(this.TAG, `sync_byte = ${sync_byte}, not 0x47`);
                break;
            }

dbussert avatar Mar 03 '22 22:03 dbussert

I had the same issue using FFmpeg and sending via UDP to my server, try to add pkt_size=1316 at the end of the url

udp://[adress]:[port]?pkt_size=1316

Itrasis avatar Jun 15 '22 08:06 Itrasis

I ran to a similar issue while transporting mpegts over websocket protocol. It seems that sometimes the data packets get lost and then the sync byte is no longer where it should be, but the mpegts.js seems to have a convenience function on ts demuxer class to find it: probe function. You could try to use it in similar fashion as I did to confirm where the correct sync byte is on the received chunk. This seemed to handle my issues related to sync bytes.

Näyttökuva 2023-07-21 152246

yaruno avatar Jul 21 '23 13:07 yaruno