FFmpeg / libav GPU-accelerated video processing 编码/解码/转码
来源:互联网 发布:js创建对象的三种方式 编辑:程序博客网 时间:2024/06/05 16:32
GPU-accelerated video processing integrated into the most popular open-source multimedia tools.
FFmpeg and libav are among the most popular open-source multimedia manipulation tools with a library of plugins that can be applied to various parts of the audio and video processing pipelines and have achieved wide adoption across the world.
Video encoding, decoding and transcoding are some of the most popular applications of FFmpeg. Thanks to the support of the FFmpeg and libav community and contributions from NVIDIA engineers, both of these tools now support native NVIDIA GPU hardware accelerated video encoding and decoding through the integration of the NVIDIA Video Codec SDK.
Leveraging FFmpeg’s Audio codec, stream muxing, and RTP protocols, the FFmpeg’s integration of NVIDIA Video Codec SDK enables high performance hardware accelerated video pipelines.
FFmpeg uses Video Codec SDK
If you have an NVIDIA GPU which supports hardware-accelerated video encoding and decoding, it’s simply a matter of compiling FFmpeg binary with the required support for NVIDIA libraries and using the resulting binaries to speed up video encoding/decoding.
FFmpeg supports following functionality accelerated by video hardware on NVIDIA GPUs:
- Hardware-accelerated encoding of H.264 and HEVC*
- Hardware-accelerated decoding** of H.264, HEVC, VP9, VP8, MPEG2, and MPEG4*
- Granular control over encoding settings such as encoding preset, rate control and other video quality parameters
- Create high-performance end-to-end hardware-accelerated video processing, 1:N encoding and 1:N transcoding pipeline using built-in filters in FFmpeg
- Ability to add your own custom high-performance CUDA filters using the shared CUDA context implementation in FFmpeg
- Windows/Linux support
* Support is dependent on HW. For a full list of GPUs and formats supported, please see the availableGPU Support Matrix.
** HW decode support will be added to libav in the near future
What's New in FFmpeg
- Includes Video Codec SDK 8.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
- More...
Download FFmpeg (main tree): GitHub
NVDECODE API - NVIDIA Quadro, Tesla, GRID or GeForce products with Fermi, Kepler, Maxwell and Pascal generation GPUs.
GPU Support Matrix
Appropriate NVIDIA Display Driver
DirectX SDK (Windows only)CUDA ToolkitDevelopment EnvironmentWindows: Visual Studio 2013SP5/2015, MSYS/MinGW
Linux: gcc 4.8 or higher
FFmpeg GPU HW-Acceleration Support Table
For guidelines about NVIDIA GPU-accelerated video encoding/decoding performance, please visit theVideo Codec SDK page for more details.
Getting Started with FFmpeg/libav using NVIDIA GPUs
Using NVIDIA hardware acceleration in FFmpeg/libav requires the following steps
- Download the latest FFmpeg orlibav source code, by cloning the corresponding GIT repositories
- FFmpeg: https://git.ffmpeg.org/ffmpeg.git
- Libav: https://github.com/libav/libav
- Download and install the compatible driver from NVIDIA web site
- Downoad and install the CUDA Toolkit CUDA toolkit
- Use the following configure command (Use correct CUDA library path in config command below)
./configure --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp
--extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 - Use following command for build: 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>
For more information on FFmpeg licensing, please see this page.
FFmpeg in Action
FFmpeg is used by many projects, including Google Chrome and VLC player. You can easily integrate NVIDIA hardware-acceleration to these applications by configuring FFmpeg to use NVIDIA GPUs for video encoding and decoding tasks.
HandBrake is an open-source video transcoder available for Linux, Mac, and Windows.
HandBrake works with most common video files and formats, including ones created by consumer and professional video cameras, mobile devices such as phones and tablets, game and computer screen recordings, and DVD and Blu-ray discs. HandBrake leverages tools such as Libav, x264, and x265 to create new MP4 or MKV video files from these.
Plex Media Server is a client-server media player system and software suite that runs on Windows, macOS, Linux, FreeBSD or a NAS. Plex organizes all of the videos, music, and photos from your computer’s personal media library and let you stream to your devices.
The Plex Transcoder uses FFmpeg to handle and translates your media into that the format your client device supports.
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
Resources
Supported GPUs
HW accelerated encode and decode are supported on NVIDIA GeForce, Quadro, Tesla, and GRID products with Fermi, Kepler, Maxwell and Pascal generation GPUs. Please refer toGPU support matrix for specific codec support.
Additional Resources
- Using FFmpeg with NVIDIA GPU Hardware Acceleration
- FFmpeg Homepage
- NVIDIA Video Encode and Decode GPU Support Matrix
- NVIDIA Video Codec SDK
- CUDA Toolkit
- NVEncode Programming Guide
- NVDecode Programming Guide
- FFmpeg / libav GPU-accelerated video processing 编码/解码/转码
- GPU-accelerated video processing on Mac and iOS
- libav/FFMPEG 视频音频编解码库使用
- stage video 【利用Gpu解码视频】
- ffmpeg--编码解码h264
- GPU编解码 - 硬编码
- 编译libav(ffmpeg)库
- ffmpeg/libav 选择
- 树莓派 FFmpeg 支持GPU硬解码
- 树莓派 FFmpeg 支持GPU硬解码
- 读取笔记本的摄像头的原始yuv数据,通过libav(ffmpeg编码)
- 读取笔记本的摄像头的原始yuv数据,通过libav(ffmpeg编码)
- Using lcov With FFmpeg/Libav
- Object Detection by Color: Using the GPU for Real-Time Video Image Processing
- 264编码基本概念 FFMpeg的解码流程
- ffmpeg--音频的解码和编码
- 利用 ffmpeg x264 编码解码 h264
- ffmpeg解码jpg并编码成h264
- android studio gradle/wrapper/gradle-wrapper.properties里面更新gradle版本问题
- 关于IO的推挽输出和开漏输出
- Android实践 -- 设置系统日期时间和时区
- Jenkins 使用学习笔记
- hdu 5894 hannnnah_j’s Biological Test
- FFmpeg / libav GPU-accelerated video processing 编码/解码/转码
- 滴滴插件VirtualApk学习一 编译
- git 生成ssh 密钥
- 40个Java多线程问题总结
- C# 托管内存与非托管内存之间的转换(结合Unity3d的实际开发)
- Linux 源码安装MySQL 你GET了吗?
- finally语句与return语句的执行顺序
- IDEA+selenium+testng&reportng 环境搭建
- 上市公司财务报告的那点事(5):从新手试练到股票建仓,美丽的老板出海卖电器