概述
视频解码示例应用程序演示如何使用libv4l2组件分配的缓冲区来解码H.264、H.265、vp8、vp9、mpeg4或mpeg2视频流。
应用程序读取H.264、H.265、VP8、VP9、MPEG4或MPEG2基本视频文件,对其进行解码,并将其传递给EGL渲染器,以显示解码图像,而无需任何额外的内存copy。
支持的视频格式有:
-
H.264
-
H.265号
-
VP8型
-
VP9型
-
MPEG4标准
-
MPEG2标准
编译运行
$ cd $HOME/multimedia_api/samples/00_video_decode
$ make
运行
$ ./video_decode <in-format> [options] <in-file>
$ ./video_decode H264 ../../data/Video/sample_outdoor_car_1080p_10fps.h264
流程图
1.Output Plane接收比特流格式的输入并将其传送给解码器进行解码。
2. 应用程序将解码后的帧以yuv格式传输到Capture Plane。
3. 对于Output Plane,应用程序支持MMAP和USRPTR内存类型。对于Capture Plane,它支持MMAP和DMABUF内存类型。
4. 应用程序还可以从 Capture Plane转储文件。
关键类和结构体
关键的类有两个:NvVideoDeocder,NvEglRenderer,前者是硬件解码器,后者是显示用的渲染器,用于显示图像。
NvVideoDeocder里面有一些成员函数,
NvVideoDecoder包含以下成员:
元素 | 描述 |
---|---|
output_plane | V4l2 output plane |
capture_plane | V4l2 capture plane |
createVideoDecoder | 创建Decoder的静态函数 |
subscribeEvent | 订阅事件 |
setExtControls | Set external control to V4l2 device |
setOutputPlaneFormat | Set output plane format. |
setCapturePlaneFormat | Set capture plane format. |
getControl | TBD |
dqEvent | Dqueue the event which report by V4l2 device. |
isInError | Check if under error state. |
NvVideoDecoder有两个关键成员,output_plane and capture_plane 都继承自NvV4l2ElementPlane.包含以下成员:
Element | Description |
---|---|
setupPlane | Setup the plane of V4l2 element. |
deinitPlane | Destroy the plane of V4l2 element. |
setStreamStatus | Start/Stop the stream. |
setDQThreadCallback | Set the callback function of dqueue buffer thread. |
startDQThread | Start the thread of dqueue buffer. |
stopDQThread | Stop the thread of dqueue buffer. |
qBuffer | Queue V4l2 buffer. |
dqBuffer | Dqueue V4l2 buffer. |
getNumBuffers | Get the number of V4l2 buffer. |
getNumQueuedBuffers | Get the number of V4l2 buffer which under queue. |
getNthBuffer | Gets the NvBuffer object at index n. |
代码分析
下面来看一下代码的具体流程。
程序使用一个