Spaces:
Running on T4
Running on T4
File size: 1,007 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 | """A generated moving-shape video for integration checks, never baseball validation."""
from fractions import Fraction
import sys
import av
import numpy as np
def make_fixture(path):
with av.open(str(path), "w") as output:
stream = output.add_stream("libx264", rate=30)
stream.width, stream.height, stream.pix_fmt = 320, 240, "yuv420p"
stream.time_base = Fraction(1,1000)
stream.codec_context.time_base = Fraction(1,1000)
stream.options = {"bf":"0", "crf":"18"}
for i in range(30):
image = np.full((240,320,3), 30+i, np.uint8)
image[80:160, 60+i*3:100+i*3] = [50,180,230]
frame = av.VideoFrame.from_ndarray(image, format="bgr24")
frame.pts, frame.time_base = round(i*1000/30), Fraction(1,1000)
for packet in stream.encode(frame):
output.mux(packet)
for packet in stream.encode():
output.mux(packet)
if __name__ == "__main__":
make_fixture(sys.argv[1])
|