From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 051204B07B for ; Mon, 27 May 2024 13:46:58 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4192968D4BC; Mon, 27 May 2024 16:46:56 +0300 (EEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A292968D3C0 for ; Mon, 27 May 2024 16:46:49 +0300 (EEST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f4a0050b9aso6745965ad.2 for ; Mon, 27 May 2024 06:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716817607; x=1717422407; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=+X9y9GaFwxKXRaSleMZ8U14lTn4XgfB0rSZBlJtQ7eg=; b=nGEsCBEfiw0ciFGLqnhEfB9XNhP78+3hOg92W1/xz36oNaSXcSyY14SnbNzd5XFe5q ay3+cZPTy6wSrsbzXPvA1bX+HLyu5fjgVbP/Yfp05qpbyBxxqk3bcahKufCKXATlWLOr 8SakRAL700Mi3qnujps5BAD88KzI+YyQD6hZlGN/m1nUb2PJum4nVz4HCP+wjRFfH0BI NxIuPGRaM3ArIRk9SjnwUMq9JnZPHJHAQ3jFlJUln7e4aE/NsRWZM6HvvDJoJvL+xZ6j ffeVfwDVEA+adV+aNe3cG/A7OcS0GYTEWsiz79koeTtQG5x3J0z529vYNlJsu2Mj/x7V yRoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716817607; x=1717422407; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+X9y9GaFwxKXRaSleMZ8U14lTn4XgfB0rSZBlJtQ7eg=; b=Nn41IGttU9BcAKgSiJbtmIKIXFwmrP3evEDIFNU7KtUoXn0ImZtlJ8RVh/CPCo+NXl ql4+F7ZL5mNslrf/GtVMBI/grdEVifHrwCbg2gimN6rQrRhrrAIDmr4wTvZNtj15RWaV 4L6k9Mh6f1Re/441OBQPbu0Kz4fBDxK/6L9DDvKJmypAh7jd+qg0A8mdfVgztK5p2AND Lt+0HFb4Wgvmj+ohdHxl4tHj80gUev6sThU8Qj1KjlbtfvgzsGazoUna054J2gyhQ6lB xpKPbp/lVpfl625SKS0MvwcQAFtqF6WDVuXZ7b8GycKPi6bpIF8yPRM0+A4DgOgSPTlc iKRg== X-Gm-Message-State: AOJu0YywFwMTSNzzA5quzI6kQs4uyv9VDr0TGcm/7ueS0YqefxVB7z5B RYgbHcDeB8jSM1RE+KqoZ0QRfMpMW/vQXzPXNHeV00eq15vdvmL7oalBJg== X-Google-Smtp-Source: AGHT+IFLCAt0dAskJ7KVY71Z0tbtzsOlNs1nCHE50cyzH9kMKdIsn6/lcDMd77bvkwzHgjgQu74p+g== X-Received: by 2002:a17:902:d2d1:b0:1f4:8ba4:a068 with SMTP id d9443c01a7336-1f48ba4a825mr33889985ad.35.1716817607164; Mon, 27 May 2024 06:46:47 -0700 (PDT) Received: from localhost ([103.208.20.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c757845sm61131385ad.5.2024.05.27.06.46.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 May 2024 06:46:46 -0700 (PDT) Message-Id: To: From: "llyyr" Date: Mon, 27 May 2024 18:52:31 +0530 Subject: [FFmpeg-devel] [PATCH] avformat/mpegts: correctly skip TP_extra_header in m2ts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: instead of just resyncing and skipping a bunch of TS packets, leading to a loss of frames. Before this, a stray byte with the value of 0x47 in TP_extra_header would throw off the detection of where TS packets start. A typical file that could cause issues would look like this: 00000300: 238f 4780 4750 1110 0000 01e0 0000 84c0 ^^ ^^ The first four bytes here are TP_extra_header and the actual TS packet starts at offset 0x304 FFmpeg would try to read a packet at 0x300 but since nothing skips the 4 byte TP_extra_header, find that the first byte is not 0x47 and immediately go into mpegts_resync, and incorrectly detect the stray 0x47 in the TP_extra_header at 0x302 as the new sync byte. Fix this by correctly skipping the first 4 bytes if the source packet is 192 bytes. Signed-off-by: llyyr --- libavformat/mpegts.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index c66a1ea6ede0..0d80ad80f1aa 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2944,6 +2944,12 @@ static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, AVIOContext *pb = s->pb; int len; + // 192 bytes source packet that start with a 4 bytes TP_extra_header + // followed by 188 bytes of TS packet. The sync byte is at offset 4, so skip + // the first 4 bytes otherwise we'll end up syncing to the wrong packet. + if (raw_packet_size == TS_DVHS_PACKET_SIZE) + avio_skip(pb, 4); + for (;;) { len = ffio_read_indirect(pb, buf, TS_PACKET_SIZE, data); if (len != TS_PACKET_SIZE) @@ -2966,7 +2972,11 @@ static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, static void finished_reading_packet(AVFormatContext *s, int raw_packet_size) { AVIOContext *pb = s->pb; - int skip = raw_packet_size - TS_PACKET_SIZE; + int skip; + if (raw_packet_size == TS_DVHS_PACKET_SIZE) + skip = raw_packet_size - TS_DVHS_PACKET_SIZE; + else + skip = raw_packet_size - TS_PACKET_SIZE; if (skip > 0) avio_skip(pb, skip); } base-commit: e9197db4f7227a341b781c227a0a8f3a99033b5e -- 2.45.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".