CentOS中离线安装ffmpeg

moonjerx
2021-09-02 / 0 评论 / 277 阅读 / 正在检测是否收录...

1.下载安装包
ffmpeg-4.1.tar.xz
2.解压安装包:

tar -xvJf ffmpeg-4.1.tar.xz

3.编译安装: /programFiles/soft/ffmpeg 为自己指定的安装目录

./configure --enable-shared --prefix=/programFiles/soft/ffmpeg

提示错误:

nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
安装gcc编译器

centos 执行

yum install gcc

ubuntu 执行

apt install gcc
安装yasm编译器:

centos 执行

yum install -y yasm

ubuntu 执行

apt install -y yasm

离线安装yasm:

4.编译(编译时间比较长)和安装:

make && make install

5.遇到问题 -bash: make: command not found 的解决办法

一般出现这个提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make、vim等常用命令,直接yum安装下即可。

yum -y install gcc automake autoconf libtool make

安装g++:

yum install gcc gcc-c++

6.修改文件/etc/ld.so.conf

vim /etc/ld.so.conf
include ld.so.conf.d/*.conf

将安装目录的lib包路径 /{make install的目录}/ffmpeg/lib 加入最后

/programFiles/soft/ffmpeg/lib/

使修改生效:

ldconfig

7.查看版本

/programFiles/soft/ffmpeg/bin/ffmpeg -version

kt2q1e2y.png

8.配置环境变量

vim /etc/profile

在最后PATH添加环境变量( /programFiles/soft/ffmpeg/bin 为安装目录):

#set ffmpeg environment
PATH=$PATH:/programFiles/soft/ffmpeg/bin
export PATH

或者这么写:

#set ffmpeg env
export FFMPEG_HOME=/usr/bin/ffmpeg
export PATH=$PATH:${FFMPEG_HOME}/bin

使配置生效:

source /etc/profile 

9.查看环境变量是否配置成功

ffmpeg -version

kt2q2dan.png

参考资料:
https://www.cnblogs.com/wpjamer/p/ffmpeg.html
https://www.cnblogs.com/wintercloud/p/11162962.html

转码时候遇到问题 Unknown encoder 'libx264'

即,缺少libx264解码库,需要安装该库:

git clone http://git.videolan.org/git/x264.git && cd x264
./configure --enable-static --enable-shared
make && make install

FFMPEG使用NVIDIA的GPU硬件转码(使用N卡加速解码)

下载ffmpeg源码

sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev

正常编译配置(防止报错,根据提示加上--disable-x86asm)

./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib --disable-x86asm

N卡加速编译配置

./configure --enable-nonfree -–enable-cuda-sdk –enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64

编译和安装

make && make install

同分辨率转码, gpu加速转码,ddr在线模式

ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

变分辨率转码:

ffmpeg -y -vsync 0 -hwaccel cuvid –resize 1280x720 -c:v h264_cuvid -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

corp转码 (-crop (top)x(bottom)x(left)x(right))

ffmpeg -y -vsync 0 -hwaccel cuvid –crop 16x16x32x32 -c:v h264_cuvid -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

scale_cuda filter 转码

ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -vf scale_cuda=1280:720 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

scale_npp filter 转码

ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -vf scale_npp=1280:720 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

1:N 转码

ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -vf scale_npp=1920:1080 -c:a copy -c:v h264_nvenc -b:v 5M output1.mp4 -vf scale_npp=1280:720 -c:a copy -c:v h264_nvenc -b:v 8M output2.mp4

yuv编码, 1:N 编码

ffmpeg -y -vsync 0 -pix_fmt yuv420p -s 1920x1080 -i input.yuv -filter_complex "[0:v]hwupload_cuda,split=4[o1][o2][o3][o4]" -map "[o1]" -c:v h264_nvenc -b:v 8M output1.mp4 -map "[o2]" -c:v h264_nvenc -b:v 10M output2.mp4 -map "[o3]" -c:v h264_nvenc -b:v 12M output3.mp4 -map "[o4]" -c:v h264_nvenc -b:v 14M output4.mp4

转码, 1:N 编码

ffmpeg -y -hwaccel cuvid –c:v h264_cuvid -i input1.mp4 -hwaccel cuvid –c:v h264_cuvid -i input2.mp4 -map 0:0 -vf scale_npp=640:480 –c:v h264_nvenc -b:v 1M output11.mp4 -map 0:0 -vf scale_npp=320:240 –c:v h264_nvenc -b:v 500k output12.mp4 -map 1:0 -vf scale_npp=1280:720 –c:v h264_nvenc -b:v 3M output21.mp4 -map 1:0 -vf scale_npp=640:480 –c:v h264_nvenc -b:v 2M output22.mp4

软解码,gpu resize,gpu编码

ffmpeg -y -init_hw_device cuda=foo:bar -filter_hw_device foo  -i input1.mp4 -i input2.mp4 -map 0:0 -vf hwupload,scale_npp=640:480 –c:v h264_nvenc -b:v 1M  output11.mp4 -map 0:0 -vf hwupload,scale_npp=320:240 –c:v h264_nvenc -b:v 500k  output12.mp4 -map 1:0 -vf hwupload,scale_npp=1280:720 –c:v h264_nvenc -b:v 2M output21.mp4 -map 1:0 -vf hwupload,scale_npp=640:480 –c:v h264_nvenc -b:v 1M output22.mp4

更多配置通过ffmpeg查看NVIDIA编码器和解码器属性配置

更多参考:
https://developer.nvidia.com/ffmpeg
h264_nvenc 编码器配置参考
Using_FFmpeg_with_NVIDIA_GPU_Hardware_Acceleration_v01.4.pdf

0

评论 (0)

取消

您的IP: