This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
forked from jrottenberg/ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·143 lines (118 loc) · 5.23 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
import os
import sys
import re
import urllib.request, urllib.error, urllib.parse
from distutils.version import StrictVersion
MIN_VERSION = "2.8"
# https://ffmpeg.org/olddownload.html
SKIP_VERSIONS = "3.1.11 3.0.12"
VARIANTS = ["ubuntu", "alpine", "centos", "scratch", "vaapi", "nvidia"]
FFMPEG_RELEASES = "https://ffmpeg.org/releases/"
gitlabci = []
azure = []
# Get latest release from ffmpeg.org
with urllib.request.urlopen(FFMPEG_RELEASES) as conn:
ffmpeg_releases = conn.read().decode("utf-8")
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
if cur in SKIP_VERSIONS:
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:
for variant in VARIANTS:
if version != "snapshot":
short_version = version[0:3]
else:
short_version = version
dockerfile = "docker-images/%s/%s/Dockerfile" % (short_version, variant)
gitlabci.append(
f"""
{version}-{variant}:
extends: .docker
stage: {variant}
variables:
VERSION: "{short_version}"
VARIANT: {variant}
"""
)
azure.append(
" %s_%s:\n VERSION: %s\n VARIANT: %s"
% (short_version.replace(".", "_"), variant, short_version, variant)
)
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] < "4") 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"
)
if variant == "nvidia":
docker_content = docker_content.replace(
'--extra-cflags="-I${PREFIX}/include"',
'--extra-cflags="-I${PREFIX}/include -I${PREFIX}/include/ffnvcodec -I/usr/local/cuda/include/"',
)
docker_content = docker_content.replace(
'--extra-ldflags="-L${PREFIX}/lib"',
'--extra-ldflags="-L${PREFIX}/lib -L/usr/local/cuda/lib64/ -L/usr/local/cuda/lib32/"',
)
if version == "snapshot" or version[0] >= "4":
docker_content = docker_content.replace(
"--disable-ffplay",
"--disable-ffplay \\\n --enable-cuda \\\n --enable-nvenc \\\n --enable-cuvid \\\n --enable-libnpp",
)
# Don't support hw decoding and scaling on older ffmpeg versions
if version[0] < "4":
docker_content = docker_content.replace(
"--disable-ffplay", "--disable-ffplay \\\n --enable-nvenc"
)
# 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("-ubuntu18.04", "-ubuntu16.04")
# FFmpeg 3.2 and earlier don't compile correctly on Ubuntu 18.04 due to openssl issues
if variant == "vaapi" and (
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")
d = os.path.dirname(dockerfile)
if not os.path.exists(d):
os.makedirs(d)
with open(dockerfile, "w") as dfile:
dfile.write(docker_content)
with open("docker-images/gitlab-ci.yml", "w") as gitlabcifile:
gitlabcifile.write("".join(gitlabci))
with open("templates/azure.template", "r") as tmpfile:
template = tmpfile.read()
azure = template.replace("%%VERSIONS%%", "\n".join(azure))
with open("azure-pipelines.yml", "w") as azurefile:
azurefile.write(azure)