欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

多媒体视频开发_(15) FFMPEG使用NVIDIA的GPU硬件转码

程序员文章站 2024-01-01 21:37:28
下载ffmpeg源码git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/安装依赖包:sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev编译配置./configure --enable-nonfree -–enable-cuda-sdk –enable-libnpp --extra...

下载ffmpeg源码

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/

安装依赖包:

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

编译配置

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

编译

make -j 8

安装

sudo 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 编码器配置参考

本文地址:https://blog.csdn.net/u010368556/article/details/107301276

上一篇:

下一篇: