您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页FFmpeg新版本(2016年10月份以后) 支持硬件解码

FFmpeg新版本(2016年10月份以后) 支持硬件解码

来源:伴沃教育

FFmpeg provides a subsystem for hardware acceleration.

Hardware acceleration allows to use specific devices (usually graphical card or other specific devices) to perform multimedia processing. This allows to use dedicated hardware to perform demanding computation while freeing the CPU from such computations. Typically hardware acceleration enables specific hardware devices (usually the GPU) to perform operations related to decoding and encoding video streams, or filtering video.

When using FFmpeg the tool, HW-assisted decoding is enabled using through the -hwaccel option, which enables a specific decoder. Each decoder may have specific limitations (for example an H.2 decoder may only support baseline profile). HW-assisted encoding is enabled through the use of a specific encoder (for example h2_nvenc). Filtering HW-assisted processing is only supported in a few filters, and in that case you enable the OpenCL code through a filter option.

There are several hardware acceleration standards API, some of which are supported to some extent by FFmpeg.

Platforms overview

API availability

 Linux IntelLinux NVIDIAWindows IntelWindows NVIDIAOS XAndroidiOSRaspberry Pi
CUDANYNYYNNN
Direct3D 11NNYYNNNN
DXVA2NNYYNNNN
MediaCodecNNNNNYNN
MMALNNNNNNNY
NVENCNYNYNNNN
OpenCLYYYYYNNN
Quick SyncYNYNNNNN
VA-APIYY*NNNNNN
VDA†NNNNYNNN
VDPAUNYNNNNNN
VideoToolboxNNNNYNYN
XvMCYYNNNNNN

* Semi-maintained.

† Deprecated by upstream.

FFmpeg implementations

 AVHWAccelDecoderEncoderCLIFilteringAVHWFramesContext
CUDA1YYN2YYY
Direct3D 11YNN/ANNN
DXVA2YNN/AYNY
MediaCodecYYNN/AN/AN
MMALYYN/ANN/AN
NVENCN/AN3YYN/AN
OpenCLN/AN/AN/AN/AYN
Quick SyncYYYYNN*
VA-APIYNYYYY
VDAYYN/AYN/AN
VDPAUYN†N/AYNY
VideoToolboxYNYYNN
XvMCYN†N/ANN/AN

N/A This feature is not directly supported by the API, or is not currently implementable.

* Work in progress. If "Y" is indicated, infrastructure is in place but no filters have been implemented yet.

† Actually yes, but is deprecated for technical reasons and should not be used.

1 Also known as "CUDA Video Decoding API" or "CUVID" or "".

2 See NVENC

3 See CUDA

VDPAU

. Developed by NVidia for UNIX/Linux systems. To enable this you typically need the libvdpau development package in your distribution, and a compatible graphic card.

Note that VDPAU cannot be used to decode frames in memory, the compressed frames are sent by libavcodec to the GPU device supported by VDPAU and then the decoded image can be accessed using the VDPAU API. This is not done automatically by FFmpeg, but must be done at the application level (check for example the ffmpeg_vdpau.c file used by ffmpeg.c). Also, note that with this API it is not possible to move the decoded frame back to RAM, for example in case you need to encode again the decoded frame (e.g. when doing transcoding on a server).

Several decoders are currently supported through VDPAU in libavcodec, in particular H.2, MPEG-1/2/4, and VC-1.

XvMC

XVideo Motion Compensation. This is an extension of the X video extension (Xv) for the X Window System (and thus again only available only on UNIX/Linux).

Official specification is available here: 

VA-API

Video Acceleration API (VA API) is a non-proprietary and royalty-free open source software library ("libVA") and API specification, initially developed by Intel but can be used in combination with other devices. Linux only: 

DXVA2

Direct-X Video Acceleration API, developed by Microsoft (supports Windows and XBox360).

Link to MSDN documentation: 

Several decoders are currently supported, in particular H.2, MPEG2, VC1 and WMV3.

DXVA2 hardware acceleration only works on Windows. In order to build FFmpeg with DXVA2 support, you need to install the dxva2api.h header. For MinGW this can be done by downloading the header maintained by VLC:

and installing it in the include patch (for example in /usr/include/).

For MinGW, the dxva2api.h is provided by default. One way to install mingw-w is through a pacman repository, and can be installed using one of the two following commands, depending on the architecture:

pacman -S mingw-w-i686-gcc
pacman -S mingw-w-x86_-gcc

To enable DXVA2, use the --enable-dxva2 ffmpeg configure switch.

To test decoding, use the following command:

ffmpeg -hwaccel dxva2 -threads 1 -i INPUT -f null - -benchmark

VDA

Video Decoding API, only supported on MAC. H.2 decoding is available in FFmpeg/libavcodec.

Developers documentation: 

NVENC

NVENC is an API developed by NVIDIA which enables the use of NVIDIA GPU cards to perform H.2 and HEVC encoding. FFmpeg supports NVENC through the h2_nvenc and hevc_nvencencoders. In order to enable it in FFmpeg you need:

  • A supported GPU
  • Supported drivers
  • ffmpeg configured without --disable-nvenc

