- 官方关于ffmepg的网页
https://developer.nvidia.com/FFmpeg
- 下载驱动
https://www.nvidia.com/drivers
- 下载CUDA
https://developer.nvidia.com/cuda-downloads
- 下载ffmpeg
http://www.ffmpeg.org/download.html
- 安装ffnvcodec
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make && sudo make install
- 编译ffmpeg
cd ffmpeg-4.0.2
./configure --disable-asm --disable-x86asm \
--enable-cuda --enable-cuvid --enable-nvenc \
--enable-nonfree --enable-libnpp \
--extra-cflags=-I/usr/local/cuda/include \
--extra-cflags=-fPIC --extra-ldflags=-L/usr/local/cuda/lib64
# --enable-shared --enable-pic
make -j8
sudo make install
- 验证
退出当前终端,重新进入一个,输入命令:
ffmpeg -decoders | grep h264
输出的第一行,应该是:ffmpeg version 4.0.2
VFS..D h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
V..... h264_v4l2m2m V4L2 mem2mem H.264 decoder wrapper (codec h264)
V..... h264_cuvid Nvidia CUVID H264 decoder (codec h264)
ffmpeg -encoders | grep nv
V..... h264_nvenc NVIDIA NVENC H.264 encoder (codec h264)
V..... h264_v4l2m2m V4L2 mem2mem H.264 encoder wrapper (codec h264)
V..... nvenc NVIDIA NVENC H.264 encoder (codec h264)
V..... nvenc_h264 NVIDIA NVENC H.264 encoder (codec h264)
- 测试
ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -vsync 0 -i 2018.MOV -vcodec h264_nvenc -preset slow -b:v 2000k 2017.h264
注意,这里的preset参数,有的不能用了。
- 出错及解决办法
- 吾电脑提示要加上--disable-x86asm参数。
- configure时出错,提示:
ERROR: cuda requested, but not all dependencies are satisfied: ffnvcodec
解决办法:
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make && sudo make install