from fractions import Fraction from pathlib import Path import numpy as np import pytest import av @pytest.fixture def video(tmp_path): """Variable-cadence generated recording; no user footage or accuracy claims.""" path = tmp_path / "synthetic.mp4" with av.open(str(path), "w") as out: stream = out.add_stream("libx264", rate=30) stream.width, stream.height, stream.pix_fmt = 160, 120, "yuv420p" stream.time_base = Fraction(1, 1000) stream.codec_context.time_base = Fraction(1, 1000) stream.options = {"bf": "0", "crf": "0"} for i, time in enumerate([0, 33, 66, 100, 150, 183, 216, 250]): img = np.full((120,160,3), i*20, np.uint8) img[20:40, 20+i:50+i] = [255,30,60] frame = av.VideoFrame.from_ndarray(img, format="bgr24") frame.pts, frame.time_base = time, Fraction(1,1000) for packet in stream.encode(frame): out.mux(packet) for packet in stream.encode(): out.mux(packet) return path