Last active
July 27, 2020 10:24
-
-
Save yoosefi/88d0a0b0b10a4dd69db46bfc8fba4336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
# Builds ffmpeg with nvenc for private use. | |
# Fetches main sources (ffmpeg, nvidia headers) for you. | |
# Uses autodetect to include extra media libraries already on your system; | |
# this doesn't download and compile the universe like other scripts. | |
# To use, place this script in its own directory and run it. | |
# The ffmpeg version can be changed below. | |
########## CONFIG ########## | |
ffmpegVersion="n4.2.4" | |
############################ | |
# workspace | |
ffmpeg="ffmpeg-${ffmpegVersion}" | |
rm -rf build | |
build="${PWD}/build" | |
include="${build}/include" | |
lib="${build}/lib" | |
# check build tools | |
for tool in cmake git yasm; do | |
(hash $tool 2>/dev/null) || (echo "Missing: ${tool}"; exit 1) | |
done | |
# install headers and pkgconfig locally. the sdk isn't needed. from nvidia's own docs: | |
# FFmpeg maintains a version of NVIDIA Video Codec SDK headers in a separate git repository, for ease of compilation. | |
# As such the download of NVIDIA Video Codec SDK is not essential for building FFmpeg. | |
if [ ! -d nv-codec-headers ]; then | |
echo "Fetching nv-codec-headers ..." | |
git clone -q --single-branch --depth 1 https://git.videolan.org/git/ffmpeg/nv-codec-headers.git | |
fi | |
cd nv-codec-headers | |
git pull -q | |
make install PREFIX="${build}" | |
cd .. | |
# compile ffmpeg | |
if [ ! -d $ffmpeg ]; then | |
echo "Fetching ${ffmpeg} ..." | |
git clone -q -b $ffmpegVersion --single-branch --depth 1 https://git.ffmpeg.org/ffmpeg.git $ffmpeg | |
fi | |
cd $ffmpeg | |
PKG_CONFIG_PATH="${lib}/pkgconfig" ./configure \ | |
--prefix="${build}" \ | |
--extra-cflags="-m64 -I${include}" \ | |
--extra-ldflags="-L${lib}" \ | |
--enable-gpl \ | |
--enable-nonfree \ | |
--enable-nvenc \ | |
--enable-version3 \ | |
--disable-doc \ | |
--disable-ffplay \ | |
--disable-ffprobe \ | |
"$@" | |
make -j$(nproc) ffmpeg install | |
cd .. | |
echo | |
echo "Success." | |
echo | |
file build/bin/ffmpeg | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment