nvidia 硬件条件下 ffmpeg安装流程

https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#CompilationInstallation

nvidia 硬件条件下 ffmpeg安装流程

一.安装yasm

yasm

curl -L -O http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure –prefix=”/usr”
make
sudo make install

二.安装nasm

nasm

curl -L -O http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.xz
tar xf nasm-2.13.01.tar.xz
cd nasm-2.13.01
./configure –prefix=”/usr”
make
sudo make install

三.安装libfdk-aac

libfdk-aac

Requires ffmpeg to be configured with –enable-libfdk_aac (and –enable-nonfree if you also included –enable-gpl).

git clone –depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
sudo autoreconf -fiv
./configure –prefix=”/usr” –disable-shared
make
sudo make install

四. 安装lame

lame

curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure –prefix=”/usr” –disable-shared –enable-nasm
make
sudo make install

五. 安装libopus

libopus

Requires ffmpeg to be configured with –enable-libopus.

curl -L -O https://archive.mozilla.org/pub/opus/opus-1.2.tar.gz
tar xvzf opus-1.2.tar.gz
cd opus-1.2
./configure –prefix=”/usr” –disable-shared
make
sudo make install

六. 安装libogg

libogg

Ogg bitstream library. Required by libtheora and libvorbis.

curl -L -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar xzvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure –prefix=”/usr” –disable-shared
make
sudo make install

七. 安装libvorbis

libvorbis

Vorbis audio encoder. Requires libogg.

Requires ffmpeg to be configured with –enable-libvorbis.

curl -L -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
./configure –prefix=”/usr” –with-ogg=”/usr” –disable-shared
make
sudo make install

八. 安装libtheora

libtheora

git clone git://git.xiph.org/mirrors/theora.git theora-git
cd theora-git
PKG_CONFIG_PATH=/usr/lib/pkgconfig ./autogen.sh –prefix=/usr –disable-examples –disable-shared –disable-sdltest –disable-vorbistest && make && make install

九. 安装libx265

libx265

Requires ffmpeg to be configured with –enable-gpl –enable-libx265.

sudo yum install hg cmake
hg clone https://bitbucket.org/multicoreware/x265
cd x265/build/linux
sudo cmake -G “Unix Makefiles” -DCMAKE_INSTALL_PREFIX=”/usr” -DENABLE_SHARED:bool=off ../../source
make
sudo make install

十. 安装x264

x264 , need nasm 2.13.01

gpl mode

curl -L -O http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar xjvf last_x264.tar.bz2
cd x264-snapshot-20170625-2245/
./configure –prefix=”/usr” –enable-static
make
sudo make install

disable-gpl

./configure –prefix=”/usr” –enable-static –disable-gpl –disable-opencl
make
sudo make install

十一. 安装libvpx

libvpx

VP8/VP9 video encoder.

git clone –depth 1 https://github.com/webmproject/libvpx.git
cd libvpx
./configure –prefix=”/usr” –disable-examples –disable-unit-tests –as=yasm
make
sudo make install

十二. 安装cuda toolkit

先安装cuda toolkit 一般情况下 cuda 会带上驱动, 但是驱动可能不是最新的,还是需要安装gpu卡的最新驱动!

cuda

Base Installer Download (1.4 GB)

Installation Instructions:

Run sudo sh cuda_8.0.61_375.26_linux.run

Follow the command-line prompts

curl -L -O https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
sudo sh cuda_8.0.61_375.26_linux-run

Patch 2 (Released Jun 26, 2017) Download (95.3 MB)

cuBLAS Patch Update to CUDA 8: Includes performance enhancements and bug-fixes

curl -L -O https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run
sudo sh cuda_8.0.61.2_linux-run

输入相关信息

安装后提示信息

===========

= Summary =

Driver: Installed
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /root/cuda_samples

Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

十三. 配置cuda信息

配置cuda相关信息

vi ~/.bashrc
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH= CUDAHOME/lib64exportPATH= PATH:/usr/local/cuda-8.0/bin

十四. 安装配置nvidia-video-codec-sdk

#####################可安装可不安装

nvec

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

下载需要账号认证

