喂食1610x996图像时,Gstreamer appsrc无效缓冲区大小错误

时间:2016-04-28 12:51:20

标签: opencv gstreamer nvidia

我正在尝试使用以下管道提供nvidia h264编码器(nvvidconv)OpenCv Mat:

#define CAPS_APPSRC "video/x-raw, format=(string)I420,width=(int)1610, height=(int)996, framerate=25/1"
#define CAPS_NVCONV "video/x-raw(memory:NVMM)"
#define CAPS_OMX "video/x-h264, stream-format=(string)byte-stream"
descr = g_strdup_printf ("appsrc name=src_name ! " CAPS_APPSRC " ! omxh264enc ! " CAPS_OMX " ! h264parse ! flvmux ! filesink location=test.mp4");

垫框尺寸为1610x996 BGR转换为I420

cvtColor(g_frame,frame420,CV_BGR2YUV_I420);

g_frame是1610x996

frame420出现为1610x1494 [(1610x1494 * 1.5)= 2405340]

在颜色转换后的appsrc回调中,我分配一个新缓冲区并复制Mat数据,如下所示:

    size = frame420.step * frame420.rows;

    buffer = gst_buffer_new_allocate (NULL, size, NULL);
    gst_buffer_map(buffer,&info,GST_MAP_WRITE);

    memcpy(info.data,frame420.ptr(),size);
    gst_buffer_unmap(buffer,&info);

然后将缓冲区提供给appsrc,如下所示:

GST_BUFFER_PTS (buffer) = timestamp;
    GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 25);
    timestamp += GST_BUFFER_DURATION (buffer);
    g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);

但是当我运行管道时,它会出现以下错误:

0:00:00.079123916  4112   0x2ac400 ERROR                default video-frame.c:149:gst_video_frame_map_id: invalid buffer size 2405340 < 2410320
0:00:00.079192404  4112   0x2ac400 ERROR            omxvideoenc /dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomxvideoenc.c:1778:gst_omx_video_enc_fill_buffer:<omxh264enc-omxh264enc0> Invalid input buffer size

错误中提到的缓冲区大小&#34; 2405340&amp; 2410320 &#34; 2405340是可以理解的,因为它的数据大小正在作为输入提供。 2410320来自哪里?

为什么会发生这种情况?

现在,如果我只是将缓冲区大小调整为1600x996,那么相同的管道工作正常。它也适用于任何标准分辨率e-g 1280x720等

0 个答案:

没有答案