在移植 FFMPEG 時心裡一直有個疑問,該如何得知 FFMPEG 所移植的平台是否支援硬體加速呢?若 FFMPEG 函數庫本身可以直接使用機器上的硬體加速,這樣是不是就不需要擔心 decode/encode 的速度了。
1. 當你呼叫 avcodec_register_all()時, ffmpeg 便會幫你註冊對應的硬體加速函數,以 h264為例,如下:
REGISTER_HWACCEL(H264_DXVA2, h264_dxva2);
REGISTER_HWACCEL(H264_VAAPI, h264_vaapi);
REGISTER_HWACCEL(H264_VDA, h264_vda);
REGISTER_HWACCEL(H264_VDPAU, h264_vdpau);
分別對應四種硬體加速的函數庫
- DirectX Video Acceleration (DXVA) is a Microsoft API specification for the Microsoft Windows and Xbox 360 platforms that allows video decoding to be hardware accelerated.
- Video Acceleration API (VA API) is an open source software library ("libVA") and API specification.
- VDPAU (Video Decode and Presentation API for Unix) is an open source library (libvdpau) and API originally designed by Nvidia for its GeForce 8 series and later GPU hardware,[1][2] targeted at the X Window System on Unix-Like operating systems (including Linux, FreeBSD, and Solaris).
- VDA (Video Decode Acceleration Framework) is Apple Inc.'s API for hardware-accelerated decoding of H.264 on Mac OS X and iOS
2. 參考 h264.c, ffmpeg 在 decode 時利用 ff_find_hwaccel() 以取得硬體加速的處理函數
decode_frame()
decode_nal_units()
decode_slice_header()
h264_slice_header_init()
ff_find_hwaccel()
3. 若能夠查詢到對應的函數,那麼便可以認為 ffmpeg 在該平台上針對此種 codec,使用硬體提供的encode/decode加速功能。
AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
參考資料
- VAAPI
- http://en.wikipedia.org/wiki/Video_Acceleration_API
- VDPAU(Video Decode and Presentation API for Unix)
- http://zh.wikipedia.org/wiki/VDPAU
- http://forum.xbmc.org/showthread.php?tid=143446