2026-11-10 23:56:50 +08:00
|
|
|
"""Explicit Linux FFmpeg acceptance: pytest tests/media_v2_linux.py -q.
|
|
|
|
|
Not part of portable suite; requires real FFmpeg/libx264/drawtext and Noto fonts.
|
|
|
|
|
"""
|
2026-11-14 14:07:26 +08:00
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
from pathlib import Path
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
import pytest
|
2026-11-14 14:07:26 +08:00
|
|
|
from app.domain.timeline import compile_timeline
|
|
|
|
|
from app.adapters.media import compose_workflow, inspect_video_track, run_process, MediaError
|
2026-11-10 23:56:50 +08:00
|
|
|
from test_timeline_v2 import spec
|
|
|
|
|
|
2026-11-14 14:07:26 +08:00
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
@pytest.mark.asyncio
|
2026-11-14 14:07:26 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"profile,fit",
|
|
|
|
|
[
|
|
|
|
|
("landscape_1080_v1", "contain"),
|
|
|
|
|
("landscape_1080_v1", "cover"),
|
|
|
|
|
("portrait_1080_v1", "contain"),
|
|
|
|
|
("portrait_1080_v1", "cover"),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
async def test_real_fixed_frame_workflow(tmp_path, profile, fit):
|
|
|
|
|
settings = SimpleNamespace(
|
|
|
|
|
workspace_root=tmp_path,
|
|
|
|
|
ffmpeg_bin="ffmpeg",
|
|
|
|
|
ffprobe_bin="ffprobe",
|
|
|
|
|
max_output_bytes=100 * 1024 * 1024,
|
|
|
|
|
)
|
|
|
|
|
body = spec()
|
|
|
|
|
body["profile"] = profile
|
|
|
|
|
body["render"] = {
|
|
|
|
|
"fit": fit,
|
|
|
|
|
"audio": {
|
|
|
|
|
"asset_id": "audio",
|
|
|
|
|
"source_start_ms": 3000,
|
|
|
|
|
"source_end_ms": 18000,
|
|
|
|
|
"offset_frame": 0,
|
|
|
|
|
},
|
|
|
|
|
"subtitles": [
|
|
|
|
|
{"start_frame": 119, "end_frame": 241, "text": "Across shots"},
|
|
|
|
|
{"start_frame": 241, "end_frame": 360, "text": "Final frame"},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
audio = tmp_path / "audio.wav"
|
|
|
|
|
await run_process(
|
|
|
|
|
[
|
|
|
|
|
"ffmpeg",
|
|
|
|
|
"-v",
|
|
|
|
|
"error",
|
|
|
|
|
"-f",
|
|
|
|
|
"lavfi",
|
|
|
|
|
"-i",
|
|
|
|
|
"sine=frequency=440:sample_rate=48000",
|
|
|
|
|
"-t",
|
|
|
|
|
"18",
|
|
|
|
|
str(audio),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
plan = compile_timeline(body, {"audio": {"kind": "audio", "duration_seconds": 18}})
|
|
|
|
|
w, h = plan.generation_parameters["upscale_width"], plan.generation_parameters["upscale_height"]
|
|
|
|
|
sources = []
|
|
|
|
|
for index, color in enumerate(("red", "green", "blue")):
|
|
|
|
|
source = tmp_path / f"source-{index}.mp4"
|
|
|
|
|
await run_process(
|
|
|
|
|
[
|
|
|
|
|
"ffmpeg",
|
|
|
|
|
"-v",
|
|
|
|
|
"error",
|
|
|
|
|
"-f",
|
|
|
|
|
"lavfi",
|
|
|
|
|
"-i",
|
|
|
|
|
f"color=c={color}:s={w}x{h}:r=24",
|
|
|
|
|
"-frames:v",
|
|
|
|
|
"121",
|
|
|
|
|
"-c:v",
|
|
|
|
|
"libx264",
|
|
|
|
|
"-preset",
|
|
|
|
|
"ultrafast",
|
|
|
|
|
"-threads",
|
|
|
|
|
"2",
|
|
|
|
|
str(source),
|
|
|
|
|
]
|
|
|
|
|
)
|
2026-11-10 23:56:50 +08:00
|
|
|
sources.append(source)
|
2026-11-14 14:07:26 +08:00
|
|
|
result = await compose_workflow(
|
|
|
|
|
plan, tmp_path / "work", settings=settings, sources=sources, audio=audio
|
|
|
|
|
)
|
|
|
|
|
track = await inspect_video_track(result.outputs[0], settings)
|
|
|
|
|
assert track["frames"] == 360 and track["fps"] == 24
|
|
|
|
|
assert (track["width"], track["height"]) == plan.canvas
|
|
|
|
|
assert abs(track["duration"] - 15) <= 0.10
|
2026-11-10 23:56:50 +08:00
|
|
|
# Decode full output, not just the muxer metadata.
|
2026-11-14 14:07:26 +08:00
|
|
|
await run_process(["ffmpeg", "-v", "error", "-i", str(result.outputs[0]), "-f", "null", "-"])
|
|
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_real_119_frame_source_rejected(tmp_path):
|
2026-11-14 14:07:26 +08:00
|
|
|
settings = SimpleNamespace(
|
|
|
|
|
workspace_root=tmp_path,
|
|
|
|
|
ffmpeg_bin="ffmpeg",
|
|
|
|
|
ffprobe_bin="ffprobe",
|
|
|
|
|
max_output_bytes=100 * 1024 * 1024,
|
|
|
|
|
)
|
|
|
|
|
source = tmp_path / "short.mp4"
|
|
|
|
|
await run_process(
|
|
|
|
|
[
|
|
|
|
|
"ffmpeg",
|
|
|
|
|
"-v",
|
|
|
|
|
"error",
|
|
|
|
|
"-f",
|
|
|
|
|
"lavfi",
|
|
|
|
|
"-i",
|
|
|
|
|
"color=c=red:s=1920x1056:r=24",
|
|
|
|
|
"-frames:v",
|
|
|
|
|
"119",
|
|
|
|
|
"-c:v",
|
|
|
|
|
"libx264",
|
|
|
|
|
"-preset",
|
|
|
|
|
"ultrafast",
|
|
|
|
|
"-threads",
|
|
|
|
|
"2",
|
|
|
|
|
str(source),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
with pytest.raises(MediaError, match="120"):
|
|
|
|
|
await compose_workflow(
|
|
|
|
|
compile_timeline(spec(), {}), tmp_path / "work", settings=settings, sources=[source] * 3
|
|
|
|
|
)
|
2026-11-11 00:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_real_variable_sixteen_second_workflow(tmp_path):
|
|
|
|
|
from test_multishot_v3 import story
|
2026-11-14 14:07:26 +08:00
|
|
|
|
|
|
|
|
settings = SimpleNamespace(
|
|
|
|
|
workspace_root=tmp_path,
|
|
|
|
|
ffmpeg_bin="ffmpeg",
|
|
|
|
|
ffprobe_bin="ffprobe",
|
|
|
|
|
max_output_bytes=100 * 1024 * 1024,
|
|
|
|
|
)
|
|
|
|
|
body = story(durations=[24, 120, 120, 120])
|
|
|
|
|
body["render"] = {
|
|
|
|
|
"subtitles": [{"start_frame": 361, "end_frame": 384, "text": "Beyond fifteen seconds"}]
|
|
|
|
|
}
|
|
|
|
|
plan = compile_timeline(body, {})
|
|
|
|
|
sources = []
|
|
|
|
|
w, h = plan.generation_parameters["upscale_width"], plan.generation_parameters["upscale_height"]
|
|
|
|
|
for index, color in enumerate(("red", "green", "blue", "yellow")):
|
|
|
|
|
source = tmp_path / f"source-{index}.mp4"
|
|
|
|
|
await run_process(
|
|
|
|
|
[
|
|
|
|
|
"ffmpeg",
|
|
|
|
|
"-v",
|
|
|
|
|
"error",
|
|
|
|
|
"-f",
|
|
|
|
|
"lavfi",
|
|
|
|
|
"-i",
|
|
|
|
|
f"color=c={color}:s={w}x{h}:r=24",
|
|
|
|
|
"-frames:v",
|
|
|
|
|
"121",
|
|
|
|
|
"-c:v",
|
|
|
|
|
"libx264",
|
|
|
|
|
"-preset",
|
|
|
|
|
"ultrafast",
|
|
|
|
|
"-threads",
|
|
|
|
|
"2",
|
|
|
|
|
str(source),
|
|
|
|
|
]
|
|
|
|
|
)
|
2026-11-11 00:36:30 +08:00
|
|
|
sources.append(source)
|
2026-11-14 14:07:26 +08:00
|
|
|
result = await compose_workflow(plan, tmp_path / "work", settings=settings, sources=sources)
|
|
|
|
|
track = await inspect_video_track(result.outputs[0], settings)
|
|
|
|
|
assert track["frames"] == 384 and track["fps"] == 24
|
|
|
|
|
assert (track["width"], track["height"]) == (1920, 1080)
|
|
|
|
|
assert abs(track["duration"] - 16) <= 0.10
|
|
|
|
|
assert result.result["clip_count"] == 4
|
|
|
|
|
await run_process(["ffmpeg", "-v", "error", "-i", str(result.outputs[0]), "-f", "null", "-"])
|