This repository was archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gray12le.py
More file actions
95 lines (76 loc) · 2.45 KB
/
test_gray12le.py
File metadata and controls
95 lines (76 loc) · 2.45 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import logging
logging.basicConfig(level=logging.DEBUG)
from fractions import Fraction
import ffmpegio
from tempfile import TemporaryDirectory
from os import path
import numpy as np
def test_gray12le():
# codec = "h264"
# size = [256, 256]
# pix_fmt = "gray"
# vmax = 2**8
# dtype = "u1"
# framerate = Fraction(30, 1)
codec = "ffv1"
size = [254, 177]
pix_fmt = "gray12le"
vmax = 2**12
dtype = "<u2"
framerate = Fraction(32, 1)
show_log = True
with TemporaryDirectory() as dir:
filepath = path.join(dir, "temp.mkv")
with ffmpegio.open(
filepath,
"vw",
framerate,
# s_in=size,
pix_fmt_in=pix_fmt,
# pix_fmt=pix_fmt,
show_log=show_log,
vcodec=codec,
) as f:
for n in range(30):
I = np.random.randint(0, vmax, [*size[::-1]], dtype)
f.write(I)
with ffmpegio.open(filepath, "rv", show_log=show_log) as f:
for Iout in f:
pass
assert np.array_equal(I, Iout[-1, :, :, 0])
# print(ffmpegio.probe.video_streams_basic(filepath))
r_out, Iout = ffmpegio.video.read(
filepath,
# show_log=show_log,
# pix_fmt="gray12le",
)
assert np.array_equal(I, Iout[-1, :, :, 0])
filepath1 = path.join(dir, "temp1.mkv")
ffmpegio.video.write(
filepath1,
r_out,
Iout,
show_log=show_log,
pix_fmt_in="gray12le",
vcodec=codec,
)
r_out, Iout1 = ffmpegio.video.read(
filepath1,
# show_log=show_log,
# pix_fmt="gray12le",
)
assert np.array_equal(Iout1, Iout)
# print(ffmpegio.probe.video_streams_basic(filepath))
I0 = ffmpegio.image.read(
filepath,
# show_log=show_log
# pix_fmt="gray12le",
)
assert np.array_equal(I0, Iout[0, :, :, 0])
# print(sorted(ffmpegio.caps.pix_fmts().keys()))
if __name__=='__main__':
test_gray12le()
# -nostdin -hide_banner -pix_fmt gray12le -r 32 -f rawvideo -s 254x177 -i -
# -vcodec ffv1 -r 32 'C:\Users\tikum\AppData\Local\Temp\tmp_xgk_lki\temp.mkv'
# -nostdin -hide_banner -f rawvideo -c:v rawvideo -s 254x177 -r 32 -pix_fmt gray12le -i -
# -vcodec ffv1 'C:\Users\tikum\AppData\Local\Temp\tmp39wbec7m\temp1.mkv'