参考链接: https://docs.nvidia.com/jetson/l4t-multimedia/index.html
处理步骤
The following diagram shows the flow through this sample.

The Output Plane receives input in bitstream format and delivers it to the Decoder for decoding.
The Capture Plane transfer decoded frames to the application in YUV format.
For the Output Plane the application supports MMAP and USRPTR memory types. For the Capture Plane it supports MMAP and DMABUF memory types.
The application can also dump files from the Capture Plane.
初始化
一:设置解码器参数
二:创建新的V4L2视频解码器对象
三:创建RGB DMA FD
四:映射到MMAP存储器,并开启流
伪代码示例如下:
/**
* InitDecoder.
*
* @param width: width
* @param height: height
* @param cb: callback
* @param user_data: callback user_data
* return context_t* ctx
*/
context_t* InitDecoder(int width, int height, OnDecodeRecv cb, void* user_data)
{
context_t *ctx = new context_t();
if (ctx == NULL) {
printf("[E]: ctx create err\n");
return NULL;
}
// Initialisation.
// memset(static_cast<void*>(&ctx), 0, sizeof (context_t));
memset(ctx, 0, sizeof (context_t));
ctx->out_pixfmt = 1; //1=nv12; 0=yuv420,用nv12稳定点
ctx->decode_pixfmt = V4L2_PIX_FMT_H264;
ctx->op_mem_type = V4L2_MEMORY_MMAP;
ctx->cp_mem_type = V4L2_MEMORY_DMABUF;
ctx->op_buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
ctx->cp_buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
ctx->fd = -1;
ctx->dst_dma_fd = -1;
ctx->num_queued_op_buffers = 0;
ctx->op_buffers = NULL;
ctx->cp_buffers = NULL;
ctx->display_height = height;
ctx->display_width = width;
pthread_mutex_init(&ctx->queue_lock, NULL);
pthread_cond_init(&ctx->queue_cond, NULL);
ctx->cb = cb;
ctx->user_data = user_data;
int ret = 0;
int flags = 0;
uint32_t idx = 0;
struct v4l2_capability caps; //解码能力结构体
struct v4l2_buffer op_v4l2_buf;
struct v4l2_plane op_planes[MAX_PLANES];
struct v4l2_exportbuffer op_expbuf; //视频输出buffer结构体
NvBufSurfaceAllocateParams rgbParams = {
{
0}};
NvBufSurface *rgb_nvbuf_surf = NULL;
/* The call creates a new V4L2 Video Decoder object
** on the device node "/dev/nvhost-nvdec"
** Additional flags can also be given with which the device
** should be opened.
** This opens the device in Blocking mode.
*/
ctx->fd = v4l2_open(DECODER_DEV, flags | O_RDWR); //创建一个解码对象,默认是阻塞模式
if (ctx->fd == -1)
{
cerr << "Could not open device" << DECODER_DEV << endl;
ctx->in_error = 1;
return NULL;
}
ret = v4l2_ioctl(ctx->fd, VIDIOC_QUERYCAP, &caps); //VIDIOC_QUERYCAP:查询设备能力集
if (ret

本文介绍如何使用NVIDIA Jetson平台上的V4L2 API进行视频解码,包括初始化解码器参数、创建V4L2视频解码器对象、配置内存类型及流处理等步骤,并提供了详细的伪代码示例。
最低0.47元/天 解锁文章
980

被折叠的 条评论
为什么被折叠?