unzip Video_Codec_SDK_8.0.14.zip
sudo cp -r Video_Codec_SDK_8.0.14/Samples/common/inc/* /usr/include/
mv Video_Codec_SDK_8.0.14 nv_sdk

#

十五. 安装nvida驱动

NVIDIA DRIVER

http://www.nvidia.com/Download/Find.aspx 下载 NVIDIA 驱动程序,以M40 24GB 为例,选择如下的驱动程序。

NVIDIA-Linux-x86_64-375.66.run
chmod +x NVIDIA-Linux-x86_64-375.66.run
sudo /bin/bash ./NVIDIA-Linux-x86_64-375.66.run

按提示进行后续操作

安装完成后, 运行 nvidia-smi 如果有类似如下的GPU信息显示出来,说明驱动安装成功
Tue Jun 27 12:44:02 2017
+—————————————————————————–+
| NVIDIA-SMI 375.66 Driver Version: 375.66 |
|——————————-+———————-+———————-+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla M40 Off | 0000:00:07.0 Off | Off |
| N/A 26C P0 61W / 250W | 0MiB / 12209MiB | 0% Default |
+——————————-+———————-+———————-+

+—————————————————————————–+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+—————————————————————————–+

十六. 支持opengl glsl滤镜的过程

1)安装x window系统,因为要支持opengl需要窗口系统
yum groupinstall “X Window System” “Desktop” “Desktop Platform”
yum install gdm
yum groupinstall “Development Tools”
yum install kernel-devel kernel-headers

2) 重建启动镜像
使用 dracut重新建立 initramfs image file :
* 备份 the initramfs file
sudomv/boot/initramfs (uname -r).img /boot/initramfs- (unamer).img.baktheinitramfsfile sudo dracut -v /boot/initramfs- (unamer).img (uname -r)

3) 修改 /etc/X11/xorg.conf

nvidaconfig-x 产生的 xorg.conf不能保证服务器重启后,xwindow正常启动,必须修改如下

获取BusID 信息

$ nvidia-xconfig –query-gpu-info

vi /etc/X11/xorg.conf

Section “DRI”
Mode 0666
EndSection

Section “Device”
Identifier “Device0”
Driver “nvidia”
VendorName “NVIDIA Corporation”
BoardName “Tesla M40”
BusID “PCI:0:7:0”
EndSection

4) 导出 display

opengl 程序需要判断display的有效性,此方法是保证环境变量有DISPLAY

vi ~/.bashrc
export DISPLAY=:0.0

5) 可安装nvidia opengl例子最新版 (可以不安装)

注意:编译例子需要gcc 升级到4.8

5.1)升级gcc 4.8
第一部分:升级到4.7

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo 
yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++
这个将安装的文件放在了

/opt/centos/devtoolset-1.1
如果想要编辑器去处理的话,这样操作

export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc  
export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
如果你想要gcc替换本地的,当然不是真的去替换,只要把他放在我们的/usrlocal/bin下面就好了,不必去管系统自带的【/usr/bin】。

ln -s /opt/centos/devtoolset-1.1/root/usr/bin/* /usr/local/bin/
hash -r
gcc --version


第二部分:升级到4.8【这个应该是目前最新的啦,不过网上查的话已经到5.2啦,感觉落后一点比较稳,当然还有就是这个版本是新的里面使用最多的】

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
或

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-2/devtools-2.repo
然后

yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
这个将安装的文件放在了

/opt/rh/devtoolset-2
如果想要编辑器去处理的话,这样操作

export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc  
export CPP=/opt/rh/devtoolset-2/root/usr/bin/cpp
export CXX=/opt/rh/devtoolset-2/root/usr/bin/c++
如果你想要gcc替换本地的,当然不是真的去替换,只要把他放在我们的/usrlocal/bin下面就好了,不必去管系统自带的【/usr/bin】。

ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
hash -r
gcc --version

5.2) 下载安装编译例子
git clone https://github.com/NVIDIAGameWorks/GraphicsSamples.git
cd GraphicsSamples
cd samples/build/linux64
make debug
##如果异常,需要把每一个.mk文件 增加rt库依赖
例如:
vi Makefile.Basic.mk
Basic_debug_libraries += dl
Basic_debug_libraries += rt

5.3)可复制相关库文件 (判断相关版本信息决定是否覆盖)
cp /root/GraphicsSamples/extensions/externals/lib/linux64/libGLEW.a /usr/lib64/libGLEW.a
cp /root/GraphicsSamples/extensions/externals/lib/linux64/libglfw3.a /usr/local/lib/libglfw3.a

6) 重启进入xwindows模式
$ vi /etc/inittab
Change:
id:3:initdefault:

To:
id:5:initdefault:

十七. 修改ffmpeg,增加自己开发的opengl滤镜
1) 下载ffmpeg ,应安装3.2系列或者3.3.1

2)下载opengl滤镜模板
git clone https://github.com/nervous-systems/ffmpeg-opengl.git

3) ffmpeg 源码结构,添加opengl滤镜
ln -s ~/ffmpeg-opengl/vf_genericshader.c libavfilter/
git apply ~/ffmpeg-opengl/FFmpeg.diff

十八. 配置ffmpeg, 编译安装
1) 配置
PKG_CONFIG_PATH=”/usr/lib/pkgconfig” ./configure –prefix=”/usr” –pkg-config-flags=”–static” –enable-gpl –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libtheora –enable-libxvid –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree –extra-cflags=”-I/usr/local/cuda/include/” –extra-ldflags=-L/usr/local/cuda/lib64 –disable-shared –enable-nvenc –enable-cuda –enable-cuvid –enable-libnpp –enable-pthreads
2) 编译
make -j 10

3) 安装
make install

其他资料:

######### ffmpeg 3.3.2 不支持M40, 驱动要求378以上,ffmpeg应安装3.2系列或者3.3.1

ffmpeg

gpl模式

PKG_CONFIG_PATH=”/usr/lib/pkgconfig” ./configure –prefix=”/usr” –pkg-config-flags=”–static” –enable-gpl –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libtheora –enable-libxvid –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree –extra-cflags=”-I/usr/local/cuda/include/” –extra-ldflags=-L/usr/local/cuda/lib64 –disable-shared –enable-nvenc –enable-cuda –enable-cuvid –enable-libnpp –enable-pthreads

纯硬加解码,非gpl模式

PKG_CONFIG_PATH=”/usr/lib/pkgconfig” ./configure –prefix=”/usr” –enable-cuda –enable-cuvid –enable-nvenc –enable-nonfree –enable-libnpp –enable-libfdk_aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libtheora –enable-libvorbis –enable-libvpx –enable-pthreads –extra-cflags=-I/usr/local/cuda/include –extra-ldflags=-L/usr/local/cuda/lib64

滤镜处理

PKG_CONFIG_PATH=”/usr/lib/pkgconfig” ./configure –prefix=”/usr” –pkg-config-flags=”–static” –enable-gpl –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libtheora –enable-libxvid –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree –extra-cflags=”-I/usr/local/cuda/include/” –extra-ldflags=-L/usr/local/cuda/lib64 –disable-shared –enable-nvenc –enable-cuda –enable-cuvid –enable-libnpp –enable-pthreads –enable-filter=genericshader –enable-opengl –extra-libs=”-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread”

测试型情况

PKG_CONFIG_PATH=”/usr/lib/pkgconfig” ./configure –enable-libx264 –enable-filter=genericshader –enable-gpl –enable-opengl –extra-libs=”-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread”

ffmpeg 解码器、编码器列表

ffmpeg -encoders |grep he
ffmpeg -decoders |grep cuvid
ffmpeg -decoders |grep he

相关工具安装

显示pci信息

  1. lspci -vnn

显示硬件信息

  1. lshw
    2.1安装:
    yum install lshw
    2.2显示显卡信息
    lshw -C display

    2.3查看当前使用的显卡驱动
    sudo lshw -c video | grep configuration
    configuration: latency=0
    configuration: driver=nvidia latency=0
    modinfo nvidia

相关资料链接

cuda下载链接:
https://developer.nvidia.com/cuda-downloads

https://www.qcloud.com/document/product/213/6816?lang=en

驱动下载:
http://www.nvidia.com/Download/Find.aspx

ffmpeg 硬件加速的用法

https://trac.ffmpeg.org/wiki/HWAccelIntro

自定义滤镜:

未硬件加速

ffmpeg -i input.mp4 -vf genericshader -y output.mp4

硬件加速

ffmpeg -i toystory.mp4 -vf genericshader -vcodec h264_nvenc -y out4.mp4

cpu 使用监控

vmstat -w -n 1

gpu 使用监控

nvidia-smi dmon -i 0

你可能感兴趣的:(nvidia 硬件条件下 ffmpeg安装流程)