cmvr-visual/backend/tests/media_longshot_linux.py

36 lines
1.9 KiB
Python
Raw Normal View History

"""Explicit real-FFmpeg acceptance for mixed native-length workflow clips."""
from types import SimpleNamespace
import pytest
from app.media import MediaError, compose_workflow, inspect_video_track, run_process
from app.timeline import compile_timeline
@pytest.mark.asyncio
async def test_real_five_ten_fifteen_second_clips_produce_thirty_seconds(tmp_path):
settings = SimpleNamespace(workspace_root=tmp_path, ffmpeg_bin='ffmpeg', ffprobe_bin='ffprobe',
max_output_bytes=100 * 1024 * 1024)
body = {'schema_version': 2, 'profile': 'landscape_1080_v1', 'shots': [
{'key': f'shot_{i}', 'prompt': f'shot {i}', 'duration_frames': frames}
for i, frames in enumerate((120, 240, 360), 1)]}
plan = compile_timeline(body, {})
sources = []
for index, color in enumerate(('red', 'green', 'blue'), 1):
source = tmp_path / f'source-{index}.mp4'
frames = plan.shot_generation_parameters[f'shot_{index}']['num_frames']
await run_process(['ffmpeg', '-v', 'error', '-f', 'lavfi', '-i',
f'color=c={color}:s=1920x1056:r=24', '-frames:v', str(frames),
'-c:v', 'libx264', '-preset', 'ultrafast', '-threads', '2', str(source)])
sources.append(source)
output = await compose_workflow(plan, tmp_path / 'output', settings=settings, sources=sources)
track = await inspect_video_track(output.outputs[0], settings)
assert track['frames'] == 720 and track['fps'] == 24
assert (track['width'], track['height']) == (1920, 1080)
assert abs(track['duration'] - 30) < .05
await run_process(['ffmpeg', '-v', 'error', '-threads', '2', '-i', str(output.outputs[0]), '-f', 'null', '-'])
# A real short source cannot be stretched or frozen to impersonate15 seconds.
with pytest.raises(MediaError):
await compose_workflow(plan, tmp_path / 'invalid-output', settings=settings,
sources=[sources[0], sources[1], sources[0]])