#!/usr/bin/env python3
"""Generate the local test videos of the live fixture provider (docs/plan/milionar-library/120 §3).

media/fixture_long.mp4 (240 s) and media/fixture_short.mp4 (40 s): static SMPTE bars with a tone, every frame a
keyframe, so a seek lands exactly. Created once; git-ignored.
"""
import os
import subprocess

HERE = os.path.dirname(os.path.abspath(__file__))
MEDIA = os.path.join(HERE, 'media')


def make(name, seconds):
    path = os.path.join(MEDIA, name)
    if os.path.exists(path):
        return path
    os.makedirs(MEDIA, exist_ok=True)
    subprocess.run(['ffmpeg', '-y', '-loglevel', 'error', '-f', 'lavfi', '-i', 'smptehdbars=size=1280x720:rate=25',
                    '-f', 'lavfi', '-i', 'sine=frequency=440', '-t', str(seconds), '-c:v', 'libx264', '-g', '1',
                    '-pix_fmt', 'yuv420p', '-c:a', 'aac', path], check=True)
    return path


if __name__ == '__main__':
    for name, seconds in (('fixture_long.mp4', 240), ('fixture_short.mp4', 40)):
        print(make(name, seconds))
