|
|
@@ -0,0 +1,523 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""analyze_output.py —— 原版工具产出视频的自动取证报告
|
|
|
+
|
|
|
+用法(用户视角,跑完原版 AB 合成后把产物拖进来):
|
|
|
+ python -X utf8 analyze_output.py "产物视频.mp4"
|
|
|
+ python -X utf8 analyze_output.py "产物.mp4" --ref "素材.mp4" --ref "实拍.mp4" --cover "封面.jpg"
|
|
|
+ python -X utf8 analyze_output.py "产物.mp4" --report "报告.txt" --frames 900 --step 2
|
|
|
+
|
|
|
+自动输出:
|
|
|
+ 1. 容器/流全参数(ffprobe format+streams JSON 摘要)
|
|
|
+ 2. 帧率与帧结构:标称/平均帧率、90fps 检测、时间戳重复/丢弃、逐帧时间差分布、
|
|
|
+ 重复帧(视觉相同)检测 —— 用于识别 fps 重采样、interleave 双流、
|
|
|
+ 每帧时长翻倍(双帧包)等模式
|
|
|
+ 3. 场序:流级 field_order + 逐帧 interlaced_frame/top_field_first 标记
|
|
|
+ 4. 逐行奇偶模式检测:对解码帧计算 相邻行差d1 vs 隔行差d2 的梳状比、
|
|
|
+ 行差奇偶不对称度、行均值信号 Nyquist 能量 —— 判定是否存在 A/B 两路
|
|
|
+ 按行奇偶混合(blend all_expr=if(eq(mod(Y,2),...)) 的指纹)
|
|
|
+ 5. 首帧来源比对:与 --ref(视频/图片,可多个)的首帧/封面比对 MSE/PSNR
|
|
|
+ 6. 音频:编解码/采样率/声道/时长;与 --ref 视频时长比 → 变速痕迹
|
|
|
+ 7. 元数据残留:format/stream 全部 tag,以及文件头尾 64KB 的可疑字符串扫描
|
|
|
+ (encoder 伪造 / handler_name 伪装 / creation_time 等)
|
|
|
+
|
|
|
+依赖:ffmpeg + ffprobe 在 PATH;numpy(仅帧解码分析需要,缺失时自动降级跳过 2/4 的解码部分)。
|
|
|
+"""
|
|
|
+import argparse
|
|
|
+import io
|
|
|
+import json
|
|
|
+import os
|
|
|
+import re
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
+
|
|
|
+try:
|
|
|
+ sys.stdout.reconfigure(encoding="utf-8")
|
|
|
+except Exception:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 基础工具
|
|
|
+
|
|
|
+def sh(args, timeout=120):
|
|
|
+ p = subprocess.run(args, capture_output=True, timeout=timeout)
|
|
|
+ return p.stdout, p.stderr, p.returncode
|
|
|
+
|
|
|
+
|
|
|
+def ffprobe_json(path, extra=None, timeout=60):
|
|
|
+ cmd = ["ffprobe", "-v", "error", "-print_format", "json"] + (extra or []) + [path]
|
|
|
+ out, err, rc = sh(cmd, timeout)
|
|
|
+ if rc != 0:
|
|
|
+ raise RuntimeError("ffprobe 失败: %s" % err.decode("utf-8", errors="replace")[:500])
|
|
|
+ return json.loads(out.decode("utf-8", errors="replace"))
|
|
|
+
|
|
|
+
|
|
|
+def human_bytes(n):
|
|
|
+ try:
|
|
|
+ n = float(n)
|
|
|
+ except (TypeError, ValueError):
|
|
|
+ return "?"
|
|
|
+ for unit in ["B", "KB", "MB", "GB"]:
|
|
|
+ if n < 1024:
|
|
|
+ return "%.1f%s" % (n, unit)
|
|
|
+ n /= 1024.0
|
|
|
+ return "%.1fTB" % n
|
|
|
+
|
|
|
+
|
|
|
+def ratio_str(fr):
|
|
|
+ """'30000/1001' -> (分子, 分母)"""
|
|
|
+ try:
|
|
|
+ if "/" in fr:
|
|
|
+ a, b = fr.split("/")
|
|
|
+ return int(a), int(b)
|
|
|
+ return int(fr), 1
|
|
|
+ except Exception:
|
|
|
+ return None, None
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 第1节:容器/流
|
|
|
+
|
|
|
+def section_container(path):
|
|
|
+ data = ffprobe_json(path, ["-show_format", "-show_streams"])
|
|
|
+ fmt = data.get("format", {})
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("1) 容器与流")
|
|
|
+ print("=" * 72)
|
|
|
+ print("文件 : %s (%s)" % (path, human_bytes(os.path.getsize(path))))
|
|
|
+ print("容器 : %s / %s" % (fmt.get("format_name"), fmt.get("format_long_name")))
|
|
|
+ print("总时长 : %s s" % fmt.get("duration"))
|
|
|
+ print("总码率 : %s bps" % fmt.get("bit_rate"))
|
|
|
+ print("流数量 : %s" % fmt.get("nb_streams"))
|
|
|
+ for s in data.get("streams", []):
|
|
|
+ idx = s.get("index")
|
|
|
+ if s.get("codec_type") == "video":
|
|
|
+ fr_num, fr_den = ratio_str(s.get("r_frame_rate", "0/1"))
|
|
|
+ af_num, af_den = ratio_str(s.get("avg_frame_rate", "0/1"))
|
|
|
+ print(" [流 %s] 视频 %s(%s) %sx%s SAR=%s 像素格式=%s" % (
|
|
|
+ idx, s.get("codec_name"), s.get("profile"),
|
|
|
+ s.get("width"), s.get("height"), s.get("sample_aspect_ratio"),
|
|
|
+ s.get("pix_fmt")))
|
|
|
+ print(" r_frame_rate=%s(%.4f) avg_frame_rate=%s(%.4f) 帧数=%s tbr=%s" % (
|
|
|
+ s.get("r_frame_rate"), (fr_num / fr_den if fr_den else 0),
|
|
|
+ s.get("avg_frame_rate"), (af_num / af_den if af_den else 0),
|
|
|
+ s.get("nb_frames"), s.get("time_base")))
|
|
|
+ print(" 场序 field_order=%s | 色彩空间=%s/%s | bit_depth=%s" % (
|
|
|
+ s.get("field_order", "(未标记)"), s.get("color_space"),
|
|
|
+ s.get("color_transfer"), s.get("bits_per_raw_channel")))
|
|
|
+ elif s.get("codec_type") == "audio":
|
|
|
+ print(" [流 %s] 音频 %s 采样率=%sHz 声道=%s(%s) 码率=%s 时长=%ss" % (
|
|
|
+ idx, s.get("codec_name"), s.get("sample_rate"), s.get("channels"),
|
|
|
+ s.get("channel_layout"), s.get("bit_rate"), s.get("duration")))
|
|
|
+ else:
|
|
|
+ print(" [流 %s] %s %s" % (idx, s.get("codec_type"), s.get("codec_name")))
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 第2/3节:帧结构
|
|
|
+
|
|
|
+def section_frames(path, max_frames=600):
|
|
|
+ """帧时间戳/场标记分析 + 视觉重复帧检测。"""
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("2) 帧率与帧结构(前 %d 帧)" % max_frames)
|
|
|
+ print("=" * 72)
|
|
|
+ try:
|
|
|
+ frames = ffprobe_json(path, [
|
|
|
+ "-select_streams", "v:0", "-show_frames", "-show_entries",
|
|
|
+ "frame=pts_time,pkt_duration_time,pict_type,interlaced_frame,top_field_first,repeat_pict",
|
|
|
+ "-read_intervals", "%%+#%d" % max_frames,
|
|
|
+ ], timeout=180).get("frames", [])
|
|
|
+ except Exception as e:
|
|
|
+ print(" [!] 帧级探测失败,跳过: %s" % e)
|
|
|
+ return None
|
|
|
+ if not frames:
|
|
|
+ print(" [!] 无帧数据(容器可能无视频流或损坏)")
|
|
|
+ return None
|
|
|
+
|
|
|
+ pts = [float(f.get("pts_time", 0) or 0) for f in frames]
|
|
|
+ durs = [float(f.get("pkt_duration_time", 0) or 0) for f in frames]
|
|
|
+ deltas = [round(b - a, 6) for a, b in zip(pts, pts[1:]) if b >= a]
|
|
|
+ dup_ts = sum(1 for a, b in zip(pts, pts[1:]) if abs(b - a) < 1e-6)
|
|
|
+ interlaced = [f for f in frames if str(f.get("interlaced_frame")) == "1"]
|
|
|
+ tff_vals = set(str(f.get("top_field_first")) for f in interlaced)
|
|
|
+
|
|
|
+ span = pts[-1] - pts[0] if len(pts) > 1 else 0
|
|
|
+ eff_fps = (len(pts) - 1) / span if span > 0 else 0
|
|
|
+ print(" 帧数=%d 时间跨度=%.3fs 有效帧率(时间戳推算)=%.4f fps" % (len(pts), span, eff_fps))
|
|
|
+ if deltas:
|
|
|
+ from collections import Counter
|
|
|
+ dc = Counter(deltas)
|
|
|
+ top = dc.most_common(5)
|
|
|
+ print(" 帧间隔分布(前5种): %s" % ", ".join(
|
|
|
+ "%.4fs x%d(≈%.2ffps)" % (d, c, (1.0 / d if d else 0)) for d, c in top))
|
|
|
+ print(" 重复时间戳帧(双帧包特征): %d / %d" % (dup_ts, len(pts) - 1))
|
|
|
+
|
|
|
+ # 90fps / 高帧率判定
|
|
|
+ verdicts = []
|
|
|
+ if eff_fps > 85:
|
|
|
+ verdicts.append("★ 高帧率 %.1ffps —— 命中 interleave 双流 90fps 模板特征(fps=90 交错方案)"
|
|
|
+ % eff_fps)
|
|
|
+ if eff_fps > 55 and eff_fps <= 85:
|
|
|
+ verdicts.append("◇ 中高帧率 %.1ffps —— 疑似 3x 基准帧率交错方案的变体(如 28fps→84)" % eff_fps)
|
|
|
+ if dup_ts > len(pts) * 0.3:
|
|
|
+ verdicts.append("★ 超过三成帧时间戳重复 —— 病源式双帧包(fps 重采样会破坏动作)")
|
|
|
+ if durs and len(set(round(d, 4) for d in durs)) == 1:
|
|
|
+ verdicts.append("○ 全部帧等时长(CFR)")
|
|
|
+ else:
|
|
|
+ verdicts.append("○ 帧时长不全相同(%d 种)" % len(set(round(d, 4) for d in durs if d > 0)))
|
|
|
+ for v in verdicts:
|
|
|
+ print(" " + v)
|
|
|
+
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("3) 场序(interlace)标记")
|
|
|
+ print("=" * 72)
|
|
|
+ try:
|
|
|
+ fo = ffprobe_json(path, ["-select_streams", "v:0", "-show_entries",
|
|
|
+ "stream=field_order"])["streams"][0].get("field_order", "?")
|
|
|
+ except Exception:
|
|
|
+ fo = "?"
|
|
|
+ print(" 流级 field_order = %s" % fo)
|
|
|
+ print(" 帧级 interlaced_frame=1 的帧: %d / %d" % (len(interlaced), len(frames)))
|
|
|
+ if interlaced:
|
|
|
+ print(" top_field_first 取值集合: %s (False=bff, True=tff)" % (tff_vals or {"?"}))
|
|
|
+ print(" → 帧级标记为隔行。若内容实际是逐行混合,该标记即『伪装隔行』指纹(setfield)")
|
|
|
+ if fo in ("tt", "bb", "tff", "bff"):
|
|
|
+ print(" → ★ 流级带隔行标记(%s)。若画面实为逐行/行混合,这是 setfield 伪装——"
|
|
|
+ "平台转码会据此做去隔行,把行混合内容二次恶化(重影/模糊)" % fo)
|
|
|
+ elif fo == "progressive" and not interlaced:
|
|
|
+ print(" → ○ 无隔行标记(流级 progressive + 帧级逐行),平台不会触发去隔行")
|
|
|
+ elif fo in ("?", "(未标记)") and not interlaced:
|
|
|
+ print(" → ○ 无隔行标记")
|
|
|
+ return frames
|
|
|
+
|
|
|
+
|
|
|
+def decode_gray_frames(path, count, step=1, max_seconds=60):
|
|
|
+ """解码前 count*step 帧灰度图为 numpy 数组列表(需要 ffmpeg + numpy)。"""
|
|
|
+ import numpy as np
|
|
|
+ probe = ffprobe_json(path, ["-select_streams", "v:0", "-show_entries",
|
|
|
+ "stream=width,height"])
|
|
|
+ s = probe["streams"][0]
|
|
|
+ w, h = int(s["width"]), int(s["height"])
|
|
|
+ # 用 select 过滤再输出,一次 pipe 拿回(单引号由 ffmpeg 滤镜解析器处理逗号)
|
|
|
+ vf = "select='not(mod(n,%d))'" % step
|
|
|
+ cmd = ["ffmpeg", "-v", "error", "-i", path, "-t", str(max_seconds),
|
|
|
+ "-vf", vf + ",format=gray", "-f", "rawvideo", "-"]
|
|
|
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
+ frames = []
|
|
|
+ try:
|
|
|
+ while len(frames) < count:
|
|
|
+ buf = proc.stdout.read(w * h)
|
|
|
+ if not buf or len(buf) < w * h:
|
|
|
+ break
|
|
|
+ frames.append(np.frombuffer(buf, dtype=np.uint8).reshape(h, w).astype(np.float32))
|
|
|
+ finally:
|
|
|
+ try:
|
|
|
+ proc.stdout.close()
|
|
|
+ proc.terminate()
|
|
|
+ proc.wait(timeout=5)
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+ return frames
|
|
|
+
|
|
|
+
|
|
|
+def section_visual(path, count=240, step=1):
|
|
|
+ """视觉层:重复帧模式 + 逐行奇偶混合检测。"""
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("4) 视觉帧结构:重复帧模式 + 逐行奇偶(A/B行混合)检测")
|
|
|
+ print("=" * 72)
|
|
|
+ try:
|
|
|
+ import numpy as np
|
|
|
+ except ImportError:
|
|
|
+ print(" [!] 未安装 numpy,跳过视觉检测(pip install numpy 后重跑)")
|
|
|
+ return
|
|
|
+ try:
|
|
|
+ frames = decode_gray_frames(path, count, step)
|
|
|
+ except Exception as e:
|
|
|
+ print(" [!] 帧解码失败,跳过: %s" % e)
|
|
|
+ return
|
|
|
+ if len(frames) < 2:
|
|
|
+ print(" [!] 解码帧不足(<2),跳过")
|
|
|
+ return
|
|
|
+ print(" 解码 %d 帧(步长 %d)进行比对" % (len(frames), step))
|
|
|
+
|
|
|
+ # --- 4a 相邻帧重复(SSIM 简化版:归一化 MSE) ---
|
|
|
+ mses = []
|
|
|
+ for a, b in zip(frames, frames[1:]):
|
|
|
+ diff = ((a - b) ** 2).mean()
|
|
|
+ mses.append(diff)
|
|
|
+ near_dup = sum(1 for m in mses if m < 1.0)
|
|
|
+ frozen_run = 1
|
|
|
+ best_run = 1
|
|
|
+ for m in mses:
|
|
|
+ frozen_run = frozen_run + 1 if m < 0.5 else 1
|
|
|
+ best_run = max(best_run, frozen_run)
|
|
|
+ print(" 相邻帧 MSE: 中位 %.2f | <1.0(近似静止)占 %.0f%% | 最长连续静止 %d 帧"
|
|
|
+ % (float(np.median(mses)), near_dup * 100.0 / len(mses), best_run))
|
|
|
+ if near_dup > len(mses) * 0.6:
|
|
|
+ print(" ★ 大量近似重复帧 —— 存在帧复制/冻结(fps 重采样或 loop 补帧特征)")
|
|
|
+ if best_run >= 8:
|
|
|
+ print(" ★ 连续 %d 帧近似静止 —— 冻结段(loop/tpad 补帧或 fps 滤镜吃掉动作)" % best_run)
|
|
|
+
|
|
|
+ # --- 4b 逐行奇偶混合指纹 ---
|
|
|
+ # blend all_expr=if(eq(mod(Y,2),k),A,B) 的指纹:
|
|
|
+ # 偶数行全来自一路、奇数行全来自另一路 → 行差出现严格奇偶交替的大/小模式
|
|
|
+ comb_ratios, asym_list, nyq_list = [], [], []
|
|
|
+ for i, fr in enumerate(frames):
|
|
|
+ h, w = fr.shape
|
|
|
+ d1 = np.abs(np.diff(fr, axis=0)).mean() # |I(y)-I(y-1)|
|
|
|
+ d2 = np.abs(fr[2:] - fr[:-2]).mean() # |I(y)-I(y-2)|
|
|
|
+ comb_ratios.append(d1 / max(d2, 1e-9))
|
|
|
+ rowd = np.abs(np.diff(fr, axis=0)).mean(axis=1)
|
|
|
+ odd, even = float(rowd[0::2].mean()), float(rowd[1::2].mean())
|
|
|
+ asym_list.append(abs(odd - even) / max(odd, even, 1e-9))
|
|
|
+ rm = fr.mean(axis=1) - fr.mean()
|
|
|
+ spec = np.abs(np.fft.rfft(rm))
|
|
|
+ freqs = np.fft.rfftfreq(len(rm))
|
|
|
+ nyq = spec[(freqs > 0.45) & (freqs < 0.55)].max() if ((freqs > 0.45) & (freqs < 0.55)).any() else 0
|
|
|
+ low = spec[(freqs > 0) & (freqs < 0.35)].max() if ((freqs > 0) & (freqs < 0.35)).any() else 1
|
|
|
+ nyq_list.append(float(nyq / max(low, 1e-9)))
|
|
|
+ cr = float(np.median(comb_ratios))
|
|
|
+ asy = float(np.median(asym_list))
|
|
|
+ nyq = float(np.median(nyq_list))
|
|
|
+ print(" 梳状比 d1/d2 中位: %.3f (≈1.0 逐行自然内容;>1.15 隔行/行混合;<0.75 平滑)" % cr)
|
|
|
+ print(" 行差奇偶不对称度中位: %.1f%% (>15%% 且稳定 → 奇偶行能量分布不同)" % (asy * 100))
|
|
|
+ print(" 行频 Nyquist 能量占比中位: %.4f (>0.08 → 一行亮一行暗交替)" % nyq)
|
|
|
+ if (cr > 1.15 and nyq > 0.08) or asy > 0.20:
|
|
|
+ print(" ★★★ 命中『逐行奇偶混合』指纹:相邻行分属两路画面"
|
|
|
+ "(blend all_expr=if(eq(mod(Y,2)... 类 AB 合成;实测仿制样本 cr≈1.24 / nyq≈0.14)")
|
|
|
+ elif cr > 1.15:
|
|
|
+ print(" ★★ 强隔行梳状:内容含真场交替/错相位缩放(会诱发平台端去隔行)")
|
|
|
+ elif cr < 0.75:
|
|
|
+ print(" ○ 画面平滑无行级结构(可能已被缩放/模糊抹平,或非行混合方案)")
|
|
|
+ else:
|
|
|
+ print(" ○ 行级结构接近自然逐行内容(未见奇偶混合指纹)")
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 第5节:首帧来源比对
|
|
|
+
|
|
|
+def first_frame_gray(media_path, target_wh=None):
|
|
|
+ """取媒体(视频或图片)首帧灰度图;若有 target_wh 则缩放到该尺寸再返回。"""
|
|
|
+ import numpy as np
|
|
|
+ probe = ffprobe_json(media_path, ["-select_streams", "v:0", "-show_entries",
|
|
|
+ "stream=width,height"])
|
|
|
+ st = probe["streams"][0]
|
|
|
+ w, h = int(st["width"]), int(st["height"])
|
|
|
+ cmd = ["ffmpeg", "-v", "error", "-i", media_path, "-frames:v", "1",
|
|
|
+ "-vf", "format=gray", "-f", "rawvideo", "-"]
|
|
|
+ out, err, rc = sh(cmd, timeout=120)
|
|
|
+ if rc != 0 or len(out) < w * h:
|
|
|
+ raise RuntimeError("取首帧失败: %s" % err.decode("utf-8", errors="replace")[:200])
|
|
|
+ fr = np.frombuffer(out[:w * h], dtype=np.uint8).reshape(h, w).astype(np.float32)
|
|
|
+ if target_wh and (w, h) != tuple(target_wh):
|
|
|
+ try:
|
|
|
+ from PIL import Image
|
|
|
+ im = Image.fromarray(fr.astype(np.uint8)).resize(target_wh)
|
|
|
+ fr = np.asarray(im, dtype=np.float32)
|
|
|
+ except ImportError:
|
|
|
+ # 无 PIL:用 numpy 最近邻缩放兜底
|
|
|
+ tw, th = target_wh
|
|
|
+ yi = (np.arange(th) * h // th)[:, None]
|
|
|
+ xi = (np.arange(tw) * w // tw)[None, :]
|
|
|
+ fr = fr[yi, xi]
|
|
|
+ return fr
|
|
|
+
|
|
|
+
|
|
|
+def section_firstframe(out_path, refs):
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("5) 首帧来源比对")
|
|
|
+ print("=" * 72)
|
|
|
+ if not refs:
|
|
|
+ print(" 未提供 --ref,跳过。(用法: --ref 素材.mp4 --ref 实拍.mp4 --cover 封面.jpg)")
|
|
|
+ return
|
|
|
+ try:
|
|
|
+ import numpy as np
|
|
|
+ except ImportError:
|
|
|
+ print(" [!] 未安装 numpy,跳过")
|
|
|
+ return
|
|
|
+ probe = ffprobe_json(out_path, ["-select_streams", "v:0", "-show_entries",
|
|
|
+ "stream=width,height"])
|
|
|
+ s = probe["streams"][0]
|
|
|
+ tw, th = int(s["width"]), int(s["height"])
|
|
|
+ try:
|
|
|
+ base = first_frame_gray(out_path, (tw, th))
|
|
|
+ except Exception as e:
|
|
|
+ print(" [!] 产物首帧解码失败: %s" % e)
|
|
|
+ return
|
|
|
+ best = None
|
|
|
+ for ref in refs:
|
|
|
+ label = os.path.basename(ref)
|
|
|
+ try:
|
|
|
+ rf = first_frame_gray(ref, (tw, th))
|
|
|
+ mse = float(((base - rf) ** 2).mean())
|
|
|
+ psnr = 99.0 if mse <= 1e-9 else 10 * __import__("math").log10(255.0 ** 2 / mse)
|
|
|
+ print(" vs %-40s MSE=%9.2f PSNR=%6.2f dB" % (label, mse, psnr))
|
|
|
+ if best is None or mse < best[1]:
|
|
|
+ best = (label, mse, psnr)
|
|
|
+ except Exception as e:
|
|
|
+ print(" vs %-40s 失败: %s" % (label, str(e)[:120]))
|
|
|
+ if best:
|
|
|
+ tag = "最可能的首帧来源" if best[2] > 18 else "均不匹配(首帧可能来自其他源/黑场/封面)"
|
|
|
+ print(" → 最佳匹配: %s (PSNR %.2f dB) —— %s" % (best[0], best[2], tag))
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 第6节:音频与变速
|
|
|
+
|
|
|
+def section_audio(path, refs):
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("6) 音频参数与变速痕迹")
|
|
|
+ print("=" * 72)
|
|
|
+ data = ffprobe_json(path, ["-select_streams", "a:0", "-show_entries",
|
|
|
+ "stream=codec_name,sample_rate,channels,channel_layout,"
|
|
|
+ "bit_rate,duration,time_base"])
|
|
|
+ streams = data.get("streams", [])
|
|
|
+ if not streams:
|
|
|
+ print(" 产物无音频流。")
|
|
|
+ return
|
|
|
+ s = streams[0]
|
|
|
+ print(" 编码=%s 采样率=%sHz 声道=%s(%s) 码率=%s 时长=%ss"
|
|
|
+ % (s.get("codec_name"), s.get("sample_rate"), s.get("channels"),
|
|
|
+ s.get("channel_layout"), s.get("bit_rate"), s.get("duration")))
|
|
|
+ if s.get("sample_rate") == "44100":
|
|
|
+ print(" ○ 44100Hz —— 与 aresample=44100 指纹链一致")
|
|
|
+ fmt = ffprobe_json(path, ["-show_format", "-show_entries", "format=duration"])
|
|
|
+ out_dur = float(fmt.get("format", {}).get("duration") or 0)
|
|
|
+ for ref in refs:
|
|
|
+ if re.search(r"\.(png|jpe?g|bmp|webp)$", ref, re.I):
|
|
|
+ continue
|
|
|
+ try:
|
|
|
+ rfmt = ffprobe_json(ref, ["-show_format", "-show_entries", "format=duration"])
|
|
|
+ r_dur = float(rfmt.get("format", {}).get("duration") or 0)
|
|
|
+ except Exception:
|
|
|
+ continue
|
|
|
+ if r_dur > 0 and out_dur > 0:
|
|
|
+ r = out_dur / r_dur
|
|
|
+ note = "≈1.00 无变速"
|
|
|
+ if r < 0.97:
|
|
|
+ note = "★ 产物更短 → 疑似加速(变速/atempo 或 -t 截断)"
|
|
|
+ elif r > 1.03:
|
|
|
+ note = "★ 产物更长 → 疑似减速/补帧延长"
|
|
|
+ print(" 时长比 产物/参考(%s) = %.4f → %s"
|
|
|
+ % (os.path.basename(ref), r, note))
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- 第7节:元数据残留
|
|
|
+
|
|
|
+SUSPECT_KEYS = ("encoder", "handler_name", "creation_time", "comment", "copyright",
|
|
|
+ "title", "artist", "album", "major_brand", "minor_version",
|
|
|
+ "compatible_brands", "duration", "synco")
|
|
|
+
|
|
|
+def section_metadata(path, data):
|
|
|
+ print("\n" + "=" * 72)
|
|
|
+ print("7) 元数据残留与可疑字符串")
|
|
|
+ print("=" * 72)
|
|
|
+ fmt_tags = (data.get("format", {}) or {}).get("tags", {}) or {}
|
|
|
+ for k, v in fmt_tags.items():
|
|
|
+ print(" [format] %s = %s" % (k, v))
|
|
|
+ for s in data.get("streams", []):
|
|
|
+ tags = s.get("tags", {}) or {}
|
|
|
+ for k, v in tags.items():
|
|
|
+ print(" [stream %s] %s = %s" % (s.get("index"), k, v))
|
|
|
+ # 可疑点判读
|
|
|
+ enc = fmt_tags.get("encoder", "") or ""
|
|
|
+ m = re.match(r"Lavf(\d+)\.(\d+)", enc)
|
|
|
+ notes = []
|
|
|
+ if "handler_name" in fmt_tags or any("handler_name" in (s.get("tags") or {}) for s in data.get("streams", [])):
|
|
|
+ h = next((v for s in data.get("streams", [])
|
|
|
+ for k, v in (s.get("tags") or {}).items() if k == "handler_name"), "")
|
|
|
+ if h and h.lower() not in ("videohandler", "soundhandler"):
|
|
|
+ notes.append("★ handler_name='%s' 非默认值 —— 元数据伪造痕迹(伪装拍摄设备)" % h)
|
|
|
+ if m:
|
|
|
+ notes.append("encoder 标记 Lavf%s.%s(ffmpeg 复用器版本,可能与实际编码器不符=伪造点)" % m.groups())
|
|
|
+ for n in notes:
|
|
|
+ print(" " + n)
|
|
|
+
|
|
|
+ # 文件头尾字符串扫描
|
|
|
+ size = os.path.getsize(path)
|
|
|
+ with open(path, "rb") as f:
|
|
|
+ head = f.read(65536)
|
|
|
+ f.seek(max(0, size - 65536))
|
|
|
+ tail = f.read(65536)
|
|
|
+ strings = set()
|
|
|
+ for blob in (head, tail):
|
|
|
+ for m2 in re.finditer(rb"[\x20-\x7e]{6,}", blob):
|
|
|
+ s2 = m2.group().decode("ascii", errors="replace")
|
|
|
+ if any(k in s2.lower() for k in ("encoder", "handler", "gopro", "dji",
|
|
|
+ "lavf", "ffmpeg", "xc", "quicktime",
|
|
|
+ "isom", "creation", "2017", "2018",
|
|
|
+ "2019", "2020", "2021", "2022", "2023",
|
|
|
+ "2024", "2025", "2026")):
|
|
|
+ strings.add(s2[:80])
|
|
|
+ if strings:
|
|
|
+ print(" 头尾 64KB 可疑字符串:")
|
|
|
+ for s2 in sorted(strings)[:20]:
|
|
|
+ print(" | %s" % s2)
|
|
|
+ else:
|
|
|
+ print(" 头尾 64KB 未见可疑字符串(可能已 bitexact 清洗)")
|
|
|
+
|
|
|
+
|
|
|
+# ---------------------------------------------------------------- main
|
|
|
+
|
|
|
+def main():
|
|
|
+ ap = argparse.ArgumentParser(description="原版产出视频自动取证报告")
|
|
|
+ ap.add_argument("video", help="原版工具产出的视频文件路径")
|
|
|
+ ap.add_argument("--ref", action="append", default=[],
|
|
|
+ help="参考素材(视频或图片),可多次:--ref 素材.mp4 --ref 实拍.mp4")
|
|
|
+ ap.add_argument("--cover", help="封面图(等同 --ref,语义化别名)")
|
|
|
+ ap.add_argument("--report", help="同时把全部输出写入该文本文件(UTF-8)")
|
|
|
+ ap.add_argument("--frames", type=int, default=600, help="帧级探测帧数上限(默认600)")
|
|
|
+ ap.add_argument("--count", type=int, default=240, help="视觉解码帧数(默认240)")
|
|
|
+ ap.add_argument("--step", type=int, default=1, help="视觉解码步长(隔帧采样)")
|
|
|
+ args = ap.parse_args()
|
|
|
+
|
|
|
+ path = args.video
|
|
|
+ if not os.path.isfile(path):
|
|
|
+ print("[!] 文件不存在: %s" % path)
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ # ffmpeg/ffprobe 存在性
|
|
|
+ for tool in ("ffprobe", "ffmpeg"):
|
|
|
+ try:
|
|
|
+ sh([tool, "-version"], timeout=15)
|
|
|
+ except Exception as e:
|
|
|
+ print("[!] 找不到 %s,请先安装并加入 PATH: %s" % (tool, e))
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ sink = None
|
|
|
+ if args.report:
|
|
|
+ sink = open(args.report, "w", encoding="utf-8", buffering=1)
|
|
|
+ class Tee(object):
|
|
|
+ def __init__(self, *outs):
|
|
|
+ self.outs = outs
|
|
|
+ def write(self, s):
|
|
|
+ for o in self.outs:
|
|
|
+ o.write(s)
|
|
|
+ def flush(self):
|
|
|
+ for o in self.outs:
|
|
|
+ try:
|
|
|
+ o.flush()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+ sys.stdout = Tee(sys.__stdout__, sink)
|
|
|
+
|
|
|
+ refs = list(args.ref)
|
|
|
+ if args.cover:
|
|
|
+ refs.append(args.cover)
|
|
|
+
|
|
|
+ print("#### 取证报告: %s" % os.path.basename(path))
|
|
|
+ print("#### 生成时间: %s" % __import__("datetime").datetime.now().isoformat(timespec="seconds"))
|
|
|
+ print("#### 说明: ★=强指纹 ○=普通观察 [!]=异常")
|
|
|
+
|
|
|
+ data = section_container(path)
|
|
|
+ section_frames(path, max_frames=args.frames)
|
|
|
+ section_visual(path, count=args.count, step=args.step)
|
|
|
+ section_firstframe(path, refs)
|
|
|
+ section_audio(path, refs)
|
|
|
+ section_metadata(path, data)
|
|
|
+
|
|
|
+ print("\n#### 报告结束。将本报告连同 capture_ffmpeg.py 的命令行日志一并归档。")
|
|
|
+ if sink:
|
|
|
+ sink.close()
|
|
|
+ sys.stdout = sys.__stdout__
|
|
|
+ print("[√] 报告已写入: %s" % os.path.abspath(args.report))
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|