# HG changeset patch # User michael # Date 1208985385 0 # Node ID 78153a85dcccba50a4813db603506c1fe55780dd # Parent 319a613c1dd79dc80b806a0e2d6a61c6468dd04c Ensure that the timestamp reading code used for seeking chooses a position which is a multiple of the packet size from the last packet start instead of the file start. This fixes some seek issues with randomly cut ts files and the mysterious "4 byte PCR somehing MTS something bug". diff -r 319a613c1dd7 -r 78153a85dccc mpegts.c --- a/mpegts.c Tue Apr 22 20:08:39 2008 +0000 +++ b/mpegts.c Wed Apr 23 21:16:25 2008 +0000 @@ -90,6 +90,9 @@ AVFormatContext *stream; /** raw packet size, including FEC if present */ int raw_packet_size; + + int pos47; + /** if true, all pids are analyzed to find streams */ int auto_guess; @@ -1046,6 +1049,8 @@ if (p >= p_end) return; + ts->pos47= url_ftell(ts->stream->pb) % ts->raw_packet_size; + if (tss->type == MPEGTS_SECTION) { if (is_start) { /* pointer field present */ @@ -1379,7 +1384,7 @@ uint8_t buf[TS_PACKET_SIZE]; int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid; const int find_next= 1; - pos = ((*ppos + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size; + pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; if (find_next) { for(;;) { url_fseek(s->pb, pos, SEEK_SET);