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