Spaces:
Running on T4
Running on T4
Download tools/make_fixture.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/make_fixture.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/tools/make_fixture.py
-
curl -L -o make_fixture.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/make_fixture.py
1.01 kB
| """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]) | |