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
- FFmpeg: https://git.ffmpeg.org/ffmpeg.git
- Libav: https://github.com/libav/libav
- 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