[FFmpeg-devel] [PATCH 5/5] lavd: Add KMS frame grabber

Andy Furniss adf.lists at gmail.com
Wed Sep 20 00:21:24 EEST 2017


Mark Thompson wrote:
> On 15/09/17 00:15, Andy Furniss wrote:
>> Andy Furniss wrote:
>>> Mark Thompson wrote:
>>>> ---
>>>> Now sets the trusted packet flag; otherwise unchanged.
>>>>
>>>>
>>>>    configure                |   1 +
>>>>    libavdevice/Makefile     |   1 +
>>>>    libavdevice/alldevices.c |   1 +
>>>>    libavdevice/kmsgrab.c    | 455 +++++++++++++++++++++++++++++++++++++++++++++++
>>>>    4 files changed, 458 insertions(+)
>>>>    create mode 100644 libavdevice/kmsgrab.c
>>>>
>>>> diff --git a/configure b/configure
>>>> index 6581c53c1a..76a7591ceb 100755
>>>> --- a/configure
>>>> +++ b/configure
>>>> @@ -3040,6 +3040,7 @@ gdigrab_indev_select="bmp_decoder"
>>>>    iec61883_indev_deps="libiec61883"
>>>>    jack_indev_deps="jack"
>>>>    jack_indev_deps_any="sem_timedwait dispatch_dispatch_h"
>>>> +kmsgrab_indev_deps="libdrm"
>>>
>>> Doesn't get built for me = doesn't show up as indev after configure anything special needed?
>>
>> Never mind I found --enable-libdrm (had tried --enable-kmsgrab)
> 
> I assume you're going to try AMD + Mesa + VAAPI.
> 
> VAAPI_DISABLE_INTERLACE=1 ./ffmpeg_g -y -format bgr0 -device /dev/dri/card1 -f kmsgrab -i - -vsync 0 -init_hw_device vaapi=v:/dev/dri/renderD129 -filter_hw_device v -vf 'hwmap,scale_vaapi=w=1920:h=1080:format=nv12' -c:v h264_vaapi -profile 578 -bf 0 out.mp4
> 
> Three Mesa issues I had to get around:
> 
> * Device derivation doesn't work because the Mesa driver doesn't want to initialise on the DRM master device for some reason; making the matching device separately does work.
> * Against current git, you need to reapply the VAAPI_DISABLE_INTERLACE patch and use it - if not, the colour conversion just barfs because it wants interlaced surfaces.
> * The postproc scaler seems to only write the luma plane when converting from RGB - this is also visible when uploading normal RGB images, so just a bug somewhere.
> 
> With that, it works to record the screen in greyscale...
> 
> I have some other Mesa stuff to do queued up (libva2 with VAAPI export for EGL import on AMD), so I'll pursue these further soonish.

Leo just posted a patchset on the mesa list that makes vaapi work better 
with this and postproc generally.

You don't need the env with those and kmsgrab is now working for me - up 
to a point ...

That point being around 7k frames it will run out of something.

[AVHWFramesContext @ 0x31ed880] Failed to create surface from DRM 
object: 2 (resource allocation failed).
[Parsed_hwmap_0 @ 0x3114c40] Failed to map frame: -5.

I see that memory is reducing before this although I still have spare - 
is this the same issue you explained on users WRT leaking on decode?


More information about the ffmpeg-devel mailing list