[FFmpeg-trac] #8450(avdevice:new): x11grab doesn't work with headless X servers

FFmpeg trac at avcodec.org
Mon Dec 30 18:05:24 EET 2019


#8450: x11grab doesn't work with headless X servers
----------------------------------+----------------------------------
             Reporter:  eero-t    |                     Type:  defect
               Status:  new       |                 Priority:  normal
            Component:  avdevice  |                  Version:  4.1.4
             Keywords:            |               Blocked By:
             Blocking:            |  Reproduced by developer:  0
Analyzed by developer:  0         |
----------------------------------+----------------------------------
 Summary of the bug:

 FFmpeg x11grab doesn't work with headless X server configurations.

 How to reproduce:
 1. Start headless X server:
 {{{
 Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp
 }}}
 2. Try streaming that with FFmepg:
 {{{
 $ ffmpeg  -an -f x11grab -video_size 1920x1080 -framerate 2 -i :99 -c:v
 libx264 -tune zerolatency -pix_fmt nv12 -b:v 5000k -f flv
 rtmp://hostname/live/desktop
 ffmpeg version 4.1.4-1build2 Copyright (c) 2000-2019 the FFmpeg developers
   built with gcc 9 (Ubuntu 9.2.1-4ubuntu1)
 ...
 [x11grab @ 0x5652189c7b80] Cannot get the image data event_error:
 response_type:0 error_code:128 sequence:9 resource_id:4194304 minor_code:4
 major_code:130.
 [x11grab @ 0x5652189c7b80] Stream #0: not enough frames to estimate rate;
 consider increasing probesize
 Input #0, x11grab, from ':99':
   Duration: N/A, bitrate: N/A
     Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 2
 fps, 1000k tbr, 1000k tbn, 1000k tbc
 Stream mapping:
   Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
 ...
 Output #0, flv, to 'rtmp://192.168.0.8/live/desktop':
   Metadata:
     encoder         : Lavf58.20.100
     Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), nv12,
 1920x1080, q=-1--1, 5000 kb/s, 2 fps, 1k tbn, 8 tbc
     Metadata:
       encoder         : Lavc58.35.100 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/5000000 buffer size: 0 vbv_delay: -1
 frame=    2 fps=0.0 q=7.0 size=       2kB time=00:00:00.12 bitrate=
 104.4kbits/s dup=0 drop=4 speed=0.2frame=    2 fps=1.8 q=7.0 size=
 2kB time=00:00:00.12 bitrate= 104.4kbits/s dup=0 drop=9 speed=0.1frame=
 2 fps=1.1 q=7.0 size=       2kB time=00:00:00.12 bitrate= 104.4kbits/s
 dup=0 drop=14 speed=0.frame=    2 fps=0.9 q=7.0 size=       2kB
 time=00:00:00.12 bitrate= 104.4kbits/s dup=0 drop=18 speed=0.
 ...
 }}}

 Outcome is that FFmpeg is forever stuck at dropping frames.

 FFmpeg code outputs above warning from two places here:
 https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/xcbgrab.c

 Checking the X protocol headers, tells that "minor_code:4 major_code:130"
 is ShmGetImage(), i.e. culprit is xcbgrab_frame_shm() function.

 In the Xvfb case, I can add "-shmem" option to get X root window to be
 available as shared memory:
 https://www.x.org/archive/X11R7.5/doc/man/man1/Xvfb.1.html

 HOWEVER, while that gets FFmpeg streaming working, then the use-cases
 which output I'd like to stream, don't work!  (Those use-cases use GL with
 Mesa)

 If I try to use Xdummy instead of Xvfb (to get 3D acceleration working for
 X clients):
 * https://xpra.org/trac/wiki/Xdummy
 * https://packages.ubuntu.com/eoan/xserver-xorg-video-dummy

 FFmpeg fails with that too, but I didn't find any Xdummy option that would
 allow FFmpeg to work with it.

 In summary, there are several issues:
 * Error message that's incomprehensible to normal users
 * Not stopping when things have failed completely (=FFmpeg can't acquire
 any input frames)
 * FFmpeg code seems to have also a non-SHM function for getting the
 frames, but FFmpeg doesn't seem to fallback to that, or that part is
 broken for some other reason which doesn't show up in FFmpeg output

 PS. "xdpyinfo" shows following for Xdummy:
 {{{
 name of display:    :99
 version number:    11.0
 vendor string:    The X.Org Foundation
 vendor release number:    12005000
 X.Org version: 1.20.5
 maximum request size:  16777212 bytes
 motion buffer size:  256
 bitmap unit, bit order, padding:    32, LSBFirst, 32
 image byte order:    LSBFirst
 number of supported pixmap formats:    7
 supported pixmap formats:
     depth 1, bits_per_pixel 1, scanline_pad 32
     depth 4, bits_per_pixel 8, scanline_pad 32
     depth 8, bits_per_pixel 8, scanline_pad 32
     depth 15, bits_per_pixel 16, scanline_pad 32
     depth 16, bits_per_pixel 16, scanline_pad 32
     depth 24, bits_per_pixel 32, scanline_pad 32
     depth 32, bits_per_pixel 32, scanline_pad 32
 keycode range:    minimum 8, maximum 255
 focus:  PointerRoot
 number of extensions:    28
     BIG-REQUESTS
     Composite
     DAMAGE
     DOUBLE-BUFFER
     DPMS
     DRI2
     DRI3
     GLX
     Generic Event Extension
     MIT-SCREEN-SAVER
     MIT-SHM
     Present
     RANDR
     RECORD
     RENDER
     SECURITY
     SHAPE
     SYNC
     X-Resource
     XC-MISC
     XFIXES
     XFree86-DGA
     XFree86-VidModeExtension
     XINERAMA
     XInputExtension
     XKEYBOARD
     XTEST
     XVideo
 default screen number:    0
 number of screens:    1

 screen #0:
   dimensions:    1920x1080 pixels (508x285 millimeters)
   resolution:    96x96 dots per inch
   depths (7):    24, 1, 4, 8, 15, 16, 32
   root window id:    0x14a
   depth of root window:    24 planes
   number of colormaps:    minimum 1, maximum 1
   default colormap:    0x20
   default number of colormap cells:    256
   preallocated pixels:    black 0, white 16777215
   options:    backing-store WHEN MAPPED, save-unders NO
 ...
 }}}

 I.e. MIT-SHM extension is suppported, X root window just isn't using it.

--
Ticket URL: <https://trac.ffmpeg.org/ticket/8450>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list