FFmpeg/vaapi Sample Player (ffvademo)
Copyright (C) 2014 Intel Corporation Author: Gwenole Beauchesne [email protected]
The FFmpeg/vaapi Sample Player (ffvademo) and its associated helper library are available available under the terms of the GNU Lesser General Public License v2.1+
This project consists in a simple FFmpeg/vaapi based video player, and an associated helper library, that demonstrate how to use FFmpeg with Video Acceleration (VA) APIs.
- FFmpeg decoder with VA-API support
- Native X11 renderer through vaPutSurface()
- EGL renderer showing off VA/EGL interop capabilities
Non-goals
- A full-blown player supporting every possible codec
- A player that supports audio decoding
- A player that supports software decoding
Software requirements
- VA-API (>= 0.36.0 for VA/EGL interop)
- FFmpeg (>= 2.1)
-
Play an H.264 video with an MP4 container $ ffvademo /path/to/video.mp4
-
Play a VC-1 video while converting the output to I420 format $ ffvademo -f yuv420p /path/to/video.wmv
-
Play an H.264 video while rendering with EGL/GLESv2 $ ffvademo -r egl -f argb /path/to/video.mp4
- sudo apt install libva-dev libegl-dev,安装编译依赖。
- 使用cmake . 在本地生成Makefile
- make编译,得到ffvademo可执行程序。
- 执行./ffvademo a.mp4 -r egl,使用egl渲染视频。
- 假如没有找到 vaapi 后端库,试试 export LIBVA_DRIVER_NAME=jmgpu,然后再运行ffvademo程序。
- ffmpeg调用vaapi解码,得到一个AVFrame
- 取AVFrame的data[3],得到一个VASurfaceID
- 通过vaDeriveImage将VASurfaceID转换成一个VAImage
- 通过avAcquireBufferHandle将AVImage的信息提取出来,得到VABufferInfo
- 通过eglCreateImageKHR,将VABufferInfo的内容填充到attributes中,根据这个信息创建衣蛾EGLImageKHR
- 使用eglImageTargetTexture2DOES,将EGLImageKHR附加到opengl的texture上。
- 之后就是正常的opengl纹理操作。
以上就是vaapi解码的数据,是如何与opengl结合,显示在界面上的。其他的细节这里忽略。在贴纹理显示视频之前,需要调用 vaSyncSurface,来保证解码已经处理完,否则可能会出现绿色的墙砖一样的问题。