"""Explicit Linux FFmpeg acceptance: pytest tests/media_v2_linux.py -q. Not part of portable suite; requires real FFmpeg/libx264/drawtext and Noto fonts. """ from pathlib import Path from types import SimpleNamespace import pytest from app.timeline import compile_timeline from app.media import compose_workflow, inspect_video_track, run_process, MediaError from test_timeline_v2 import spec @pytest.mark.asyncio @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)]) sources.append(source) 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)<=.10 # Decode full output, not just the muxer metadata. await run_process(['ffmpeg','-v','error','-i',str(result.outputs[0]),'-f','null','-']) @pytest.mark.asyncio async def test_real_119_frame_source_rejected(tmp_path): 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) @pytest.mark.asyncio async def test_real_variable_sixteen_second_workflow(tmp_path): from test_multishot_v3 import story 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)]) sources.append(source) 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)<=.10 assert result.result['clip_count']==4 await run_process(['ffmpeg','-v','error','-i',str(result.outputs[0]),'-f','null','-'])