Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 2c19dd1

Browse files
committed
added test for gray12le pix_fmt
1 parent 911d9b2 commit 2c19dd1

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/test_gray12le.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import logging
2+
3+
logging.basicConfig(level=logging.DEBUG)
4+
5+
from fractions import Fraction
6+
import ffmpegio
7+
from tempfile import TemporaryDirectory
8+
from os import path
9+
import numpy as np
10+
11+
12+
def test_gray12le():
13+
14+
# codec = "h264"
15+
# size = [256, 256]
16+
# pix_fmt = "gray"
17+
# vmax = 2**8
18+
# dtype = "u1"
19+
# framerate = Fraction(30, 1)
20+
21+
codec = "ffv1"
22+
size = [254, 177]
23+
pix_fmt = "gray12le"
24+
vmax = 2**12
25+
dtype = "<u2"
26+
framerate = Fraction(32, 1)
27+
28+
show_log = True
29+
30+
with TemporaryDirectory() as dir:
31+
filepath = path.join(dir, "temp.mkv")
32+
with ffmpegio.open(
33+
filepath,
34+
"vw",
35+
framerate,
36+
# s_in=size,
37+
pix_fmt_in=pix_fmt,
38+
# pix_fmt=pix_fmt,
39+
show_log=show_log,
40+
vcodec=codec,
41+
) as f:
42+
for n in range(30):
43+
I = np.random.randint(0, vmax, [*size[::-1]], dtype)
44+
f.write(I)
45+
46+
with ffmpegio.open(filepath, "rv", show_log=show_log) as f:
47+
for Iout in f:
48+
pass
49+
50+
assert np.array_equal(I, Iout[-1, :, :, 0])
51+
52+
# print(ffmpegio.probe.video_streams_basic(filepath))
53+
r_out, Iout = ffmpegio.video.read(
54+
filepath,
55+
# show_log=show_log,
56+
# pix_fmt="gray12le",
57+
)
58+
59+
assert np.array_equal(I, Iout[-1, :, :, 0])
60+
61+
filepath1 = path.join(dir, "temp1.mkv")
62+
ffmpegio.video.write(
63+
filepath1,
64+
r_out,
65+
Iout,
66+
show_log=show_log,
67+
pix_fmt_in="gray12le",
68+
vcodec=codec,
69+
)
70+
r_out, Iout1 = ffmpegio.video.read(
71+
filepath1,
72+
# show_log=show_log,
73+
# pix_fmt="gray12le",
74+
)
75+
assert np.array_equal(Iout1, Iout)
76+
77+
# print(ffmpegio.probe.video_streams_basic(filepath))
78+
I0 = ffmpegio.image.read(
79+
filepath,
80+
# show_log=show_log
81+
# pix_fmt="gray12le",
82+
)
83+
84+
assert np.array_equal(I0, Iout[0, :, :, 0])
85+
86+
# print(sorted(ffmpegio.caps.pix_fmts().keys()))
87+
88+
if __name__=='__main__':
89+
test_gray12le()
90+
91+
92+
# -nostdin -hide_banner -pix_fmt gray12le -r 32 -f rawvideo -s 254x177 -i -
93+
# -vcodec ffv1 -r 32 'C:\Users\tikum\AppData\Local\Temp\tmp_xgk_lki\temp.mkv'
94+
# -nostdin -hide_banner -f rawvideo -c:v rawvideo -s 254x177 -r 32 -pix_fmt gray12le -i -
95+
# -vcodec ffv1 'C:\Users\tikum\AppData\Local\Temp\tmp39wbec7m\temp1.mkv'

0 commit comments

Comments
 (0)