-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-vapoursynth.sh
executable file
·248 lines (221 loc) · 6.33 KB
/
build-vapoursynth.sh
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/sh
# Caution: this script is for ubuntu 16.04 or newer
set -e
s_begin=$( date "+%s")
. ./config.txt
export CFLAGS="-pipe -O3 -fno-strict-aliasing -Wno-deprecated-declarations"
export CXXFLAGS="$CFLAGS"
#if [ ! -e $stamp -a -x "/usr/bin/apt" ]; then
sudo apt update
sudo apt upgrade
sudo apt install --no-install-recommends \
build-essential \
git \
python3-pip \
autoconf \
automake \
libtool \
libtool-bin \
libltdl-dev \
libva-dev \
libvdpau-dev \
libass-dev \
libtesseract-dev \
libleptonica-dev \
zlib1g-dev \
libbz2-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
liblzma-dev \
libfontconfig-dev \
libfreetype6-dev \
libfftw3-dev \
libpango1.0-dev \
libopenjp2-7-dev \
libxml2-dev \
lib$python3dotx \
lib$python3dotx-dev \
cython3
#touch $stamp
#fi
TOP="$PWD"
rm -rf build
mkdir build
cd build
build_pwd=$PWD
# newer nasm
if [ ! -x "$VSPREFIX/bin/nasm" ]; then
ver="2.14.02"
wget -c https://www.nasm.us/pub/nasm/releasebuilds/$ver/nasm-${ver}.tar.xz
tar xf nasm-${ver}.tar.xz
cd nasm-$ver
./configure --prefix="$VSPREFIX"
make -j$JOBS
make install
cd $build_pwd
rm -fr nasm-$ver nasm-${ver}.tar.xz
fi
max_attempts=3
retry_git_clone() {
local repo_url="$1"
local target_dir="$2"
local attempts=0
while true; do
if [ "$attempts" -ge "$max_attempts" ]; then
echo "Maximum number of clone attempts reached. Exiting."
exit 1
fi
if [ -n "$target_dir" ]; then
if git clone --depth 1 "$repo_url" "$target_dir"; then
break
else
attempts=$((attempts +1))
echo "clone attempt $attempts failed. Retrying in 5 seconds..."
sleep 5
fi
else
if git clone --depth 1 "$repo_url"; then
break
else
attempts=$((attempts +1))
echo "clone attempt $attempts failed. Retrying in 5 seconds..."
sleep 5
fi
fi
done
}
# build zimg, needed by Vapoursynth
if [ ! -f "$my_pkg_config_path/zimg.pc" ]; then
retry_git_clone https://github.com/sekrit-twc/zimg
cd zimg
git checkout $(git tag | sort -V | tail -1)
git submodule update --init --recursive
autoreconf -if
./configure --prefix="$VSPREFIX" --disable-static
make -j$JOBS
make install-strip
cd $build_pwd
rm -rf zimg
fi
# build ImageMagick 7, needed by imwri plugin
if [ ! -f "$my_pkg_config_path/Magick++.pc" ]; then
retry_git_clone https://github.com/ImageMagick/ImageMagick
old_pwd=$PWD
cd ImageMagick
git checkout $(git tag | grep '^7\.' | sort -V | tail -1)
PATH="$PWD:$PATH" autoreconf -if
./configure --prefix="$VSPREFIX" \
--disable-static \
--disable-docs \
--without-utilities \
--enable-hdri \
--with-quantum-depth=16
make -j$JOBS
make install-strip
cd $build_pwd
rm -rf ImageMagick
fi
# for nvidia support in ffmpeg
if [ ! -f "$my_pkg_config_path/ffnvcodec.pc" ]; then
retry_git_clone https://github.com/FFmpeg/nv-codec-headers.git
make -C nv-codec-headers install PREFIX="$VSPREFIX"
rm -fr nv-codec-headers
fi
# ffmpeg
if [ ! -f "$my_pkg_config_path/libavcodec.pc" ]; then
git clone https://github.com/FFmpeg/FFmpeg --branch release/6.1
cd FFmpeg
./configure --prefix="$VSPREFIX" \
--disable-static \
--enable-shared \
--disable-programs \
--disable-doc \
--disable-debug \
--enable-ffnvcodec \
--enable-nvdec \
--enable-nvenc \
--enable-cuvid \
--enable-vaapi \
--enable-vdpau
make -j$JOBS
make install
cd $build_pwd
rm -rf FFmpeg
fi
# VapourSynth, with an temp up-to-date cython install for security
if [ ! -x "$VSPREFIX/bin/vspipe" ]; then
old_pythonuserbase="$PYTHONUSERBASE"
export PYTHONUSERBASE="$PWD/temp"
pip3 install -q -I --user cython
retry_git_clone https://github.com/vapoursynth/vapoursynth
cd vapoursynth
#git checkout $(git tag | grep '^R' | sort -V | tail -1)
autoreconf -if
./configure --prefix="$VSPREFIX" --disable-static
make -j$JOBS
make install-strip
pip3 uninstall -y -q cython
export PYTHONUSERBASE="$old_pythonuserbase"
mkdir -p "${vs_site_packages}" "$VSPREFIX/include/vapoursynth" "$VSPREFIX/vsplugins"
cp include/*.h "$VSPREFIX/include/vapoursynth"
cd $build_pwd
rm -rf vapoursynth
fi
cd $build_pwd/..
rm -rf build
echo "Create \`$VSPREFIX/env.sh' and \`$VSPREFIX/env.csh'"
cat <<EOF >"$VSPREFIX/env.sh"
# source this file with
# . "$VSPREFIX/env.sh"
# in order to use vspipe from your local installation of vapoursynth,
# which is in the read only \$VSPREFIX variable.
#
export VSPREFIX="$VSPREFIX"
vs_site_packages="${vs_site_packages}"
#
if [ \$( echo "\$PATH" | egrep -Ec "(^|:)\$VSPREFIX/bin(:|\$)" ) = "0" ]; then
export PATH="\$VSPREFIX/bin:\$PATH"
fi
if [ -z "\$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="\$VSPREFIX/lib"
elif [ \$( echo "\$LD_LIBRARY_PATH" | egrep -Ec "(^|:)\$VSPREFIX/lib(:|\$)" ) = "0" ]; then
export LD_LIBRARY_PATH="\$VSPREFIX/lib:\$LD_LIBRARY_PATH"
fi
if [ -z "\$PYTHONPATH" ]; then
export PYTHONPATH="\${vs_site_packages}"
elif [ \$( echo "\$PYTHONPATH" | grep -Ec "(^|:)\${vs_site_packages}(:|\$)" ) = "0" ]; then
export PYTHONPATH="\${vs_site_packages}:\$PYTHONPATH"
fi
EOF
cat <<EOF >"$VSPREFIX/env.csh"
# source this file with
# source "$VSPREFIX/env.csh"
# in order to use vspipe from your local installation of vapoursynth,
# which is in the read only \$VSPREFIX variable.
#
setenv VSPREFIX "$VSPREFIX"
set vs_site_packages="${vs_site_packages}"
#
if ( \`echo "\$PATH" | grep -Ec "(^|:)\$VSPREFIX/bin(:|"'$'")"\` == "0" ) then
setenv PATH "\$VSPREFIX/bin:\$PATH"
endif
if ( ! \${?LD_LIBRARY_PATH} ) then
setenv LD_LIBRARY_PATH "$VSPREFIX/lib"
else if ( \`echo "\$LD_LIBRARY_PATH" | grep -Ec "(^|:)\$VSPREFIX/lib(:|"'$'")"\` == "0" ) then
setenv LD_LIBRARY_PATH "\$VSPREFIX/lib:\$LD_LIBRARY_PATH"
endif
if ( ! \${?PYTHONPATH} ) then
setenv PYTHONPATH "\${vs_site_packages}"
else if ( \`echo "\$PYTHONPATH" | grep -Ec "(^|:)\${vs_site_packages}(:|"'$'")"\` == "0" ) then
setenv PYTHONPATH "\${vs_site_packages}:\$PYTHONPATH"
endif
EOF
# http://www.vapoursynth.com/doc/autoloading.html#linux
conf="$HOME/.config/vapoursynth/vapoursynth.conf"
echo "Create \`$conf'"
mkdir -p "$HOME/.config/vapoursynth"
echo "SystemPluginDir=$VSPREFIX/vsplugins" > "$conf"
s_end=$( date "+%s")
s=$(($s_end - $s_begin))
printf "\nFinished after %d min %d sec\n" $(($s / 60)) $(($s % 60))