[FFmpeg-devel] [PATCH] avformat/mpegts: fix resync logic stuck in 192 bytes

Michael Niedermayer michael at niedermayer.cc
Wed May 20 15:39:32 EEST 2020


On Tue, May 19, 2020 at 09:06:59PM +0200, Marton Balint wrote:
> pos47_full is not updated for every packet, and for unseekable inputs the
> resync logic might simply skip some 0x47 sync bytes. In order to detect these
> let's check for modulo instead of exact value.
> 
> Also skip unrecognized sync byte distances instead of considering them as a
> failure of detection. It only delays the detection of the new packet size.
> 
> Also note that AVIO only buffers a single packet (for UDP/mpegts, that usually
> means 1316 bytes), so among every ten consecutive 188-byte MPEGTS packets there
> will always be a seek failure, and that caused the old code to not find the 188
> byte pattern across 10 consecutive packets.
> 
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavformat/mpegts.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index a065c61c40..f2b2c05d86 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -2846,12 +2846,14 @@ static void reanalyze(MpegTSContext *ts) {
>      if (pos < 0)
>          return;
>      pos -= ts->pos47_full;
> -    if (pos == TS_PACKET_SIZE) {
> +    if (pos % TS_PACKET_SIZE == 0) {
>          ts->size_stat[0] ++;
> -    } else if (pos == TS_DVHS_PACKET_SIZE) {
> +    } if (pos % TS_DVHS_PACKET_SIZE == 0) {
>          ts->size_stat[1] ++;
> -    } else if (pos == TS_FEC_PACKET_SIZE) {
> +    } if (pos % TS_FEC_PACKET_SIZE == 0) {
>          ts->size_stat[2] ++;
> +    } else {
> +        return;
>      }

This patch breaks, or at least changes

./ffmpeg -i tspacket_size_changeback.ts  -vframes 2 -qscale 2 test.avi

ill mail you the file privatly as i dont remember from where this is
and google fails to find any public copy

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200520/e874b3de/attachment.sig>


More information about the ffmpeg-devel mailing list