From 005b824e4f5d97ccd3d63e8f5ddcc34b2a60b2ca Mon Sep 17 00:00:00 2001 From: hoelee Date: Fri, 30 Oct 2026 02:58:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(verify):=20AAC=20=E4=BB=8E=20TS=20=E6=8D=A2?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=88=B0=20MP4=20=E4=B8=8D=E6=98=AF=E6=8E=89?= =?UTF-8?q?=E5=8C=85=EF=BC=8C=E5=88=AB=E5=86=8D=E5=88=A4=20payload=20diffe?= =?UTF-8?q?rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MPEG-TS 里的 AAC 是 ADTS 帧(每帧 7 字节头),MP4 存同样的帧但不带头、配置进 AudioSpecificConfig。`-f data` 直接把包负载吐出来,于是同一条音轨、同一个包数 (实测 157137 / 157137)却被判 `a 0: payload differs (src .../342d39a4, out .../38f9b7e6)`, 一份好片被记成 infra 失败、退避三次后进 #block-infra。 实测(KODV-0081.ts / 20 s 窗口): raw src=87f3e5b6 out=955905a0 不一致 -> 假阳性 bsf src=955905a0 out=955905a0 一致 pcm src=d86dbbed out=d86dbbed 一致 故两边都过 `-bsf:a aac_adtstoasc`(TS 侧剥 ADTS 头,MP4 侧无操作)。编解码器从 ffprobe 现读(`plan_` 里的 codec 是「copy」动作名,不是流的真实编码)。 截断的副本仍然被拒,测试里两条都钉住了。 --- scripts/tracks.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/tracks.py b/scripts/tracks.py index eb06dab..26db767 100644 --- a/scripts/tracks.py +++ b/scripts/tracks.py @@ -468,19 +468,35 @@ def stream_signature(path, sel, timeout=1800): differs" on streams that were byte-identical (a false failure on a good file is the one outcome this gate must never produce). Cost is one linear read of the stream's payload - ~2 s per 10 min of audio - and no giant JSON in memory like `-show_packets`. + + ONE exception to "container-independent", and it is an ADTS one: an AAC stream in MPEG-TS is + carried as ADTS frames (7-byte header per frame), while MP4 stores the same frames raw with a + single `AudioSpecificConfig`. `-f data` therefore returns different bytes for the SAME audio, + and the gate reported `a 0: payload differs (src 157137 packets/342d39a4, out 157137 + packets/38f9b7e6)` - identical packet counts, one extra header per frame. Measured on + KODV-0081.ts: raw dumps disagree (87f3e5b6 / 955905a0), both sides through + `-bsf:a aac_adtstoasc` agree (955905a0 / 955905a0), and the decoded PCM agrees too. So for + AAC the dump goes through that bitstream filter on BOTH sides - it strips ADTS where it exists + and is a pass-through where it does not. """ + bsf = [] r = subprocess.run([FFPROBE, "-v", "error", "-select_streams", sel, "-count_packets", - "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", path], + "-show_entries", "stream=codec_name,nb_read_packets", "-of", "csv=p=0", path], capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=timeout, creationflags=NOWIN) if r.returncode != 0: return None try: - nb = int((r.stdout or "").strip().splitlines()[0]) + parts = (r.stdout or "").strip().splitlines()[0].split(",") + codec_name, nb = (parts[0].strip(), int(parts[1])) except Exception: # noqa: BLE001 return None - p = subprocess.Popen([FFMPEG, "-v", "error", "-i", path, "-map", "0:" + sel, "-c", "copy", - "-f", "data", "-"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, + # 编解码器从 ffprobe 现读,而不是相信调用方传进来的字符串:`plan_` 里存的 `codec` 是 + # 「copy」这个动作,不是流的真实编码;而这一条 bsf 必须按**真实编码**决定。 + if codec_name.lower() in ("aac", "aac_latm"): + bsf = ["-bsf:a", "aac_adtstoasc"] + p = subprocess.Popen([FFMPEG, "-v", "error", "-i", path, "-map", "0:" + sel, "-c", "copy"] + bsf + + ["-f", "data", "-"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=NOWIN) h = hashlib.md5() try: