Переглянути джерело

feat: 去重镜像开关dedup.mirror默认关(画面文字不反向)+强度可配;成片路径回写biaoti.chengpianPath

wubinggen 3 місяців тому
батько
коміт
3230993c89

+ 5 - 1
video_dedup.py

@@ -140,6 +140,8 @@ def main():
     ap.add_argument('--overlay', help='叠加一张半透明图片覆盖全画面(可配合 --overlay-alpha)')
     ap.add_argument('--overlay-alpha', type=float, default=0.05,
                     help='叠加图层不透明度 0~1,默认 0.05(即 5%% 混合,肉眼近无感)')
+    ap.add_argument('--no-mirror', action='store_true',
+                    help='禁用镜像翻转(画面不左右翻转;文字/标识不反向)')
     ap.add_argument('--same-name', action='store_true', help='输出保持原文件名(默认追加随机后缀)')
     args = ap.parse_args()
 
@@ -162,7 +164,9 @@ def main():
     out_dir.mkdir(parents=True, exist_ok=True)
 
     rng = random.Random(args.seed)
-    cfg = PRESETS[args.preset]
+    cfg = dict(PRESETS[args.preset])
+    if args.no_mirror:
+        cfg['p_hflip'] = 0.0
     report_path = out_dir / '处理报告.csv'
     fields = ['文件名', '输出名', '状态', '原分辨率', '原时长(s)', '新时长(s)',
               '镜像', '裁剪', '边框', '调色', '变速', '帧率', '叠加图层']

+ 11 - 4
白盒重建/config.example.json

@@ -1,7 +1,9 @@
 {
   "db_path": "data.db",
   "ai": {
-    "zhipu_keys": ["在此填你自己的智谱APIKey(bigmodel.cn 申请),可多枚做轮换容错"],
+    "zhipu_keys": [
+      "在此填你自己的智谱APIKey(bigmodel.cn 申请),可多枚做轮换容错"
+    ],
     "zhipu_api_key": "单key直接填这里;多key也可用竖线分隔 k1|k2|k3(与数组位合并去重)",
     "model": "cogview-3-flash",
     "image_size": "1024x1024",
@@ -19,7 +21,6 @@
     "border_w": 0,
     "border_color": "black",
     "shadow_color": ""
-
   },
   "translate": {
     "baidu_appid": "自己的百度翻译appid",
@@ -46,6 +47,10 @@
     ],
     "daily_limit_per_account": 5
   },
+  "dedup": {
+    "mirror": false,
+    "preset": "strong"
+  },
   "ads": {
     "enabled": false,
     "interval_sec": 300,
@@ -59,6 +64,8 @@
     "recharge_amount": 0.0,
     "include_not_live": false
   },
-  "proxy": { "enabled": false, "api_url": "" }
+  "proxy": {
+    "enabled": false,
+    "api_url": ""
+  }
 }
-

+ 1 - 0
白盒重建/kuaishou_tool/config.py

@@ -24,6 +24,7 @@ DEFAULTS = {
                     "min_commission": 0.0, "max_price": 0.0, "ban_shops": []},
     },
     "publish": {"fragment_mb": 8, "delay_sec": [30, 180], "daily_limit_per_account": 5},
