FFmpeg集成到GPU

 FFmpeg集成到GPU

GPU加速视频处理集成到最流行的开源多媒体工具中。

FFmpeg是最流行的开源多媒体操作工具之一,它有一个插件库,可以应用于音频和视频处理管道的各个部分,并在世界各地得到广泛采用。             

视频编码、解码和转码是FFmpeg最流行的应用之一。由于FFmpeg和libav社区的支持以及NVIDIA工程师的贡献,这两个工具现在都支持本机NVIDIA GPU硬件加速的视频编码和解码,通过整合NVIDIA视频编解码器SDK。             

利用FFmpeg的音频编解码器、流muxing和RTP协议,FFmpeg与NVIDIA视频编解码器SDK的集成实现了高性能硬件加速的视频管道。

FFmpeg uses Video Codec SDK

FFmpeg支持由NVIDIA GPU上的视频硬件加速的以下功能:             

H.264和HEVC的硬件加速编码*             

H.264、HEVC、VP9、VP8、MPEG2和MPEG4的硬件加速解码***             

对编码设置(如编码预设、速率控制和其他视频质量参数)进行精确控制             

使用FFmpeg中的内置过滤器创建高性能的端到端硬件加速视频处理、1:N编码和1:N转码管道             

能够使用FFmpeg中的共享CUDA上下文实现添加自定义的高性能CUDA过滤器             

Windows/Linux支持             

*支持取决于硬件。有关支持的GPU和格式的完整列表,请参阅可用的GPU支持列表。             

**在不久的将来,libav将增加对HW解码的支持。

What's New in FFmpeg

  • Includes Video Codec SDK 9.0 headers (both encode/decode)
  • 10-bit hwaccel accelerated pipeline
  • Support for fractional CQ
  • Support for Weighted Prediction
  • CUDA Scale filter (supports both 8 and 10 bit scaling).
  • Decode Capability Query

FFmpeg GPU HW-Acceleration Support Table

 

有关NVIDIA GPU加速视频编码/解码性能的指南,请访问视频编解码器SDK页面了解更多详细信息。

Getting Started with FFmpeg/libav using NVIDIA GPUs

Using NVIDIA hardware acceleration in FFmpeg/libav requires the following steps

  • Download and install ffnvcodec:
    git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
    cd nv-codec-headers && sudo make install && cd –
  • Download the latest FFmpeg or libav source code, by cloning the corresponding GIT repositories
  • Download and install the compatible driver from NVIDIA web site
  • Download and install the CUDA Toolkit CUDA toolkit
  • Use the following configure command (Use correct CUDA library path in config command below) 
    ./configure --enable-cuda-sdk --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp 
    --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  • Use the following command to compile: make -j 10
  • Use FFmpeg/libav binary as required. To start with FFmpeg, try the below sample command line for 1:2 transcoding
    ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -vsync 0 -i <input.mp4> -vf scale_npp=1920:1072
    -vcodec h264_nvenc <output0.264> -vf scale_npp=1280:720 -vcodec h264_nvenc <output1.264>

有关FFmpeg许可的详细信息,请参阅本页。有关构建过程和构建windows的更多信息,请参阅使用FFmpeg with NVIDIA GPU硬件加速指南。

FFmpeg in Action

FFmpeg被许多项目使用,包括googlechrome和VLC播放器。通过配置FFmpeg将NVIDIA gpu用于视频编码和解码任务,您可以轻松地将NVIDIA硬件加速集成到这些应用程序中。             

HandBrake是一个开源视频转码器,可用于Linux、Mac和Windows。             

HandBrake使用最常见的视频文件和格式,包括由消费者和专业摄像机创建的视频文件和格式、手机和平板电脑等移动设备、游戏和电脑屏幕录制以及DVD和蓝光光盘。HandBrake利用Libav、x264和x265等工具从这些工具创建新的MP4或MKV视频文件。             

Plex Media Server是一个客户端服务器媒体播放器系统和软件套件,运行在Windows、macOS、Linux、FreeBSD或NAS上。Plex从您计算机的个人媒体库中组织所有的视频、音乐和照片,并允许您流式传输到您的设备。             

Plex转码器使用FFmpeg处理媒体并将其转换为客户端设备支持的格式。

How to use FFmpeg/libav with NVIDIA GPU-acceleration

Decode a single H.264 to YUV

To decode a single H.264 encoded elementary bitstream file into YUV, use the following command:

FFMPEG: ffmpeg -vsync 0 -c:v h264_cuvid -i <input.mp4> -f rawvideo <output.yuv>
LIBAV: avconv -vsync 0 -c:v h264_cuvid -i <input.mp4> -f rawvideo <output.yuv>

Example applications:

  • Video analytics, video inferencing
  • Video post-processing
  • Video playback

Encode a single YUV file to a bitstream

To encode a single YUV file into an H.264/HEVC bitstream, use the following command:

H.264

FFMPEG: ffmpeg -f rawvideo -s:v 1920x1080 -r 30 -pix_fmt yuv420p -i <input.yuv> -c:v h264_nvenc -preset slow -cq 10 -bf 2 -g 150 <output.mp4>
LIBAV: avconv -f rawvideo -s:v 1920x1080 -r 30 -pix_fmt yuv420p -i <input.yuv> -c:v h264_nvenc -preset slow -cq 10 -bf 2 -g 150 <output.mp4> 

HEVC (No B-frames)

FFMPEG: ffmpeg -f rawvideo -s:v 1920x1080 -r 30 -pix_fmt yuv420p -i <input.yuv> -vcodec hevc_nvenc -preset slow -cq 10 -g 150 <output.mp4>
LIBAV: avconv -f rawvideo -s:v 1920x1080 -r 30 -pix_fmt yuv420p -i <input.yuv> -vcodec hevc_nvenc -preset slow -cq 10 -g 150 <output.mp4>

Example applications:

  • Surveillance
  • Archiving footages from remote cameras
  • Archiving raw captured video from a single camera

Transcode a single video file

To do 1:1 transcode, use the following command:

FFMPEG: ffmpeg -hwaccel cuvid -c:v h264_cuvid -i <input.mp4> -vf scale_npp=1280:720 -c:v h264_nvenc <output.mp4>
LIBAV: avconv -hwaccel cuvid -c:v h264_cuvid -i <input.mp4> -vf scale_npp=1280:720 -c:v h264_nvenc <output.mp4>

Example applications:

  • Accelerated transcoding of consumer videos

Transcode a single video file to N streams

To do 1:N transcode, use the following command:

FFMPEG: ffmpeg -hwaccel cuvid -c:v h264_cuvid -i <input.mp4> -vf scale_npp=1280:720 -vcodec h264_nvenc <output0.mp4> -vf scale_npp 640:480 -vcodec h264_nvenc <output1.mp4>
LIBAV: avconv -hwaccel cuvid -c:v h264_cuvid -i <input.mp4> -vf scale_npp=1280:720 -vcodec h264_nvenc <output0.mp4> -vf scale_npp 640:480 -vcodec h264_nvenc <output1.mp4>

Example applications:

  • Commercial (data center) video transcoding

 

 

原文地址:https://www.cnblogs.com/wujianming-110117/p/13235658.html