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
|
#!/usr/bin/env python3
import os
import re
import shlex
import shutil
import subprocess
from sys import stderr
cmds = {}
class CheckError(Exception):
pass
def checking(thing):
stderr.write("checking %s... " % thing)
stderr.flush()
def check(name, flags=[], optional=False, var=None, run=True):
checking("for %s" % name)
var = var or name.upper()
split = shlex.split(os.getenv(var) or name)
exe = shutil.which(split[0])
if not exe:
stderr.write("not found\n")
if not optional:
raise CheckError()
stderr.write("%s\n" % exe)
cmd = [exe] + split[1:] + flags + shlex.split(os.getenv(var + "FLAGS") or "")
if run:
checking("%s usability" % exe)
try:
subprocess.check_call(cmd + ["-h"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
stderr.write("yes\n")
except subprocess.CalledProcessError as e:
raise CheckError() from e
cmds[var] = cmd
return cmd
def run_ffmpeg(arg):
return subprocess.check_output(ffmpeg + [arg], stderr=subprocess.STDOUT).decode('utf-8')
def ffmpeg_check(name, regex, checks, output):
for check in checks:
checking("if %s supports %s %s" % (ffmpeg[0], name, check))
if re.search("\n %s %s " % (regex, check), output):
stderr.write("yes\n")
else:
stderr.write("no\n")
raise CheckError()
try:
check("zopfli", var="GZIP")
except CheckError:
check("gzip", ["-9"])
check("apngasm", run=False)
check("convert")
check("cwebp", ["-quiet", "-alpha_cleanup", "-m", "6"])
ffmpeg = check("ffmpeg", ["-v", "warning", "-y"], run=False)
ffmpeg_formats = run_ffmpeg("-formats")
ffmpeg_check("demuxing", "D.", ["matroska,webm", "ogg", "wav", "yuv4mpegpipe"], ffmpeg_formats)
ffmpeg_check("muxing", ".E", ["ipod", "mp4", "ogg", "wav", "webm", "yuv4mpegpipe"], ffmpeg_formats)
ffmpeg_check("decoding", ".{6}", ["mpeg4", "rawvideo", "pcm_s16le", "vorbis"], run_ffmpeg("-decoders"))
ffmpeg_check("encoding", ".{6}", ["libx264", "rawvideo", "libtheora", "libvpx", "libvpx-vp9", "libfdk_aac", "libopus", "pcm_s16le"], run_ffmpeg("-encoders"))
check("npm", ["--quiet"])
check("webpmux")
check("defluff", optional=True, run=False)
check("pngquant", optional=True)
check("zopflipng", optional=True)
stderr.write("creating Makefile.inc\n")
with open("Makefile.inc", "w") as f:
f.write(''.join('%s := %s\n' % (k, subprocess.list2cmdline(cmds[k])) for k in cmds))
|