【ffmpeg】Ubuntu16.04重新編譯ffmpeg來使用h264_nvenc編碼

目的

使ffmpeg進行視頻編碼時可以用到cuda加速,即h264_nvenc編碼(h264編碼可以在移動端進行播放)

環境

  • Ubuntu 16.04
  • Cuda 9.1

參考鏈接

  • https://dwijaybane.wordpress.com/2017/07/19/ffmpeg-with-nvidia-acceleration-on-ubuntu-16-04-nvenc-sdk/
  • http://developer.download.nvidia.com/compute/redist/ffmpeg/1511-patch/FFMPEG-with-NVIDIA-Acceleration-on-Ubuntu_UG_v01.pdf

前言

重新編譯ffmpeg是個蠻繁瑣的過程,並且由於環境的原因,會導致編譯過程會出現各種各樣的bug, 我只配成了我的環境。如果有出現不同的情況歡迎評論進行交流。

提前下載文件

  1. 下載NVIDIA的SDK:

https://developer.nvidia.com/nvidia-video-codec-sdk

(這是9.1版本:Video_Codec_SDK_9.1.23)可以按照cuda版本在網上找不同的版本

  1. 下載ffmpeg

https://ffmpeg.org/releases/?C=N;O=D

根據自己需要下載ffmpeg版本,我下載的ffmpeg 3.4.2.tar.bz2 (不要下載太新的 新版本需要的nvidia驅動版本高)

配置依賴

先刪除ffmpeg及x264包

sudo apt-get -y remove ffmpeg x264 libx264-dev

安裝依賴

sudo apt-get -y install build-essential git yasm nasm unzip wget sysstat pkg-config

安裝NVENC SDK

unzip Video_Codec_SDK_9.1.23.zip
# 如果是8.0.14 版本,要運行一步下邊這一行
# sudo cp Video_Codec_SDK_8.0.14/Samples/common/inc/*.h /usr/local/include

安裝CUDA UTILITY

wget http://developer.download.nvidia.com/compute/redist/ffmpeg/1511-patch/cudautils.zip
unzip cudautils.zip
cd cudautils
make
cd ..

安裝x264

git clone git://git.videolan.org/x264.git
cd x264
./configure --disable-cli --enable-static --enable-shared --enable-strip --disable-asm
make -j 4
sudo make install
sudo ldconfig
cd ..

安裝ffmpeg

tar -xjvf ffmpeg-3.4.2.tar.bz2
mkdir ffmpeg_build
cd ffmpeg_build

# 中間需要安裝個codec-h
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install
cd ..

../ffmpeg-3.4.2/configure \
--enable-nonfree \
--enable-nvenc \
--extra-cflags=-I../cudautils \
--extra-ldflags=-L../cudautils \
--enable-gpl --enable-libx264

make -j4
make install
echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf
ldconfig

測試安裝是否成功

ffmpeg -encoders | grep 264

如果有下邊這些基本就代表成功了

V..... libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
V..... libx264rgb libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
V..... nvenc NVIDIA NVENC h264 encoder (codec h264)
V..... nvenc_h264 NVIDIA NVENC h264 encoder (codec h264)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章