+    "dedup": {"mirror": False, "preset": "strong"},   # mirror 默认关:画面不左右翻转
     "ads": {"enabled": False, "interval_sec": 300,
             "stop_enabled": True, "stop_cost_threshold": 10.0,
             "bid_enabled": True, "roi_target": 0.0, "roi_tolerance": 0.0,

+ 10 - 3
白盒重建/kuaishou_tool/media.py

@@ -413,9 +413,11 @@ def compose(cfg: dict, video_path, image_path, title: str) -> Path:
 # 5. 视频去重:复用 ../../video_dedup.py(README:集成自研去重工具)
 # --------------------------------------------------------------------------
 def dedup(cfg: dict, video_path) -> Path:
-    """调用 video_dedup.py(-p strong)做指纹级去重,产出移入 临存视频/。
+    """调用 video_dedup.py 做指纹级去重,产出移入 临存视频/。
 
-    - 命令:python video_dedup.py -i 视频 -o 临时目录 -p strong;
+    - 命令:python video_dedup.py -i 视频 -o 临时目录 -p <档位>;
+    - cfg['dedup']:preset(默认 strong)、mirror(默认 False=不镜像,
+      画面文字/标识不反向;True=允许随机左右翻转,更强的指纹改变);
     - 成功后取产物 mp4 移入 临存视频/,并去掉随机 token 还原为 videoId 原名;
     - 脚本缺失/调用失败/无产物时【原样返回输入路径】并记日志(不中断流水线)。
     """
@@ -426,6 +428,7 @@ def dedup(cfg: dict, video_path) -> Path:
     if not DEDUP_SCRIPT.exists():
         _logger().warning('去重脚本不存在(%s),原样返回: %s', DEDUP_SCRIPT, video_path)
         return video_path
+    ded = cfg.get('dedup') or {}
     out_dir = config.dir_of(cfg, '临存视频')
     out_dir.mkdir(parents=True, exist_ok=True)
     dst = out_dir / f'{video_path.stem}.mp4'   # 去掉 video_dedup 的随机 token,还原原名
@@ -437,7 +440,10 @@ def dedup(cfg: dict, video_path) -> Path:
     try:
         with tempfile.TemporaryDirectory(prefix='m3_dedup_') as td:
             cmd = [sys.executable, str(DEDUP_SCRIPT),
-                   '-i', str(video_path), '-o', td, '-p', 'strong']
+                   '-i', str(video_path), '-o', td,
+                   '-p', str(ded.get('preset') or 'strong')]
+            if not ded.get('mirror', False):
+                cmd.append('--no-mirror')
             r = subprocess.run(cmd, capture_output=True, text=True,
                                encoding='utf-8', errors='replace',
                                env=env, timeout=cfg.get('dedup_timeout', 1800))
@@ -497,5 +503,6 @@ def process_full(cfg: dict, video_id: str):
     except Exception:
         _logger().exception('process_full 处理失败: videoId=%r', video_id)
         return None
+    db.exe('UPDATE biaoti SET chengpianPath=? WHERE biaoti1=?', (str(out), video_id))
     _logger().info('process_full 成片完成: %r → %s', video_id, out)
     return out

+ 30 - 0
白盒重建/tests/test_media.py

@@ -518,6 +518,36 @@ def test_dedup_missing_script(cfg, tmp_path, monkeypatch):
     assert media.dedup(cfg, src) == src
 
 
+def test_dedup_mirror_flag(cfg, tmp_path, monkeypatch):
+    """镜像开关:默认(未配置/mirror=False)传 --no-mirror;mirror=True 不传。
+    档位 preset 一并从 cfg['dedup'] 透传。"""
+    src = tmp_path / 'm.mp4'
+    src.write_bytes(b'x')
+    cmds = []
+
+    class FakeR:
+        returncode, stdout, stderr = 0, '', ''
+
+    def fake_run(cmd, **kw):
+        cmds.append(cmd)
+        out = Path(cmd[cmd.index('-o') + 1])
+        out.mkdir(parents=True, exist_ok=True)
+        (out / 'm.mp4').write_bytes(b'y')
+        return FakeR()
+
+    monkeypatch.setattr(media.subprocess, 'run', fake_run)
+    c2 = copy.deepcopy(cfg)
+    c2['dedup'] = {}
+    media.dedup(c2, src)                                   # 未配置 → 默认不镜像
+    assert '--no-mirror' in cmds[-1]
+    c2['dedup'] = {'mirror': False, 'preset': 'medium'}
+    media.dedup(c2, src)
+    assert '--no-mirror' in cmds[-1] and 'medium' in cmds[-1]
+    c2['dedup'] = {'mirror': True}
+    media.dedup(c2, src)
+    assert '--no-mirror' not in cmds[-1]
+
+
 # --------------------------------------------------------------------------
 # 6. process_full(编排;网络全打桩,ffmpeg 真实执行)
 # --------------------------------------------------------------------------