Encoding a DMABuf into a video stream with VAAPI

xaterus at gmail.com xaterus at gmail.com
Mon Feb 20 17:00:12 UTC 2023




I want to encode a framebuffer I got via dmabuf into a video stream. I have
a dmabuf file descriptor which contains the framebuffer.

I got the filedescriptor from the intel i915 driver via ioctl

The dmabuf has the format BGRx and modifier is 0 respectively changes to


Now I want to encode it per zero copy in gstreamer into a video stream
(h264, h265 etc...). 

I push the single frames per appsrc into the gstreamer pipline. Since I use
intel hardware I thought it makes sense to use VAAPI.

The problem is that the sink pads of vaapi only support video/x-raw and
video/x-raw(memory:VASurface) and I have video/x-raw(memory:DMABuf).


Is there any way to convert video/x-raw(memory:DMABuf) to
video/x-raw(memory:VASurface) (zero copy) or import the DMABuf directly as


Alternatively is there a plugin which is better suited than vaapi?


My code to push the frames into gstreamer currently looks like this:


    GstMemory* mem = gst_dmabuf_allocator_alloc(vedpy->gdata.allocator,
dmabuf->fd, dmabuf->width * dmabuf->height * (dmabuf->stride/1024));

    vedpy->gdata.buffer = gst_buffer_new();

    gst_buffer_append_memory(vedpy->gdata.buffer, mem );


    gsize offset[GST_VIDEO_MAX_PLANES] = {0, 0, 0, 0};

    gint stride[GST_VIDEO_MAX_PLANES] = {dmabuf->stride, 0, 0, 0};

    gst_buffer_add_video_meta_full( vedpy->gdata.buffer,


                                    dmabuf->width, dmabuf->height, 1,
offset, stride);

    GstFlowReturn ret;

    vfio_encode_dpy *vedpy = container_of(dcl, vfio_encode_dpy, dcl);

    g_signal_emit_by_name (vedpy->gdata.source, "push-buffer",
vedpy->gdata.buffer, &ret);



And my pipline:


char launch_stream[]  = "appsrc name=source ! "

BGRx:0x0100000000000001} ! "

    " vaapipostproc !"

    " vaapih265enc ! 



which obviously does not work, because vaapipostproc cannot be linked with
the filter.


Thanks in advance.


Best Regards,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20230220/3699d1ad/attachment.htm>

More information about the gstreamer-devel mailing list