This repository was archived by the owner on Apr 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
executable file
·116 lines (95 loc) · 3.96 KB
/
update.py
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
#!/usr/bin/env python
"""
Sungle utility to fetch ffmpeg releases and generate dockerfile for each
"""
import os
import sys
import re
import urllib2
from distutils.version import StrictVersion
MIN_VERSION = "2.8"
VARIANT = "ubuntu"
FFMPEG_RELEASES = "https://ffmpeg.org/releases/"
travis = []
azure = []
# Get latest release from ffmpeg.org
response = urllib2.urlopen(FFMPEG_RELEASES)
ffmpeg_releases = response.read()
parse_re = re.compile("ffmpeg-([.0-9]+).tar.bz2.asc<\/a>\s+")
all_versions = parse_re.findall(ffmpeg_releases)
all_versions.sort(key=StrictVersion, reverse=True)
version, all_versions = all_versions[0], all_versions[1:]
last = version.split(".")
keep_version = ["snapshot"]
keep_version.append(version)
for cur in all_versions:
if cur < MIN_VERSION:
break
tmp = cur.split(".")
# Check Minor
if len(tmp) >= 2 and tmp[1].isdigit() and tmp[1] < last[1]:
keep_version.append(cur)
last = tmp
# Check Major
elif len(tmp) > 1 and tmp[0].isdigit() and tmp[0] < last[0]:
keep_version.append(cur)
last = tmp
for version in keep_version:
if version == "snapshot":
dockerfile = "docker-images/%s/Dockerfile" % version
travis.append(" - VERSION=%s" % version)
azure.append(
" %s:\n VERSION: %s\n" % (version.replace(".", "_"), version)
)
else:
dockerfile = "docker-images/%s/Dockerfile" % (version[0:3])
travis.append(" - VERSION=%s" % (version[0:3]))
azure.append(
" %s:\n VERSION: %s\n "
% (version[0:3].replace(".", "_"), version[0:3])
)
with open("templates/Dockerfile-env", "r") as tmpfile:
env_content = tmpfile.read()
with open("templates/Dockerfile-template." + VARIANT, "r") as tmpfile:
template = tmpfile.read()
with open("templates/Dockerfile-run", "r") as tmpfile:
run_content = tmpfile.read()
env_content = env_content.replace("%%FFMPEG_VERSION%%", version)
docker_content = template.replace("%%ENV%%", env_content)
docker_content = docker_content.replace("%%RUN%%", run_content)
# OpenJpeg 2.1 is not supported in 2.8
if version[0:3] == "2.8":
docker_content = docker_content.replace("--enable-libopenjpeg", "")
docker_content = docker_content.replace("--enable-libkvazaar", "")
if (version != "snapshot" and version[0:3] != "4.0") or VARIANT == "centos":
docker_content = re.sub(r"--enable-libaom [^\\]*", "", docker_content)
if (version == "snapshot" or version[0] >= "3") and VARIANT == "vaapi":
docker_content = docker_content.replace(
"--disable-ffplay", "--disable-ffplay \\\n --enable-vaapi"
)
# FFmpeg 3.2 and earlier don't compile correctly on Ubuntu 18.04 due to openssl issues
if version[0] < "3" or (version[0] == "3" and version[2] < "3"):
docker_content = docker_content.replace("ubuntu:18.04", "ubuntu:16.04")
docker_content = docker_content.replace("libva-drm2", "libva-drm1")
docker_content = docker_content.replace("libva2", "libva1")
patch = ""
if version[0:3] == "4.0":
with open("templates/Dockerfile-patch-4.0", "r") as tmpfile:
patch = tmpfile.read()
docker_content = docker_content.replace("%%FFMPEG_PATCH%%", patch)
d = os.path.dirname(dockerfile)
if not os.path.exists(d):
os.makedirs(d)
with open(dockerfile, "w") as dfile:
dfile.write(docker_content)
# generate CI helpers for the current versions
with open("templates/travis.template", "r") as templatetravis:
template = templatetravis.read()
travis = template.replace("%%VERSIONS%%", "\n".join(travis))
with open(".travis.yml", "w") as travisfile:
travisfile.write(travis)
with open("templates/azure.template", "r") as templateazure:
template = templateazure.read()
azure = template.replace("%%VERSIONS%%", "\n".join(azure))
with open("azure-pipelines.yml", "w") as azurefile:
azurefile.write(azure)