<html><head><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="DE" link="#0563C1" vlink="#954F72" style="word-wrap:break-word"><div>Hi,</div><div><br></div><div>Le lundi 20 février 2023 à 18:00 +0100, Michael via gstreamer-devel a écrit :</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal"><span lang="EN-GB">Hello,<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">I want to encode a framebuffer I got via dmabuf into a video stream. I have a dmabuf file descriptor which contains the framebuffer.<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">I got the filedescriptor from the intel i915 driver via ioctl VFIO_DEVICE_QUERY_GFX_PLANE. <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">The dmabuf has the format BGRx and modifier is 0 respectively changes to I915_FORMAT_MOD_X_TILED.<o:p></o:p></span></p><p class="MsoNormal"></p></div></blockquote><div><br></div><div>I'm a bit unclear what you mean, is it 0 / LINEAR or I915_FORMAT_MOD_X_TILED ?</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">Now I want to encode it per zero copy in gstreamer into a video stream (h264, h265 etc...). <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">I push the single frames per appsrc into the gstreamer pipline. Since I use intel hardware I thought it makes sense to use VAAPI.<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">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).</span></p></div></blockquote><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">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)?<o:p></o:p></span></p><p class="MsoNormal"></p></div></blockquote><div><br></div><div>The data is in RGB and the encoders only support YUV, so you must apply a conversion to the buffers anyway. You should be using vaapipostproc (or vapostproc) to adapt using hardware acceleration. Note that you don't need the dmabuf caps feature if you have linear buffers. The GstDmabufAllocator utility will wrap your dmabuf and implement CPU mapping in case it would be the only option. </div><div><br></div><div>Nicolas</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">A lternatively is there a plugin which is better suited than vaapi?<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">My code to push the frames into gstreamer currently looks like this:<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    GstMemory* mem = gst_dmabuf_allocator_alloc(vedpy->gdata.allocator, dmabuf->fd, dmabuf->width * dmabuf->height * (dmabuf->stride/1024));<o:p></o:p></span></p><p class="MsoNormal"></p></div></blockquote><div><br></div><div>Very strange size formula, should be just "dmabuf->height * dmabuf->stride".</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB">    vedpy->gdata.buffer = gst_buffer_new();<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    gst_buffer_append_memory(vedpy->gdata.buffer, mem );<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    gsize offset[GST_VIDEO_MAX_PLANES] = {0, 0, 0, 0};<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    gint stride[GST_VIDEO_MAX_PLANES] = {dmabuf->stride, 0, 0, 0};<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    gst_buffer_add_video_meta_full( vedpy->gdata.buffer, GST_VIDEO_FRAME_FLAG_NONE,<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">                                    GST_VIDEO_FORMAT_ENCODED,<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">                                    dmabuf->width, dmabuf->height, 1, offset, stride);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    GstFlowReturn ret;<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    vfio_encode_dpy *vedpy = container_of(dcl, vfio_encode_dpy, dcl);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    g_signal_emit_by_name (vedpy->gdata.source, "push-buffer", vedpy->gdata.buffer, &ret);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    ...<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">   <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">And my pipline:<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">char launch_stream[]  = "appsrc name=source ! "<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    " video/x-raw(memory:DMABuf),width=1024,height=768,framerate=0/1,format={BGRx,BGRx:0x0100000000000001} ! "<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    " vaapipostproc !"<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    " vaapih265enc ! <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">    ...<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">which obviously does not work, because vaapipostproc cannot be linked with the filter.<o:p></o:p></span></p><p class="MsoNormal"></p></div></blockquote><div><br></div><div>I think are using work-in-progress drm-modifier branch. I think the plan is to ignore the old vaapi plugin, and only implement this for the new VA plugin (just try and replace every vaapi* element into va* names).</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">Thanks in advance.<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-GB">Best Regards,<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB">Michael<o:p></o:p></span></p></div></blockquote><div><br></div><div><span></span></div></body></html>