cmvr-visual/backend/tests/test_chinese_workflow_subtitles.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

36 lines
2.0 KiB
Python

"""用实际 FFmpeg 证明不同中文字形能渲染,避免仅验证字幕字符串而漏掉方框。"""
import os
from pathlib import Path
import shutil
from types import SimpleNamespace
import pytest
@pytest.mark.asyncio
@pytest.mark.skipif(os.name != 'nt', reason='Windows Chinese font regression')
async def test_windows_workflow_renders_distinct_chinese_glyphs(tmp_path):
from app.adapters.media import compose_workflow, run_process
ffmpeg, ffprobe = shutil.which('ffmpeg'), shutil.which('ffprobe')
if not ffmpeg or not ffprobe or not (Path(os.environ.get('WINDIR', 'C:/Windows')) / 'Fonts/msyh.ttc').exists():
pytest.skip('Real FFmpeg and Microsoft YaHei required')
settings = SimpleNamespace(workspace_root=tmp_path, ffmpeg_bin=ffmpeg, ffprobe_bin=ffprobe,
max_output_bytes=20 * 1024 * 1024)
source = tmp_path / 'black.mp4'
await run_process([ffmpeg,'-v','error','-f','lavfi','-i','color=c=black:s=320x180:r=24',
'-frames:v','48','-c:v','libx264','-pix_fmt','yuv420p',str(source)])
plan = SimpleNamespace(fps=24,frames=48,canvas=(1920,1080),
clips=[{'start_frame':0,'duration_frames':48,'width':320,'height':180}],
spec={'profile':'landscape_1080_v1','shots':[{}],'render':{'audio':None,'fit':'contain',
'subtitles':[{'start_frame':0,'end_frame':24,'text':'鲲鹏'},
{'start_frame':24,'end_frame':48,'text':'北冥'}]}})
result = await compose_workflow(plan,tmp_path/'render',settings=settings,sources=[source])
samples=[]
for second in ('0.5','1.5'):
raw=await run_process([ffmpeg,'-v','error','-ss',second,'-i',str(result.outputs[0]),
'-vf','crop=400:160:760:900,format=gray','-frames:v','1','-f','rawvideo','-'])
samples.append(raw)
# 缺字方框对两段等长中文产生同一幅图;真正中文字形的笔画差异明显。
assert len(samples[0]) == len(samples[1]) == 64000
assert sum(abs(a-b)>30 for a,b in zip(samples[0],samples[1]))>300