CentOS7 编译安装 ffmpeg 3.4.4 with cuda

具体编译命令可以参考 http://www.linuxfromscratch.org/blfs/view/svn/multimedia/ffmpeg.html

###############################################################################
 需要先把【安装所需文件】的内容拷贝到服务器 【/opt/storage】 目录,再执行以下脚本
###############################################################################

1.CUDA RPM 方式安装 (希望厂商预装)

##cd ~
#cd /opt/storage/cuda
## 1.Install EPEL to satisfy the DKMS dependency by following the instructions at EPEL's website.
## yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#yum install epel-release-latest-7.noarch.rpm
## 2.Install the repository meta-data, clean the yum cache, and install CUDA:
## wget http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-9.2.148-1.x86_64.rpm
#rpm -i cuda-repo-rhel7-9.2.148-1.x86_64.rpm
#yum clean expire-cache
#yum install cuda

## 改为本地安装
cd /opt/storage/cuda/  
yum install epel-release-latest-7.noarch.rpm  
rpm -i cuda-repo-rhel7-9-2-local-9.2.148-1.x86_64.rpm  
rpm -i cuda-repo-rhel7-9-2-148-local-patch-1-1.0-1.x86_64.rpm  
yum clean all  
yum install -y cuda

## 测试
/usr/local/cuda-9.2/bin/nvcc -V
## 3.需要重启机器 Reboot the system to load the NVIDIA drivers.

reboot

## 测试一下 驱动安装状态
nvidia-smi 

## 4.Set up the development environment by modifying the PATH and LD_LIBRARY_PATH variables:
echo 'export PATH=/usr/local/cuda-9.2/bin${PATH:+:${PATH}}  
export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> /etc/profile  
source /etc/profile  

2.ffmpeg dependence

2.1 faad

cd /tmp  
#http://www.audiocoding.com/downloads.html  faad2-2.7.tar.gz (要选择这个扩展名的文件)
#wget https://phoenixnap.dl.sourceforge.net/project/faac/faad2-src/faad2-2.8.0/faad2-2.8.8.tar.gz
tar zxvf /opt/storage/ffmpeg/faad2-2.8.8.tar.gz -C ./  
cd faad2-2.8.8

yum install autoconf  
#autoreconf -vif  
./configure  --with-mp4v2 --enable-shared  
make  
make install  
#./configure --prefix=/usr --disable-static &&
#make
#make install

2.2 faac

cd /tmp  
#http://www.audiocoding.com/downloads.html faac-1.28.tar.gz  (要选择这个扩展名的文件)
#wget https://phoenixnap.dl.sourceforge.net/project/faac/faac-src/faac-1.29/faac-1.29.9.2.tar.gz
tar zxvf /opt/storage/ffmpeg/faac-1.29.9.2.tar.gz -C ./  
cd faac-1.29.9.2  
#./bootstrap  
#./configure 
./configure --prefix=/usr --disable-static
make && make install  

2.3 fdk-aac

cd /tmp  
#wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-0.1.5.tar.gz
tar zxvf /opt/storage/ffmpeg/fdk-aac-0.1.5.tar.gz -C ./  
cd fdk-aac-0.1.5  
./configure --prefix=/usr --disable-static
make && make install  

2.4 lame

cd /tmp  
#wget https://downloads.sourceforge.net/lame/lame-3.100.tar.gz
tar xzvf /opt/storage/ffmpeg/lame-3.100.tar.gz -C ./  
cd lame-3.100  
./configure --prefix=/usr --enable-mp3rtp --disable-static
make  
make pkghtmldir=/usr/share/doc/lame-3.100 install  

2.5 libvorbis (需要先安装libogg)

cd /tmp  
tar xvf /opt/storage/ffmpeg/libogg-1.3.3.tar.xz -C ./  
cd libogg-1.3.3  
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/libogg-1.3.3 && make
make install

cd /tmp  
tar xvf /opt/storage/ffmpeg/libvorbis-1.3.6.tar.xz -C ./  
cd libvorbis-1.3.6  
./configure --prefix=/usr --disable-static && make
make install && install -v -m644 doc/Vorbis* /usr/share/doc/libvorbis-1.3.6  

2.6 speex

