auto-editor 28.0.2__py3-none-any.whl → 29.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {auto_editor-28.0.2.dist-info → auto_editor-29.0.0.dist-info}/METADATA +5 -4
- auto_editor-29.0.0.dist-info/RECORD +5 -0
- auto_editor-29.0.0.dist-info/top_level.txt +1 -0
- auto_editor/__init__.py +0 -1
- auto_editor/__main__.py +0 -503
- auto_editor/analyze.py +0 -393
- auto_editor/cmds/__init__.py +0 -0
- auto_editor/cmds/cache.py +0 -69
- auto_editor/cmds/desc.py +0 -32
- auto_editor/cmds/info.py +0 -213
- auto_editor/cmds/levels.py +0 -199
- auto_editor/cmds/palet.py +0 -29
- auto_editor/cmds/repl.py +0 -113
- auto_editor/cmds/subdump.py +0 -72
- auto_editor/cmds/test.py +0 -812
- auto_editor/edit.py +0 -548
- auto_editor/exports/__init__.py +0 -0
- auto_editor/exports/fcp11.py +0 -195
- auto_editor/exports/fcp7.py +0 -313
- auto_editor/exports/json.py +0 -63
- auto_editor/exports/shotcut.py +0 -147
- auto_editor/ffwrapper.py +0 -187
- auto_editor/help.py +0 -223
- auto_editor/imports/__init__.py +0 -0
- auto_editor/imports/fcp7.py +0 -275
- auto_editor/imports/json.py +0 -234
- auto_editor/json.py +0 -297
- auto_editor/lang/__init__.py +0 -0
- auto_editor/lang/libintrospection.py +0 -10
- auto_editor/lang/libmath.py +0 -23
- auto_editor/lang/palet.py +0 -724
- auto_editor/lang/stdenv.py +0 -1184
- auto_editor/lib/__init__.py +0 -0
- auto_editor/lib/contracts.py +0 -235
- auto_editor/lib/data_structs.py +0 -278
- auto_editor/lib/err.py +0 -2
- auto_editor/make_layers.py +0 -315
- auto_editor/preview.py +0 -93
- auto_editor/render/__init__.py +0 -0
- auto_editor/render/audio.py +0 -517
- auto_editor/render/subtitle.py +0 -205
- auto_editor/render/video.py +0 -312
- auto_editor/timeline.py +0 -331
- auto_editor/utils/__init__.py +0 -0
- auto_editor/utils/bar.py +0 -142
- auto_editor/utils/chunks.py +0 -2
- auto_editor/utils/cmdkw.py +0 -206
- auto_editor/utils/container.py +0 -102
- auto_editor/utils/func.py +0 -128
- auto_editor/utils/log.py +0 -124
- auto_editor/utils/types.py +0 -277
- auto_editor/vanparse.py +0 -313
- auto_editor-28.0.2.dist-info/RECORD +0 -56
- auto_editor-28.0.2.dist-info/entry_points.txt +0 -6
- auto_editor-28.0.2.dist-info/top_level.txt +0 -2
- docs/build.py +0 -70
- {auto_editor-28.0.2.dist-info → auto_editor-29.0.0.dist-info}/WHEEL +0 -0
- {auto_editor-28.0.2.dist-info → auto_editor-29.0.0.dist-info}/licenses/LICENSE +0 -0
auto_editor/cmds/test.py
DELETED
@@ -1,812 +0,0 @@
|
|
1
|
-
import concurrent.futures
|
2
|
-
import hashlib
|
3
|
-
import os
|
4
|
-
import shutil
|
5
|
-
import subprocess
|
6
|
-
import sys
|
7
|
-
from collections.abc import Callable
|
8
|
-
from dataclasses import dataclass, field
|
9
|
-
from fractions import Fraction
|
10
|
-
from hashlib import sha256
|
11
|
-
from tempfile import mkdtemp
|
12
|
-
from time import perf_counter
|
13
|
-
|
14
|
-
import bv
|
15
|
-
import numpy as np
|
16
|
-
|
17
|
-
from auto_editor.ffwrapper import FileInfo
|
18
|
-
from auto_editor.lang.palet import Lexer, Parser, env, interpret
|
19
|
-
from auto_editor.lang.stdenv import make_standard_env
|
20
|
-
from auto_editor.lib.data_structs import Char
|
21
|
-
from auto_editor.lib.err import MyError
|
22
|
-
from auto_editor.utils.log import Log
|
23
|
-
from auto_editor.vanparse import ArgumentParser
|
24
|
-
|
25
|
-
|
26
|
-
@dataclass(slots=True)
|
27
|
-
class TestArgs:
|
28
|
-
only: list[str] = field(default_factory=list)
|
29
|
-
help: bool = False
|
30
|
-
no_fail_fast: bool = False
|
31
|
-
category: str = "cli"
|
32
|
-
|
33
|
-
|
34
|
-
def test_options(parser: ArgumentParser) -> ArgumentParser:
|
35
|
-
parser.add_argument("--only", "-n", nargs="*")
|
36
|
-
parser.add_argument("--no-fail-fast", flag=True)
|
37
|
-
parser.add_required(
|
38
|
-
"category",
|
39
|
-
nargs=1,
|
40
|
-
choices=("palet", "cli", "sub", "all"),
|
41
|
-
metavar="category [options]",
|
42
|
-
)
|
43
|
-
return parser
|
44
|
-
|
45
|
-
|
46
|
-
def pipe_to_console(cmd: list[str]) -> tuple[int, str, str]:
|
47
|
-
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
48
|
-
stdout, stderr = process.communicate()
|
49
|
-
return process.returncode, stdout.decode("utf-8"), stderr.decode("utf-8")
|
50
|
-
|
51
|
-
|
52
|
-
all_files = (
|
53
|
-
"aac.m4a",
|
54
|
-
"alac.m4a",
|
55
|
-
"wav/pcm-f32le.wav",
|
56
|
-
"wav/pcm-s32le.wav",
|
57
|
-
"multi-track.mov",
|
58
|
-
"mov_text.mp4",
|
59
|
-
"testsrc.mkv",
|
60
|
-
)
|
61
|
-
log = Log()
|
62
|
-
|
63
|
-
|
64
|
-
def fileinfo(path: str) -> FileInfo:
|
65
|
-
return FileInfo.init(path, log)
|
66
|
-
|
67
|
-
|
68
|
-
def calculate_sha256(filename: str) -> str:
|
69
|
-
sha256_hash = hashlib.sha256()
|
70
|
-
with open(filename, "rb") as f:
|
71
|
-
for byte_block in iter(lambda: f.read(4096), b""):
|
72
|
-
sha256_hash.update(byte_block)
|
73
|
-
return sha256_hash.hexdigest()
|
74
|
-
|
75
|
-
|
76
|
-
class SkipTest(Exception):
|
77
|
-
pass
|
78
|
-
|
79
|
-
|
80
|
-
class Runner:
|
81
|
-
def __init__(self) -> None:
|
82
|
-
self.program = [sys.executable, "-m", "auto_editor"]
|
83
|
-
self.temp_dir = mkdtemp()
|
84
|
-
|
85
|
-
def main(self, inputs: list[str], cmd: list[str], output: str | None = None) -> str:
|
86
|
-
assert inputs
|
87
|
-
cmd = self.program + inputs + cmd + ["--no-open", "--progress", "none"]
|
88
|
-
temp_dir = self.temp_dir
|
89
|
-
if not os.path.exists(temp_dir):
|
90
|
-
raise ValueError("Where's the temp dir")
|
91
|
-
if output is None:
|
92
|
-
new_root = sha256("".join(cmd).encode()).hexdigest()[:16]
|
93
|
-
output = os.path.join(temp_dir, new_root)
|
94
|
-
else:
|
95
|
-
root, ext = os.path.splitext(output)
|
96
|
-
if inputs and ext == "":
|
97
|
-
output = root + os.path.splitext(inputs[0])[1]
|
98
|
-
output = os.path.join(temp_dir, output)
|
99
|
-
|
100
|
-
returncode, stdout, stderr = pipe_to_console(cmd + ["--output", output])
|
101
|
-
if returncode > 0:
|
102
|
-
raise Exception(f"Test returned: {returncode}\n{stdout}\n{stderr}\n")
|
103
|
-
|
104
|
-
return output
|
105
|
-
|
106
|
-
def raw(self, cmd: list[str]) -> None:
|
107
|
-
returncode, stdout, stderr = pipe_to_console(self.program + cmd)
|
108
|
-
if returncode > 0:
|
109
|
-
raise Exception(f"{stdout}\n{stderr}\n")
|
110
|
-
|
111
|
-
def check(self, cmd: list[str], match=None) -> None:
|
112
|
-
returncode, stdout, stderr = pipe_to_console(self.program + cmd)
|
113
|
-
if returncode > 0:
|
114
|
-
if "Error!" in stderr:
|
115
|
-
if match is not None and match not in stderr:
|
116
|
-
raise Exception(f'Could\'t find "{match}"')
|
117
|
-
else:
|
118
|
-
raise Exception(
|
119
|
-
f"Program crashed but should have shown an error.\n{' '.join(cmd)}\n{stdout}\n{stderr}"
|
120
|
-
)
|
121
|
-
else:
|
122
|
-
raise Exception("Program should not respond with code 0 but did!")
|
123
|
-
|
124
|
-
def test_help(self):
|
125
|
-
"""check the help option, its short, and help on options and groups."""
|
126
|
-
self.raw(["--help"])
|
127
|
-
self.raw(["-h"])
|
128
|
-
self.raw(["--margin", "--help"])
|
129
|
-
self.raw(["--edit", "-h"])
|
130
|
-
self.raw(["--help", "--help"])
|
131
|
-
self.raw(["-h", "--help"])
|
132
|
-
self.raw(["--help", "-h"])
|
133
|
-
|
134
|
-
def test_version(self):
|
135
|
-
"""Test version flags and debug by itself."""
|
136
|
-
self.raw(["--version"])
|
137
|
-
self.raw(["-V"])
|
138
|
-
|
139
|
-
def test_parser(self):
|
140
|
-
self.check(["example.mp4", "--video-speed"], "needs argument")
|
141
|
-
|
142
|
-
def info(self):
|
143
|
-
self.raw(["info", "example.mp4"])
|
144
|
-
self.raw(["info", "resources/only-video/man-on-green-screen.mp4"])
|
145
|
-
self.raw(["info", "resources/multi-track.mov"])
|
146
|
-
self.raw(["info", "resources/new-commentary.mp3"])
|
147
|
-
self.raw(["info", "resources/testsrc.mkv"])
|
148
|
-
|
149
|
-
def levels(self):
|
150
|
-
self.raw(["levels", "resources/multi-track.mov"])
|
151
|
-
self.raw(["levels", "resources/new-commentary.mp3"])
|
152
|
-
|
153
|
-
def subdump(self):
|
154
|
-
self.raw(["subdump", "resources/mov_text.mp4"])
|
155
|
-
self.raw(["subdump", "resources/webvtt.mkv"])
|
156
|
-
|
157
|
-
def desc(self):
|
158
|
-
self.raw(["desc", "example.mp4"])
|
159
|
-
|
160
|
-
def test_movflags(self) -> None:
|
161
|
-
file = "resources/testsrc.mp4"
|
162
|
-
out = self.main([file], ["--faststart"]) + ".mp4"
|
163
|
-
fast = calculate_sha256(out)
|
164
|
-
with bv.open(out) as container:
|
165
|
-
assert isinstance(container.streams[0], bv.VideoStream)
|
166
|
-
assert isinstance(container.streams[1], bv.AudioStream)
|
167
|
-
|
168
|
-
out = self.main([file], ["--no-faststart"]) + ".mp4"
|
169
|
-
nofast = calculate_sha256(out)
|
170
|
-
with bv.open(out) as container:
|
171
|
-
assert isinstance(container.streams[0], bv.VideoStream)
|
172
|
-
assert isinstance(container.streams[1], bv.AudioStream)
|
173
|
-
|
174
|
-
out = self.main([file], ["--fragmented"]) + ".mp4"
|
175
|
-
frag = calculate_sha256(out)
|
176
|
-
with bv.open(out) as container:
|
177
|
-
assert isinstance(container.streams[0], bv.VideoStream)
|
178
|
-
assert isinstance(container.streams[1], bv.AudioStream)
|
179
|
-
|
180
|
-
assert fast != nofast, "+faststart is not being applied"
|
181
|
-
assert frag not in (fast, nofast), "fragmented output should diff."
|
182
|
-
|
183
|
-
def test_example(self) -> None:
|
184
|
-
out = self.main(["example.mp4"], [], output="example_ALTERED.mp4")
|
185
|
-
with bv.open(out) as container:
|
186
|
-
assert container.duration is not None
|
187
|
-
assert container.duration > 17300000 and container.duration < 2 << 24
|
188
|
-
|
189
|
-
assert len(container.streams) == 2
|
190
|
-
video = container.streams[0]
|
191
|
-
audio = container.streams[1]
|
192
|
-
assert isinstance(video, bv.VideoStream)
|
193
|
-
assert isinstance(audio, bv.AudioStream)
|
194
|
-
assert video.base_rate == 30
|
195
|
-
assert video.average_rate is not None
|
196
|
-
assert video.average_rate == 30, video.average_rate
|
197
|
-
assert (video.width, video.height) == (1280, 720)
|
198
|
-
assert video.codec.name == "h264"
|
199
|
-
assert video.language == "eng"
|
200
|
-
assert audio.codec.name == "aac"
|
201
|
-
assert audio.sample_rate == 48000
|
202
|
-
assert audio.language == "eng"
|
203
|
-
assert audio.layout.name == "stereo"
|
204
|
-
|
205
|
-
def test_video_to_mp3(self) -> None:
|
206
|
-
out = self.main(["example.mp4"], [], output="example_ALTERED.mp3")
|
207
|
-
with bv.open(out) as container:
|
208
|
-
assert container.duration is not None
|
209
|
-
assert container.duration > 17300000 and container.duration < 2 << 24
|
210
|
-
|
211
|
-
assert len(container.streams) == 1
|
212
|
-
audio = container.streams[0]
|
213
|
-
assert isinstance(audio, bv.AudioStream)
|
214
|
-
assert audio.codec.name in ("mp3", "mp3float")
|
215
|
-
assert audio.sample_rate == 48000
|
216
|
-
assert audio.layout.name == "stereo"
|
217
|
-
|
218
|
-
def test_to_mono(self) -> None:
|
219
|
-
out = self.main(["example.mp4"], ["-layout", "mono"], output="example_mono.mp4")
|
220
|
-
with bv.open(out) as container:
|
221
|
-
assert container.duration is not None
|
222
|
-
assert container.duration > 17300000 and container.duration < 2 << 24
|
223
|
-
|
224
|
-
assert len(container.streams) == 2
|
225
|
-
video = container.streams[0]
|
226
|
-
audio = container.streams[1]
|
227
|
-
assert isinstance(video, bv.VideoStream)
|
228
|
-
assert isinstance(audio, bv.AudioStream)
|
229
|
-
assert video.base_rate == 30
|
230
|
-
assert video.average_rate is not None
|
231
|
-
assert video.average_rate == 30, video.average_rate
|
232
|
-
assert (video.width, video.height) == (1280, 720)
|
233
|
-
assert video.codec.name == "h264"
|
234
|
-
assert video.language == "eng"
|
235
|
-
assert audio.codec.name == "aac"
|
236
|
-
assert audio.sample_rate == 48000
|
237
|
-
assert audio.language == "eng"
|
238
|
-
assert audio.layout.name == "mono"
|
239
|
-
|
240
|
-
# PR #260
|
241
|
-
def test_high_speed(self):
|
242
|
-
self.check(["example.mp4", "--video-speed", "99998"], "empty")
|
243
|
-
|
244
|
-
# Issue #184
|
245
|
-
def test_units(self):
|
246
|
-
self.main(["example.mp4"], ["--edit", "all/e", "--set-speed", "125%,-30,end"])
|
247
|
-
self.main(["example.mp4"], ["--edit", "audio:threshold=4%"])
|
248
|
-
|
249
|
-
def test_sr_units(self):
|
250
|
-
self.main(["example.mp4"], ["--sample_rate", "44100 Hz"])
|
251
|
-
self.main(["example.mp4"], ["--sample_rate", "44.1 kHz"])
|
252
|
-
|
253
|
-
def test_video_speed(self):
|
254
|
-
self.main(["example.mp4"], ["--video-speed", "1.5"])
|
255
|
-
|
256
|
-
def test_backwards_range(self):
|
257
|
-
"""
|
258
|
-
Cut out the last 5 seconds of a media file by using negative number in the
|
259
|
-
range.
|
260
|
-
"""
|
261
|
-
self.main(["example.mp4"], ["--edit", "none", "--cut_out", "-5secs,end"])
|
262
|
-
self.main(["example.mp4"], ["--edit", "all/e", "--add_in", "-5secs,end"])
|
263
|
-
|
264
|
-
def test_cut_out(self):
|
265
|
-
self.main(
|
266
|
-
["example.mp4"],
|
267
|
-
[
|
268
|
-
"--edit",
|
269
|
-
"none",
|
270
|
-
"--video_speed",
|
271
|
-
"2",
|
272
|
-
"--silent_speed",
|
273
|
-
"3",
|
274
|
-
"--cut_out",
|
275
|
-
"2secs,10secs",
|
276
|
-
],
|
277
|
-
)
|
278
|
-
self.main(
|
279
|
-
["example.mp4"],
|
280
|
-
["--edit", "all/e", "--video_speed", "2", "--add_in", "2secs,10secs"],
|
281
|
-
)
|
282
|
-
|
283
|
-
def test_gif(self):
|
284
|
-
"""
|
285
|
-
Feed auto-editor a gif file and make sure it can spit out a correctly formatted
|
286
|
-
gif. No editing is requested.
|
287
|
-
"""
|
288
|
-
input = ["resources/only-video/man-on-green-screen.gif"]
|
289
|
-
out = self.main(input, ["--edit", "none", "--cut-out", "2sec,end"], "out.gif")
|
290
|
-
assert fileinfo(out).videos[0].codec == "gif"
|
291
|
-
|
292
|
-
def test_margin(self):
|
293
|
-
self.main(["example.mp4"], ["-m", "3"])
|
294
|
-
self.main(["example.mp4"], ["-m", "0.3sec"])
|
295
|
-
self.main(["example.mp4"], ["-m", "0.1 seconds"])
|
296
|
-
self.main(["example.mp4"], ["-m", "6,-3secs"])
|
297
|
-
|
298
|
-
def test_input_extension(self):
|
299
|
-
"""Input file must have an extension. Throw error if none is given."""
|
300
|
-
path = os.path.join(self.temp_dir, "example")
|
301
|
-
shutil.copy("example.mp4", path)
|
302
|
-
self.check([path, "--no-open"], "must have an extension")
|
303
|
-
|
304
|
-
def test_silent_threshold(self):
|
305
|
-
with bv.open("resources/new-commentary.mp3") as container:
|
306
|
-
assert container.duration is not None
|
307
|
-
assert container.duration / bv.time_base == 6.732
|
308
|
-
|
309
|
-
out = self.main(
|
310
|
-
["resources/new-commentary.mp3"], ["--edit", "audio:threshold=0.1"]
|
311
|
-
)
|
312
|
-
out += ".mp3"
|
313
|
-
|
314
|
-
with bv.open(out) as container:
|
315
|
-
assert container.duration is not None
|
316
|
-
assert container.duration / bv.time_base == 6.552
|
317
|
-
|
318
|
-
def test_track(self):
|
319
|
-
out = self.main(["resources/multi-track.mov"], []) + ".mov"
|
320
|
-
assert len(fileinfo(out).audios) == 2
|
321
|
-
|
322
|
-
def test_export_json(self):
|
323
|
-
out = self.main(["example.mp4"], ["--export", "v1"], "c77130d763d40e8.json")
|
324
|
-
self.main([out], [])
|
325
|
-
out = self.main(["example.mp4"], ["--export", "v1"], "c77130d763d40e8.v1")
|
326
|
-
self.main([out], [])
|
327
|
-
|
328
|
-
def test_import_v1(self):
|
329
|
-
path = os.path.join(self.temp_dir, "v1.json")
|
330
|
-
with open(path, "w") as file:
|
331
|
-
file.write(
|
332
|
-
"""{"version": "1", "source": "example.mp4", "chunks": [ [0, 26, 1.0], [26, 34, 0] ]}"""
|
333
|
-
)
|
334
|
-
|
335
|
-
self.main([path], [])
|
336
|
-
|
337
|
-
def test_res_with_v1(self):
|
338
|
-
v1 = self.main(["example.mp4"], ["--export", "v1"], "input.v1")
|
339
|
-
out = self.main([v1], ["-res", "720,720"], "output.mp4")
|
340
|
-
|
341
|
-
output = fileinfo(out)
|
342
|
-
assert output.videos[0].width == 720
|
343
|
-
assert output.videos[0].height == 720
|
344
|
-
assert len(output.audios) == 1
|
345
|
-
|
346
|
-
def test_premiere_named_export(self) -> None:
|
347
|
-
self.main(["example.mp4"], ["--export", 'premiere:name="Foo Bar"'])
|
348
|
-
|
349
|
-
def test_export_subtitles(self) -> None:
|
350
|
-
# cn = fileinfo(self.main(["resources/mov_text.mp4"], [], "movtext_out.mp4"))
|
351
|
-
|
352
|
-
# assert len(cn.videos) == 1
|
353
|
-
# assert len(cn.audios) == 1
|
354
|
-
# assert len(cn.subtitles) == 1
|
355
|
-
|
356
|
-
cn = fileinfo(self.main(["resources/webvtt.mkv"], [], "webvtt_out.mkv"))
|
357
|
-
assert len(cn.videos) == 1
|
358
|
-
assert len(cn.audios) == 1
|
359
|
-
assert len(cn.subtitles) == 1
|
360
|
-
|
361
|
-
def test_scale(self) -> None:
|
362
|
-
cn = fileinfo(self.main(["example.mp4"], ["--scale", "1.5"], "scale.mp4"))
|
363
|
-
assert cn.videos[0].fps == 30
|
364
|
-
assert cn.videos[0].width == 1920
|
365
|
-
assert cn.videos[0].height == 1080
|
366
|
-
assert cn.audios[0].samplerate == 48000
|
367
|
-
|
368
|
-
cn = fileinfo(self.main(["example.mp4"], ["--scale", "0.2"], "scale.mp4"))
|
369
|
-
assert cn.videos[0].fps == 30
|
370
|
-
assert cn.videos[0].width == 256
|
371
|
-
assert cn.videos[0].height == 144
|
372
|
-
assert cn.audios[0].samplerate == 48000
|
373
|
-
|
374
|
-
def test_resolution(self):
|
375
|
-
out = self.main(
|
376
|
-
["example.mp4"], ["-res", "700,380", "-b", "darkgreen"], "green"
|
377
|
-
)
|
378
|
-
cn = fileinfo(out)
|
379
|
-
|
380
|
-
assert cn.videos[0].fps == 30
|
381
|
-
assert cn.videos[0].width == 700
|
382
|
-
assert cn.videos[0].height == 380
|
383
|
-
assert cn.audios[0].samplerate == 48000
|
384
|
-
|
385
|
-
# def test_premiere_multi(self):
|
386
|
-
# p_xml = self.main([f"resources/multi-track.mov"], ["-exp"], "multi.xml")
|
387
|
-
|
388
|
-
# cn = fileinfo(self.main([p_xml], []))
|
389
|
-
# assert len(cn.videos) == 1
|
390
|
-
# assert len(cn.audios) == 2
|
391
|
-
|
392
|
-
def test_premiere(self) -> None:
|
393
|
-
for test_name in all_files:
|
394
|
-
if test_name == "multi-track.mov":
|
395
|
-
continue
|
396
|
-
|
397
|
-
p_xml = self.main([f"resources/{test_name}"], ["-exp"], "out.xml")
|
398
|
-
self.main([p_xml], [])
|
399
|
-
|
400
|
-
def test_export(self):
|
401
|
-
for test_name in all_files:
|
402
|
-
test_file = f"resources/{test_name}"
|
403
|
-
self.main([test_file], ["--export", "final-cut-pro:version=10"])
|
404
|
-
self.main([test_file], ["--export", "final-cut-pro:version=11"])
|
405
|
-
self.main([test_file], ["-exs"])
|
406
|
-
self.main([test_file], ["--stats"])
|
407
|
-
|
408
|
-
def test_clip_sequence(self) -> None:
|
409
|
-
for test_name in all_files:
|
410
|
-
test_file = f"resources/{test_name}"
|
411
|
-
self.main([test_file], ["--export", "clip-sequence"])
|
412
|
-
|
413
|
-
def test_codecs(self) -> None:
|
414
|
-
self.main(["example.mp4"], ["--video-codec", "h264"])
|
415
|
-
self.main(["example.mp4"], ["--audio-codec", "ac3"])
|
416
|
-
|
417
|
-
# Issue #241
|
418
|
-
def test_multi_track_edit(self):
|
419
|
-
out = self.main(
|
420
|
-
["example.mp4", "resources/multi-track.mov"],
|
421
|
-
["--edit", "audio:stream=1"],
|
422
|
-
"multi-track_ALTERED.mov",
|
423
|
-
)
|
424
|
-
assert len(fileinfo(out).audios) == 2
|
425
|
-
|
426
|
-
def test_concat(self):
|
427
|
-
out = self.main(["example.mp4"], ["--cut-out", "0,171"], "hmm.mp4")
|
428
|
-
self.main(["example.mp4", out], ["--debug"])
|
429
|
-
|
430
|
-
def test_concat_mux_tracks(self):
|
431
|
-
inputs = ["example.mp4", "resources/multi-track.mov"]
|
432
|
-
out = self.main(inputs, ["--mix-audio-streams"], "concat_mux.mov")
|
433
|
-
assert len(fileinfo(out).audios) == 1
|
434
|
-
|
435
|
-
def test_concat_multi_tracks(self):
|
436
|
-
out = self.main(
|
437
|
-
["resources/multi-track.mov", "resources/multi-track.mov"], [], "out.mov"
|
438
|
-
)
|
439
|
-
assert len(fileinfo(out).audios) == 2
|
440
|
-
inputs = ["example.mp4", "resources/multi-track.mov"]
|
441
|
-
out = self.main(inputs, [], "out.mov")
|
442
|
-
assert len(fileinfo(out).audios) == 2
|
443
|
-
|
444
|
-
def test_frame_rate(self):
|
445
|
-
cn = fileinfo(self.main(["example.mp4"], ["-r", "15", "--no-seek"], "fr.mp4"))
|
446
|
-
video = cn.videos[0]
|
447
|
-
assert video.fps == 15, video.fps
|
448
|
-
assert video.duration - 17.33333333333333333333333 < 3, video.duration
|
449
|
-
|
450
|
-
cn = fileinfo(self.main(["example.mp4"], ["-r", "20"], "fr.mp4"))
|
451
|
-
video = cn.videos[0]
|
452
|
-
assert video.fps == 20, video.fps
|
453
|
-
assert video.duration - 17.33333333333333333333333 < 2
|
454
|
-
|
455
|
-
def test_frame_rate_60(self):
|
456
|
-
cn = fileinfo(self.main(["example.mp4"], ["-r", "60"], "fr60.mp4"))
|
457
|
-
video = cn.videos[0]
|
458
|
-
|
459
|
-
assert video.fps == 60, video.fps
|
460
|
-
assert video.duration - 17.33333333333333333333333 < 0.3
|
461
|
-
|
462
|
-
# def embedded_image(self):
|
463
|
-
# out1 = self.main(["resources/embedded-image/h264-png.mp4"], [])
|
464
|
-
# cn = fileinfo(out1)
|
465
|
-
# assert cn.videos[0].codec == "h264"
|
466
|
-
# assert cn.videos[1].codec == "png"
|
467
|
-
|
468
|
-
# out2 = self.main(["resources/embedded-image/h264-mjpeg.mp4"], [])
|
469
|
-
# cn = fileinfo(out2)
|
470
|
-
# assert cn.videos[0].codec == "h264"
|
471
|
-
# assert cn.videos[1].codec == "mjpeg"
|
472
|
-
|
473
|
-
# out3 = self.main(["resources/embedded-image/h264-png.mkv"], [])
|
474
|
-
# cn = fileinfo(out3)
|
475
|
-
# assert cn.videos[0].codec == "h264"
|
476
|
-
# assert cn.videos[1].codec == "png"
|
477
|
-
|
478
|
-
# out4 = self.main(["resources/embedded-image/h264-mjpeg.mkv"], [])
|
479
|
-
# cn = fileinfo(out4)
|
480
|
-
# assert cn.videos[0].codec == "h264"
|
481
|
-
# assert cn.videos[1].codec == "mjpeg"
|
482
|
-
|
483
|
-
def test_motion(self):
|
484
|
-
self.main(
|
485
|
-
["resources/only-video/man-on-green-screen.mp4"],
|
486
|
-
["--edit", "motion", "--margin", "0"],
|
487
|
-
)
|
488
|
-
self.main(
|
489
|
-
["resources/only-video/man-on-green-screen.mp4"],
|
490
|
-
["--edit", "motion:threshold=0,width=200"],
|
491
|
-
)
|
492
|
-
|
493
|
-
def test_edit_positive(self):
|
494
|
-
self.main(["resources/multi-track.mov"], ["--edit", "audio:stream=all"])
|
495
|
-
self.main(["resources/multi-track.mov"], ["--edit", "not audio:stream=all"])
|
496
|
-
self.main(
|
497
|
-
["resources/multi-track.mov"],
|
498
|
-
["--edit", "(or (not audio:threshold=4%) audio:stream=1)"],
|
499
|
-
)
|
500
|
-
self.main(
|
501
|
-
["resources/multi-track.mov"],
|
502
|
-
["--edit", "(or (not audio:threshold=4%) (not audio:stream=1))"],
|
503
|
-
)
|
504
|
-
|
505
|
-
def test_edit_negative(self):
|
506
|
-
self.check(
|
507
|
-
["resources/wav/example-cut-s16le.wav", "--edit", "motion"],
|
508
|
-
"video stream",
|
509
|
-
)
|
510
|
-
self.check(
|
511
|
-
["resources/only-video/man-on-green-screen.gif", "--edit", "audio"],
|
512
|
-
"audio stream",
|
513
|
-
)
|
514
|
-
|
515
|
-
def test_yuv442p(self):
|
516
|
-
self.main(["resources/test_yuv422p.mp4"], [])
|
517
|
-
|
518
|
-
def test_prores(self):
|
519
|
-
out = self.main(["resources/testsrc.mp4"], ["-c:v", "prores"], "prores.mkv")
|
520
|
-
assert fileinfo(out).videos[0].pix_fmt == "yuv422p10le"
|
521
|
-
|
522
|
-
out2 = self.main([out], ["-c:v", "prores"], "prores2.mkv")
|
523
|
-
assert fileinfo(out2).videos[0].pix_fmt == "yuv422p10le"
|
524
|
-
|
525
|
-
def test_decode_hevc(self):
|
526
|
-
out = self.main(["resources/testsrc-hevc.mp4"], ["-c:v", "h264"]) + ".mp4"
|
527
|
-
output = fileinfo(out)
|
528
|
-
assert output.videos[0].codec == "h264"
|
529
|
-
assert output.videos[0].pix_fmt == "yuv420p"
|
530
|
-
|
531
|
-
def test_encode_hevc(self):
|
532
|
-
out = self.main(["resources/testsrc.mp4"], ["-c:v", "hevc"], "out.mkv")
|
533
|
-
output = fileinfo(out)
|
534
|
-
assert output.videos[0].codec == "hevc"
|
535
|
-
assert output.videos[0].pix_fmt == "yuv420p"
|
536
|
-
|
537
|
-
# Issue 280
|
538
|
-
def test_SAR(self) -> None:
|
539
|
-
out = self.main(["resources/SAR-2by3.mp4"], [], "2by3_out.mp4")
|
540
|
-
assert fileinfo(out).videos[0].sar == Fraction(2, 3)
|
541
|
-
|
542
|
-
def test_audio_norm_f(self) -> None:
|
543
|
-
self.main(["example.mp4"], ["--audio-normalize", "#f"])
|
544
|
-
|
545
|
-
def test_audio_norm_ebu(self) -> None:
|
546
|
-
self.main(
|
547
|
-
["example.mp4"], ["--audio-normalize", "ebu:i=-5,lra=20,gain=5,tp=-1"]
|
548
|
-
)
|
549
|
-
|
550
|
-
def palet_python_bridge(self):
|
551
|
-
env.update(make_standard_env())
|
552
|
-
|
553
|
-
def cases(*cases: tuple[str, object]) -> None:
|
554
|
-
for text, expected in cases:
|
555
|
-
try:
|
556
|
-
parser = Parser(Lexer("repl", text))
|
557
|
-
env["timebase"] = Fraction(30)
|
558
|
-
results = interpret(env, parser)
|
559
|
-
except MyError as e:
|
560
|
-
raise ValueError(f"{text}\nMyError: {e}")
|
561
|
-
|
562
|
-
result_val = results[-1]
|
563
|
-
if isinstance(expected, np.ndarray):
|
564
|
-
if not isinstance(result_val, np.ndarray):
|
565
|
-
raise ValueError(f"{text}: Result is not an ndarray")
|
566
|
-
if not np.array_equal(expected, result_val):
|
567
|
-
raise ValueError(f"{text}: Numpy arrays don't match")
|
568
|
-
elif expected != result_val:
|
569
|
-
raise ValueError(f"{text}: Expected: {expected}, got {result_val}")
|
570
|
-
|
571
|
-
cases(
|
572
|
-
("345", 345),
|
573
|
-
("238.5", 238.5),
|
574
|
-
("-34", -34),
|
575
|
-
("-98.3", -98.3),
|
576
|
-
("3sec", 90),
|
577
|
-
("-3sec", -90),
|
578
|
-
("0.2sec", 6),
|
579
|
-
("(+ 4 3)", 7),
|
580
|
-
("(+ 4 3 2)", 9),
|
581
|
-
("(+ 10.5 3)", 13.5),
|
582
|
-
("(- 4 3)", 1),
|
583
|
-
("(- 3)", -3),
|
584
|
-
("(- 10.5 3)", 7.5),
|
585
|
-
("(* 11.5 3)", 34.5),
|
586
|
-
("(/ 3/4 4)", Fraction(3, 16)),
|
587
|
-
("(/ 5)", 0.2),
|
588
|
-
("(/ 6 1)", 6.0),
|
589
|
-
("30/1", Fraction(30)),
|
590
|
-
("(pow 2 3)", 8),
|
591
|
-
("(pow 4 0.5)", 2.0),
|
592
|
-
("(abs 1.0)", 1.0),
|
593
|
-
("(abs -1)", 1),
|
594
|
-
("(bool? #t)", True),
|
595
|
-
("(bool? #f)", True),
|
596
|
-
("(bool? 0)", False),
|
597
|
-
("(bool? 1)", False),
|
598
|
-
("(bool? false)", True),
|
599
|
-
("(int? 2)", True),
|
600
|
-
("(int? 3.0)", False),
|
601
|
-
("(int? #t)", False),
|
602
|
-
("(int? #f)", False),
|
603
|
-
("(int? 4/5)", False),
|
604
|
-
('(int? "hello")', False),
|
605
|
-
('(int? "3")', False),
|
606
|
-
("(float? -23.4)", True),
|
607
|
-
("(float? 3.0)", True),
|
608
|
-
("(float? #f)", False),
|
609
|
-
("(float? 4/5)", False),
|
610
|
-
("(float? 21)", False),
|
611
|
-
("(frac? 4/5)", True),
|
612
|
-
("(frac? 3.4)", False),
|
613
|
-
('(& "Hello" " World")', "Hello World"),
|
614
|
-
('(define apple "Red Wood") apple', "Red Wood"),
|
615
|
-
("(= 1 1.0)", True),
|
616
|
-
("(= 1 2)", False),
|
617
|
-
("(= 1)", True),
|
618
|
-
("(+)", 0),
|
619
|
-
("(*)", 1),
|
620
|
-
('(define num 13) ; Set number to 13\n"Hello"', "Hello"),
|
621
|
-
('(if #t "Hello" apple)', "Hello"),
|
622
|
-
('(if #f mango "Hi")', "Hi"),
|
623
|
-
('{if (= [+ 3 4] 7) "yes" "no"}', "yes"),
|
624
|
-
("((if #t + -) 3 4)", 7),
|
625
|
-
("((if #f + -) 3 4)", -1),
|
626
|
-
("(when (positive? 3) 17)", 17),
|
627
|
-
("(string)", ""),
|
628
|
-
("(string #\\a)", "a"),
|
629
|
-
("(string #\\a #\\b)", "ab"),
|
630
|
-
("(string #\\a #\\b #\\c)", "abc"),
|
631
|
-
(
|
632
|
-
"(margin (bool-array 0 0 0 1 0 0 0) 0)",
|
633
|
-
np.array([0, 0, 0, 1, 0, 0, 0], dtype=np.bool_),
|
634
|
-
),
|
635
|
-
(
|
636
|
-
"(margin (bool-array 0 0 1 1 0 0 0) -2 2)",
|
637
|
-
np.array([0, 0, 0, 0, 1, 1, 0], dtype=np.bool_),
|
638
|
-
),
|
639
|
-
("(equal? 3 3)", True),
|
640
|
-
("(equal? 3 3.0)", False),
|
641
|
-
('(equal? 16.3 "Editor")', False),
|
642
|
-
("(equal? (bool-array 1 1 0) (bool-array 1 1 0))", True),
|
643
|
-
("(equal? (bool-array 0 1 0) (bool-array 1 1 0))", False),
|
644
|
-
("(equal? (bool-array 0 1 0) (bool-array 0 1 0 0))", False),
|
645
|
-
("(equal? #\\a #\\a)", True),
|
646
|
-
('(equal? "a" #\\a)', False),
|
647
|
-
("(equal? (vector 1 2 3) (vector 1 2 3))", True),
|
648
|
-
(
|
649
|
-
"(or (bool-array 1 0 0) (bool-array 0 0 0 1))",
|
650
|
-
np.array([1, 0, 0, 1], dtype=np.bool_),
|
651
|
-
),
|
652
|
-
("(len (vector 1 2 4))", 3),
|
653
|
-
("(len #(1 2 4))", 3),
|
654
|
-
("(len (bool-array 0 1 0))", 3),
|
655
|
-
("(equal? (reverse #(0 1 2)) #(2 1 0))", True),
|
656
|
-
("(equal? (reverse (vector 0 1 2)) (vector 2 1 0))", True),
|
657
|
-
('(ref "Zyx" 1)', Char("y")),
|
658
|
-
("(ref (vector 0.3 #\\a 2) 2)", 2),
|
659
|
-
("(ref (range 0 10) 2)", 2),
|
660
|
-
("((range 0 10) 2)", 2),
|
661
|
-
("((vector 0.3 #\\a 17) 2)", 17),
|
662
|
-
("(#(0.3 #\\a 17) 2)", 17),
|
663
|
-
("(begin)", None),
|
664
|
-
("(void)", None),
|
665
|
-
("(begin (define r 10) (* 3.14 (* r r)))", 314.0),
|
666
|
-
("#(-20dB 0dB 20dB)", [0.1, 1, 10]),
|
667
|
-
("(define ca (lambda (r) (* 3.14 (* r r)))) (ca 5)", 78.5),
|
668
|
-
(
|
669
|
-
"(define ca (lambda (r) (void) (* 3.14 (* r r)))) (ca 5)",
|
670
|
-
78.5,
|
671
|
-
),
|
672
|
-
("(define (my-pow2 a) (* a a)) (my-pow2 30)", 900),
|
673
|
-
("(define (my-pow2 a) (void) (* a a)) (my-pow2 30)", 900),
|
674
|
-
("(~a 3 4 'a)", "34a"),
|
675
|
-
("(~s 3 4 'a)", "3 4 a"),
|
676
|
-
("(~v 3 4 'a)", "3 4 'a"),
|
677
|
-
("(define (my-func x) (define (inner) 4) (+ x (inner))) (my-func 16)", 20),
|
678
|
-
("(define (text child ...) child)", None),
|
679
|
-
("(text)", []),
|
680
|
-
("(text 1)", [1]),
|
681
|
-
("(text 2 1)", [2, 1]),
|
682
|
-
("(text 3 2 1)", [3, 2, 1]),
|
683
|
-
("((or/c 0 1) 1)", True),
|
684
|
-
("((or/c 0 1) 2)", False),
|
685
|
-
("((or/c 0 1) 1)", True),
|
686
|
-
('((or/c 0 1 string?) "hello")', True),
|
687
|
-
("((or/c 0 1 string?) 3)", False),
|
688
|
-
('"hello".title', "Hello"),
|
689
|
-
('"hello".upper', "HELLO"),
|
690
|
-
('"heLlo".lower', "hello"),
|
691
|
-
('(define s "hello")s.title', "Hello"),
|
692
|
-
("(define v #(2 0 3 -4 -2 5 1 4)) v.sort", [-4, -2, 0, 1, 2, 3, 4, 5]),
|
693
|
-
("(define v #(2 0 3 -4 -2 5 1 4)) v.sort! v", [-4, -2, 0, 1, 2, 3, 4, 5]),
|
694
|
-
('#(#("sym" "symbol?") "bool?")', [["sym", "symbol?"], "bool?"]),
|
695
|
-
)
|
696
|
-
|
697
|
-
def palet_scripts(self) -> None:
|
698
|
-
self.raw(["palet", "resources/scripts/scope.pal"])
|
699
|
-
self.raw(["palet", "resources/scripts/maxcut.pal"])
|
700
|
-
self.raw(["palet", "resources/scripts/case.pal"])
|
701
|
-
self.raw(["palet", "resources/scripts/testmath.pal"])
|
702
|
-
|
703
|
-
|
704
|
-
def run_tests(tests: list[Callable], args: TestArgs) -> None:
|
705
|
-
if args.only != []:
|
706
|
-
tests = list(filter(lambda t: t.__name__ in args.only, tests))
|
707
|
-
|
708
|
-
total_time = 0.0
|
709
|
-
real_time = perf_counter()
|
710
|
-
passed = 0
|
711
|
-
total = len(tests)
|
712
|
-
|
713
|
-
def timed_test(test_func):
|
714
|
-
start_time = perf_counter()
|
715
|
-
skipped = False
|
716
|
-
try:
|
717
|
-
test_func()
|
718
|
-
success = True
|
719
|
-
except SkipTest:
|
720
|
-
skipped = True
|
721
|
-
except Exception as e:
|
722
|
-
success = False
|
723
|
-
exception = e
|
724
|
-
end_time = perf_counter()
|
725
|
-
duration = end_time - start_time
|
726
|
-
|
727
|
-
if skipped:
|
728
|
-
return (SkipTest, duration, None)
|
729
|
-
elif success:
|
730
|
-
return (True, duration, None)
|
731
|
-
else:
|
732
|
-
return (False, duration, exception)
|
733
|
-
|
734
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
735
|
-
future_to_data = {}
|
736
|
-
for test in tests:
|
737
|
-
future = executor.submit(timed_test, test)
|
738
|
-
future_to_data[future] = test
|
739
|
-
|
740
|
-
index = 0
|
741
|
-
for future in concurrent.futures.as_completed(future_to_data):
|
742
|
-
test = future_to_data[future]
|
743
|
-
name = test.__name__
|
744
|
-
success, dur, exception = future.result()
|
745
|
-
total_time += dur
|
746
|
-
index += 1
|
747
|
-
|
748
|
-
msg = f"{name:<26} ({index}/{total}) {round(dur, 2):<5} secs "
|
749
|
-
if success == SkipTest:
|
750
|
-
passed += 1
|
751
|
-
print(f"{msg}[\033[38;2;125;125;125;mSKIPPED\033[0m]", flush=True)
|
752
|
-
elif success:
|
753
|
-
passed += 1
|
754
|
-
print(f"{msg}[\033[1;32mPASSED\033[0m]", flush=True)
|
755
|
-
else:
|
756
|
-
print(f"{msg}\033[1;31m[FAILED]\033[0m", flush=True)
|
757
|
-
if args.no_fail_fast:
|
758
|
-
print(f"\n{exception}")
|
759
|
-
else:
|
760
|
-
print("")
|
761
|
-
raise exception
|
762
|
-
|
763
|
-
real_time = round(perf_counter() - real_time, 2)
|
764
|
-
total_time = round(total_time, 2)
|
765
|
-
print(
|
766
|
-
f"\nCompleted {passed}/{total}\nreal time: {real_time} secs total: {total_time} secs"
|
767
|
-
)
|
768
|
-
|
769
|
-
|
770
|
-
def main(sys_args: list[str] | None = None) -> None:
|
771
|
-
if sys_args is None:
|
772
|
-
sys_args = sys.argv[1:]
|
773
|
-
|
774
|
-
args = test_options(ArgumentParser("test")).parse_args(TestArgs, sys_args)
|
775
|
-
run = Runner()
|
776
|
-
tests = []
|
777
|
-
|
778
|
-
test_methods = {
|
779
|
-
name: getattr(run, name)
|
780
|
-
for name in dir(Runner)
|
781
|
-
if callable(getattr(Runner, name)) and name not in ["main", "raw", "check"]
|
782
|
-
}
|
783
|
-
|
784
|
-
if args.category in {"palet", "all"}:
|
785
|
-
tests.extend(
|
786
|
-
[test_methods[name] for name in ["palet_python_bridge", "palet_scripts"]]
|
787
|
-
)
|
788
|
-
|
789
|
-
if args.category in {"sub", "all"}:
|
790
|
-
tests.extend(
|
791
|
-
[test_methods[name] for name in ["info", "levels", "subdump", "desc"]]
|
792
|
-
)
|
793
|
-
|
794
|
-
if args.category in {"cli", "all"}:
|
795
|
-
tests.extend(
|
796
|
-
[
|
797
|
-
getattr(run, name)
|
798
|
-
for name in dir(Runner)
|
799
|
-
if callable(getattr(Runner, name)) and name.startswith("test_")
|
800
|
-
]
|
801
|
-
)
|
802
|
-
try:
|
803
|
-
run_tests(tests, args)
|
804
|
-
except KeyboardInterrupt:
|
805
|
-
print("Testing Interrupted by User.")
|
806
|
-
shutil.rmtree(run.temp_dir)
|
807
|
-
sys.exit(1)
|
808
|
-
shutil.rmtree(run.temp_dir)
|
809
|
-
|
810
|
-
|
811
|
-
if __name__ == "__main__":
|
812
|
-
main()
|