Visit  to download the SDK and to read more about the supported GPUs and supported drivers.

Usage example:

ffmpeg -i input -c:v h2_nvenc -profile high444p -pixel_format yuv444p -preset default output.mp4

You can see available presets, other options, and encoder info with ffmpeg -h encoder=h2_nvenc or ffmpeg -h encoder=hevc_nvenc.

Note: If you get the No NVENC capable devices found error make sure you're encoding to a supported pixel format. See encoder info as shown above.

CUDA/CUVID/NvDecode

CUVID, which is also called nvdec by Nvidia now, can be used for decoding on Windows and Linux. In combination with nvenc it offers full hardware transcoding.

CUVID offers decoders for H2, HEVC, MJPEG, mpeg1/2/4, vp8/9, vc1. Codec support varies by hardware. The full set of codecs being available only on Pascal hardware, which adds VP9 and 10 bit support.

While decoding 10 bit video is supported, it is not possible to do full hardware transcoding currently (See the partial hardware example below).

Sample decode using CUVID, the cuvid decoder copies the frames to system memory in this case:

ffmpeg -c:v h2_cuvid -i input output.mkv

Full hardware transcode with CUVID and NVENC:

ffmpeg -hwaccel cuvid -c:v h2_cuvid -i input -c:v h2_nvenc -preset slow output.mkv

Partial hardware transcode, with frames passed through system memory (This is necessary for transcoding 10bit content):

ffmpeg -c:v h2_cuvid -i input -c:v h2_nvenc -preset slow output.mkv

If ffmpeg was compiled with support for libnpp, it can be used to insert a GPU based scaler into the chain:

ffmpeg -hwaccel_device 0 -hwaccel cuvid -c:v h2_cuvid -i input -vf scale_npp=-1:720 -c:v h2_nvenc -preset slow output.mkv

The -hwaccel_device option can be used to specify the GPU to be used by the cuvid hwaccel in ffmpeg.

Intel QSV

Intel QSV (Quick Sync Video) is a technology which allows decoding and encoding using recent Intel CPU and integrated GPU, supported on recent Intel CPUs. Note that the (CPU)GPU needs to be compatible with both QSV and OpenCL. Some (older) QSV -enabled GPUs aren't compatible with OpenCL. See:  

To enable QSV support, you need the Intel Media SDK integrated in the Intel Media Server Studio: 

The Intel Media Server studio is available for both Linux and Windows, and contains the libva and libdrm libraries, the libmfx dispatcher library and the intel drivers. libmfx is the library which selects the codec depending on the system capabilities, falling back to a software implementation if the hardware accelerated codec is not available).

FFmpeg QSV support relies on libmfx, but the library provided by Intel does not come with pkg-config files and a proper installer. Thus the easiest to install the library is to use the libmfx version packaged by lu_zero here: 

Requirements on Windows: install the Intel Media SDK packaged in the Intel Media Server Studio, which comes with a graphic installer, and a MinGW compilation enviroment (for example provided by MSYS2 with a corresponding Mingw-w package). Then you need to build libmfx and install it in a path recognized by pkg-config. For example if you install in /usr/local then you need the update the $PKG_CONFIG_PATH environment variable to make it point to /usr/local/lib/pkgconfig.

Requriments on Linux: you need either to rely on the Intel Media Server Studio for Linux, or use a recent enough supported system, with the libva and libdrm libraries, the libva Intel drivers, and the libmfx library packaged by lu_zero. Note: in case you use the Intel Media Server Studio generic installation script, the installation script may overwrite your system libraries and break the system.

Check the following website for updated information about the Intel Graphics stack on the various Linux platforms: 

To enable QSV support in the FFmpeg build, configure with --enable-libmfx.

Support for decoding and encoding is integrated in FFmpeg through several codecs identified by the _qsv suffix. In particular, it currently supports MPEG2 video, VC1 (decoding only), H.2 and H.265.

For example to encode to H.2 using h2_qsv, you can use the command:

ffmpeg -i INPUT -c:v h2_qsv -preset:v faster out.qsv.mp4

If you have a Kaby Lake CPU, you can encode with HEVC using hevc_qsv:

ffmpeg -i INPUT -c:v hevc_qsv -load_plugin hevc_hw -preset:v faster out.qsv.mp4

OpenCL

Official website:

Currently only used in filtering (deshake and unsharp filters). In order to use OpenCL code you need to enable the build with --enable-opencl. An API to use OpenCL API from FFmpeg is provided in libavutil/opencl.h. No decoding/encoding is currently supported (yet).

For enable-opencl to work you need to basically install your local graphics cards drivers, as well as SDK, then use its .lib files and headers.

AMD VCE

AMD VCE is exposed through VA-API on linux. For windows there have been port  but nothing official yet.

External resources

http://trac.ffmpeg.org/wiki/HWAccelIntro

转载于:https://www.cnblogs.com/wainiwann/p/6972984.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务