cd /tmp  
#wget https://downloads.xiph.org/releases/speex/speex-1.2.0.tar.gz
tar zxvf /opt/storage/ffmpeg/speex-1.2.0.tar.gz -C ./  
cd speex-1.2.0  
./configure --prefix=/usr --disable-static --docdir=/usr/share/doc/speex-1.2.0
make  
make install

#########################################################
## pkgconfig
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH  
#########################################################

2.7 FriBidi

cd /tmp  
tar xjf /opt/storage/ffmpeg/fribidi-1.0.4.tar.bz2 -C ./  
cd fribidi-1.0.4  
./configure 
make && make install  

2.8 FreeType2

cd /tmp  
tar -jxvf /opt/storage/ffmpeg/freetype-2.9.1.tar.bz2 -C ./  
cd freetype-2.9.1

sed -ri "s:.*(AUX_MODULES.*valid):\1:" modules.cfg &&  
sed -r "s:.*(#.*SUBPIXEL_RENDERING) .*:\1:" \  
    -i include/freetype/config/ftoption.h  &&
./configure --prefix=/usr --enable-freetype-config --disable-static &&
make

make install

## 9.Fontconfig
#cd /tmp
#tar -jxvf /opt/storage/ffmpeg/fontconfig-2.13.0.tar.bz2 -C ./
#cd fontconfig-2.13.0
#rm -f src/fcobjshash.h
#./configure --prefix=/usr        \
#            --sysconfdir=/etc    \
#            --localstatedir=/var \
#            --disable-docs       \
#            --docdir=/usr/share/doc/fontconfig-2.13.0 &&
#make
#make install

2.9 nasm

cd /tmp  
tar xvf /opt/storage/ffmpeg/nasm-2.13.03.tar.xz -C ./  
cd nasm-2.13.03  
sed -e '/seg_init/d'                      \  
    -e 's/pure_func seg_alloc/seg_alloc/' \
    -i include/nasmlib.h
./configure --prefix=/usr &&
make  
make install  

2.10 libass ## 安装失败了,缺少fonttype

cd /tmp  
#wget https://github.com/libass/libass/releases/download/0.14.0/libass-0.14.0.tar.xz
tar xvf /opt/storage/ffmpeg/libass-0.14.0.tar.xz -C ./  
cd libass-0.14.0  
./configure --prefix=/usr --disable-static &&
make  
make install  

2.11 ffmpegtoolkit

#cd /tmp
#git clone https://github.com/hostsoft/ffmpegtoolkit.git ffmpegtoolkit
\cp -Rf /opt/storage/ffmpeg/ffmpegtoolkit /tmp
cd /tmp/ffmpegtoolkit  
sh latest.sh  

2.12 x264

cd /tmp  
tar xjf /opt/storage/ffmpeg/x264-snapshot-20180212-2245-stable.tar.bz2 -C ./  
cd x264-snapshot-20180212-2245-stable  
./configure --prefix=/usr \
            --enable-shared \
            --disable-cli &&
make  
make install  

bash

3.编译安装 ffmpeg with cuda

3.1 ffmpeg3.4.2

cd /tmp  
tar xvf /opt/storage/ffmpeg/ffmpeg-3.4.4.tar.xz -C ./  
cd ffmpeg-3.4.4  
./configure --enable-shared --prefix=/usr/local/ffmpeg-3.4.4-cuda --enable-libnpp --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-pthreads --enable-debug --enable-version3 --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-ffserver --enable-ffplay --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --disable-x86asm --extra-cflags="-I/usr/local/cuda-9.2/include" --extra-ldflags="-L/usr/local/cuda-9.2/lib64" 
#./configure --enable-shared --prefix=/opt/ffmpeg-3.4.4-acc-cuda  --enable-libnpp --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-pthreads --enable-debug --enable-version3 --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-ffserver --enable-ffplay --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --disable-x86asm --extra-cflags="-I/usr/local/cuda-9.2/include" --extra-ldflags="-L/usr/local/cuda-9.2/lib64" 
make -j 30  
make install  

3.2 env config

echo 'export FFMPEG_HOME=/usr/local/ffmpeg-3.4.4-cuda  
export PATH=$FFMPEG_HOME/bin:$PATH  
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FFMPEG_HOME/lib:/usr/local/lib' >> /etc/profile

source /etc/profile

## 设置动态链接库环境
ldconfig

## 测试
/usr/local/ffmpeg-3.4.4-cuda/bin/ffmpeg -h