-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_image.py
More file actions
137 lines (112 loc) · 3.96 KB
/
test_image.py
File metadata and controls
137 lines (112 loc) · 3.96 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from ffmpegio import image, probe, transcode, FFmpegError
import tempfile, re
from os import path
outext = ".png"
def test_create():
# make sure rgb channels are mapped properly
A = image.create("color", c="red", s="100x100", d=1)
assert A["shape"] == (100, 100, 3)
assert A["dtype"] == ("|u1")
# A = image.create("color", c="green", s="100x100", d=1)
# A = image.create("color", c="blue", s="100x100", d=1)
# B = image.create("cellauto")
# B = image.create("allrgb", d=1)
# B = image.create("allyuv", d=1)
# B = image.create("gradients=s=1920x1080:x0=0:x1=0:y0=0:y1=1080", d=1)
# B = image.create("gradients", d=1)
# B = image.create("mandelbrot")
# B = image.create("mptestsrc=t=dc_luma", d=1)
# B = image.create("mptestsrc", t="ring1", d=1)
# B = image.create("life", life_color="#00ff00")
# B = image.create("haldclutsrc", 16, d=1)
# A = image.create("testsrc", d=1)
# B = image.create("testsrc2", alpha=0, d=1)
# B = image.create("rgbtestsrc", d=1)
# B = image.create("smptebars", d=1)
# B = image.create("smptehdbars", d=1)
# B = image.create("pal100bars", d=1)
# B = image.create("pal75bars", d=1)
# B = image.create("yuvtestsrc", d=1)
# B = image.create("sierpinski")
# print(A['dtype'], A['shape'])
# plt.subplot(1,2,1)
# plt.imshow(A)
# plt.subplot(1,2,2)
# plt.imshow(B)
# plt.show()
def test_read_write():
url = "tests/assets/ffmpeg-logo.png"
outext = ".jpg"
A = image.read(url)
print(A["dtype"] == "|u1")
B = image.read(url, pix_fmt="ya8")
print(B["shape"])
C = image.read(url, pix_fmt="rgb24")
D = image.read(url, pix_fmt="gray")
with tempfile.TemporaryDirectory() as tmpdirname:
out_url = path.join(tmpdirname, re.sub(r"\..*?$", outext, path.basename(url)))
print(out_url, C['shape'])
image.write(out_url, C)
print(probe.video_streams_basic(out_url))
C = image.read(out_url, pix_fmt="rgba", show_log=True)
# with open(path.join(tmpdirname, "progress.txt")) as f:
# print(f.read())
# display = os.read(read_pipe, 128).strip()
# plt.subplot(4, 1, 1)
# plt.imshow(A)
# plt.subplot(4, 1, 2)
# plt.imshow(B[..., 0], alpha=B[..., -1] / 255.0)
# plt.subplot(4, 1, 3)
# plt.imshow(C)
# plt.subplot(4, 1, 4)
# plt.imshow(D)
# plt.show()
def test_read_basic_filter():
url = "tests/assets/ffmpeg-logo.png"
B = image.read(
url,
show_log=True,
pix_fmt="rgb24",
fill_color="red",
crop=(300, 50),
flip="horizontal",
transpose="clock",
)
B = image.read(url, show_log=True, s=(100, -2))
print(B['shape'])
url = "tests/assets/ffmpeg-logo.png"
B = image.read(
url,
show_log=True,
fill_color="red",
)
B = image.read(url, show_log=True, fill_color="red", pix_fmt="rgb24")
def test_square_pixels():
url = "tests/assets/testvideo-1m.mp4"
with tempfile.TemporaryDirectory() as tmpdirname:
out_url = path.join(tmpdirname, path.basename(url))
transcode(url, out_url, show_log=True, vf="setsar=11/13", t=0.5)
B = image.read(out_url)
Bu = image.read(out_url, square_pixels="upscale")
Bd = image.read(out_url, square_pixels="downscale")
Bue = image.read(out_url, square_pixels="upscale_even")
Bde = image.read(out_url, square_pixels="downscale_even")
print(B['shape'])
print(Bu['shape'])
print(Bd['shape'])
print(Bue['shape'])
print(Bde['shape'])
if __name__ == "__main__":
from matplotlib import pyplot as plt
import logging
from ffmpegio import utils, ffmpegprocess
from ffmpegio.utils import filter as filter_utils, log as log_utils
# logging.basicConfig(level=logging.DEBUG)
url = "tests/assets/ffmpeg-logo.png"
B = image.read(
url,
show_log=True,
fill_color="red",
)
plt.imshow(B)
plt.show()