fix(verify): AAC 从 TS 换封装到 MP4 不是掉包,别再判 payload differs
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」动作名,不是流的真实编码)。 截断的副本仍然被拒,测试里两条都钉住了。
This commit is contained in:
1 parent
0e5c74e5b5
commit
005b824e4f
1 file changed
+20
-4
+20
-4
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user