-
Notifications
You must be signed in to change notification settings - Fork 15
/
BuildFFmpeg.sh
executable file
·164 lines (148 loc) · 6.88 KB
/
BuildFFmpeg.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
#!/bin/bash
printf "\033[33m"
echo "Warning: It is deprecated, but you're welcome to use it anyway."
printf "\033[39m"
PREFIX="$(pwd)/buildffmpeg/prefix"
echo "Note: Your prefix folder with full directory will be built: $PREFIX"
case "$(uname -s)" in
Linux*)
OS="Linux"
DISTRO=$(cat /etc/*release | grep ^ID= | cut -d= -f2 | tr -d '"')
echo "Building FFmpeg VVCEasy $OS version..."
echo "Updating and upgrading system packages..."
case $DISTRO in
debian|ubuntu)
echo "Detected Debian/Ubuntu"
sudo apt update && sudo apt upgrade -y
echo "Installing dependencies for Debian/Ubuntu..."
sudo apt install build-essential cmake nasm autoconf pkg-config \
python3-setuptools ninja-build python3-pip libtool git wget xxd -y
sudo pip3 install meson
;;
arch)
echo "Detected Arch Linux"
sudo pacman -Syu --noconfirm
echo "Installing dependencies for Arch..."
sudo pacman -S --noconfirm base-devel cmake nasm autoconf pkg-config \
python-setuptools ninja python-pip libtool git wget xxd
sudo pip install meson
;;
fedora)
echo "Detected Fedora"
sudo dnf update -y
echo "Installing dependencies for Fedora..."
sudo dnf install -y gcc gcc-c++ cmake nasm autoconf pkgconfig \
python3-setuptools ninja-build python3-pip libtool git wget xxd
sudo pip3 install meson
;;
gentoo)
echo "Detected Gentoo"
sudo emerge --sync
echo "Installing dependencies for Gentoo..."
sudo emerge -av dev-util/cmake media-libs/nasm sys-devel/autoconf \
dev-python/setuptools dev-util/ninja dev-python/pip sys-libs/libtool \
dev-vcs/git net-misc/wget app-editors/vim
sudo pip3 install meson
;;
*)
echo "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
;;
MSYS*|MINGW*)
OS="Windows"
extra="--disable-w32threads --enable-libcodec2"
echo "Building FFmpeg VVCEasy Windows version..."
echo "Updating and upgrading MSYS2 packages..."
pacman -Syu
echo "Installing MSYS2 packages..."
pacman -S python git nasm vim wget xxd $MINGW_PACKAGE_PREFIX-{toolchain,cmake,autotools,meson,ninja}
;;
Darwin*)
OS="macOS"
echo "Building FFmpeg VVCEasy macOS version..."
echo "Checking for Brew packages requirements..."
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Please install Homebrew and try again."
exit 1
else
brew install ffmpeg cmake nasm opus meson autoconf automake wget ninja
fi
;;
*)
echo "Only for Windows, macOS & Linux are only supported"
exit 1
;;
esac
clonepull() {
if [ ! -d "$1" ]; then
git clone --depth=1 "$2" "$1"
else
git -C "$1" pull
fi
}
[ ! -d buildffmpeg ] && mkdir buildffmpeg
cd buildffmpeg
[ ! -d prefix ] && mkdir prefix
clonepull FFmpeg-VVC https://github.com/MartinEesmaa/FFmpeg-VVC
clonepull vvenc https://github.com/fraunhoferhhi/vvenc
clonepull vvdec https://github.com/fraunhoferhhi/vvdec
clonepull fdk-aac https://github.com/mstorsjo/fdk-aac
clonepull SDL https://github.com/libsdl-org/SDL -b SDL2
clonepull libxml2 https://github.com/gnome/libxml2
clonepull opus https://github.com/xiph/opus
clonepull libjxl https://github.com/libjxl/libjxl
clonepull zimg https://github.com/sekrit-twc/zimg
clonepull soxr https://github.com/chirlu/soxr
clonepull dav1d https://code.videolan.org/videolan/dav1d
clonepull vmaf https://github.com/netflix/vmaf
gitsub="submodule update --init --recursive --depth 1 --recommend-shallow"
if [ $OS = "Windows" ]; then
clonepull codec2 https://github.com/drowe67/codec2
fi
if [ ! -d libjxl ]; then
sed -i 's/-lm/-lm -lstdc++/g' libjxl/lib/jxl/libjxl.pc.in libjxl/lib/threads/libjxl_threads.pc.in
git -C libjxl $gitsub
fi
if [ ! -d zimg ]; then
git -C zimg $gitsub
wget https://raw.githubusercontent.com/m-ab-s/mabs-patches/master/zimg/0001-libm_wrapper-define-__CRT__NO_INLINE-before-math.h.patch
git -C zimg apply 0001-libm_wrapper-define-__CRT__NO_INLINE-before-math.h.patch
rm 0001-libm_wrapper-define-__CRT__NO_INLINE-before-math.h.patch
fi
make="make install-r install-prefix=$PREFIX"
autogen="./autogen.sh && ./configure --prefix=$PREFIX --enable-static --disable-shared && make install -j $(nproc)"
cmakeoptions="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF"
mesonoptions="-Ddefault_library=static -Dprefix=$PREFIX"
cd vvenc && $make && cd ..
cd vvdec && $make && cd ..
cd fdk-aac && $autogen && cd ..
cd libxml2 && $autogen && cd ..
cd opus && CFLAGS="-O2 -D_FORTIFY_SOURCE=0" LDFLAGS="-flto -s" $autogen && cd ..
mkdir -p libjxl/build && cd libjxl/build && cmake $cmakeoptions -DBUILD_TESTING=OFF -DJPEGXL_ENABLE_{BENCHMARK,MANPAGES,EXAMPLES,DOXYGEN}=OFF -DJPEGXL_FORCE_SYSTEM_BROTLI=ON .. -G Ninja && ninja install && cd ../../
mkdir -p vmaf/libvmaf/build && cd vmaf/libvmaf/build && CFLAGS="-msse2 -mfpmath=sse -mstackrealign" meson -Denable_{docs,tests}=false -Denable_float=true $mesonoptions .. && ninja install && cd ../../../
mkdir -p SDL/build && cd SDL/build && cmake $cmakeoptions .. && make install -j $(nproc) && cd ../../
cd zimg && $autogen && cd ..
mkdir -p soxr/build && cd soxr/build && cmake -D{WITH_LSR_BINDINGS,BUILD_TESTS,WITH_OPENMP}=off $cmakeoptions .. && cmake --build . -j $(nproc) --target install && cd ../../
mkdir -p dav1d/build && cd dav1d/build && meson -Denable_docs=false $mesonoptions .. && ninja install && cd ../../
sed -i 's/-lm/-lm -lstdc++/g' $PREFIX/lib/pkgconfig/libvmaf.pc
if [ "$OS" = "Windows" ]; then
cd codec2
sed -i 's|if(WIN32)|if(FALSE)|g' CMakeLists.txt
grep -ERl "\b(lsp|lpc)_to_(lpc|lsp)" --include="*.[ch]" | \
xargs -r sed -ri "s;((lsp|lpc)_to_(lpc|lsp));c2_\1;g"
mkdir -p build && cd build && cmake $cmakeoptions -D{UNITTEST,INSTALL_EXAMPLES}=off .. -G "MinGW Makefiles"
cmake --build . -j $nproc --target install
cd ../../
fi
cd FFmpeg-VVC
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
./configure --prefix=$PREFIX --enable-static --pkg-config-flags="--static" --extra-ldexeflags="-static" \
--enable-libfdk-aac --enable-libvvenc --enable-libvvdec --enable-pic \
--enable-libxml2 --enable-libopus --enable-libdav1d --enable-libjxl --enable-libzimg \
--enable-libvmaf --enable-libsoxr --enable-sdl2 $extra --extra-version=VVCEasy && \
make -j
cd ..
echo It is ready to go for prebuilt binaries of FFmpeg-VVC, you need to go directory called FFmpeg-VVC.
echo "- 2024 Martin Eesmaa (VVCEasy, MIT License)"