File size: 1,050 Bytes
326d3cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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