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 VFIO_DEVICE_QUERY_GFX_PLANE
.
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 video/x-raw(memory:VASurface)
?
Alternatively is there a framework 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, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_FORMAT_ENCODED,
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 ! "
" video/x-raw(memory:DMABuf),width=1024,height=768,framerate=0/1,format={BGRx,BGRx:0x0100000000000001} ! "
" vaapipostproc !"
" vaapih265enc !
...
which obviously does not work, because vaapipostproc can not be linked with the filter.