| 1 |
#! /usr/bin/env bash |
| 2 |
|
| 3 |
if [[ ! "$_PYAV_ACTIVATED" ]]; then |
| 4 |
export here="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" |
| 5 |
source "$here/activate.sh" |
| 6 |
fi |
| 7 |
|
| 8 |
cd "$PYAV_ROOT" |
| 9 |
|
| 10 |
# Skip the rest of the build if it already exists. |
| 11 |
if [[ -e "$PYAV_LIBRARY_PREFIX/bin/ffmpeg" ]]; then |
| 12 |
echo "We have a cached build of ffmpeg-$PYAV_LIBRARY; skipping re-build." |
| 13 |
exit 0 |
| 14 |
fi |
| 15 |
|
| 16 |
mkdir -p "$PYAV_LIBRARY_ROOT" |
| 17 |
mkdir -p "$PYAV_LIBRARY_PREFIX" |
| 18 |
|
| 19 |
# Add CUDA support if available |
| 20 |
CONFFLAGS_NVIDIA="" |
| 21 |
if [[ -e /usr/local/cuda ]]; then |
| 22 |
# Get Nvidia headers for ffmpeg |
| 23 |
cd $PYAV_LIBRARY_ROOT |
| 24 |
if [[ ! -e "$PYAV_LIBRARY_ROOT/nv-codec-headers" ]]; then |
| 25 |
git clone https://github.com/FFmpeg/nv-codec-headers.git |
| 26 |
cd nv-codec-headers |
| 27 |
make -j4 |
| 28 |
make PREFIX="$PYAV_LIBRARY_PREFIX" install |
| 29 |
fi |
| 30 |
|
| 31 |
PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" |
| 32 |
CONFFLAGS_NVIDIA="--enable-cuda-nvcc \ |
| 33 |
--enable-nonfree \ |
| 34 |
--enable-libnpp \ |
| 35 |
--extra-cflags=-I/usr/local/cuda/include \ |
| 36 |
--extra-ldflags=-L/usr/local/cuda/lib64" |
| 37 |
else |
| 38 |
echo "WARNING: Did not find cuda libraries in /usr/local/cuda..." |
| 39 |
echo " Building without NVIDIA NVENC/NVDEC support" |
| 40 |
fi |
| 41 |
|
| 42 |
cd "$PYAV_LIBRARY_ROOT" |
| 43 |
|
| 44 |
# Download and expand the source. |
| 45 |
if [[ ! -d $PYAV_LIBRARY ]]; then |
| 46 |
url="https://ffmpeg.org/releases/$PYAV_LIBRARY.tar.gz" |
| 47 |
echo Downloading $url |
| 48 |
curl "$url" --output ${PYAV_LIBRARY}.tar.gz || exit 1 |
| 49 |
tar -xzf $PYAV_LIBRARY.tar.gz |
| 50 |
rm $PYAV_LIBRARY.tar.gz |
| 51 |
echo |
| 52 |
fi |
| 53 |
cd $PYAV_LIBRARY |
| 54 |
|
| 55 |
echo ./configure |
| 56 |
./configure \ |
| 57 |
--disable-doc \ |
| 58 |
--disable-programs \ |
| 59 |
--disable-stripping \ |
| 60 |
--disable-static \ |
| 61 |
--enable-shared \ |
| 62 |
--enable-gpl \ |
| 63 |
--enable-version3 \ |
| 64 |
--disable-libxml2 \ |
| 65 |
--disable-xlib \ |
| 66 |
--disable-openssl \ |
| 67 |
--enable-debug=3 \ |
| 68 |
--enable-libx264 \ |
| 69 |
--disable-bsfs \ |
| 70 |
--enable-bsf=chomp,h264_mp4toannexb,setts \ |
| 71 |
--enable-sse \ |
| 72 |
--enable-avx \ |
| 73 |
--enable-avx2 \ |
| 74 |
$CONFFLAGS_NVIDIA \ |
| 75 |
--prefix="$PYAV_LIBRARY_PREFIX" \ |
| 76 |
|| exit 2 |
| 77 |
echo |
| 78 |
|
| 79 |
echo make |
| 80 |
make -j4 || exit 3 |
| 81 |
echo |
| 82 |
|
| 83 |
echo make install |
| 84 |
make install || exit 4 |
| 85 |
echo |
| 86 |
|
| 87 |
echo Build products: |
| 88 |
cd ~ |
| 89 |
find "$PYAV_LIBRARY_PREFIX" -name '*libav*' |