Search code examples
gstreamerscreencast

Using Gstreamer to capture screen and show it in a window?


I need to capture the screen of the second display and "monitor" it in the main display, inside a window (scaled at x0.5 and with neighbor interpolation because I prefer performance against quality). From this link, I've got this screencast command:

gst-launch ximagesrc ! ffmpegcolorspace ! queue \
! vp8enc quality=10 speed=2 ! mux. alsasrc ! audio/x-raw-int ! queue \
! audioconvert ! vorbisenc ! mux. webmmux name=mux \
! filesink location=screencast.webm

... but it capture to a file (not a window), it's missing the scale and interpolation type, the sounds is not necessary, etc.

As I'm familiar with libav, what I'm looking for is something similar to this:

avconv -f x11grab -r 30 -s 1280x1024 -i :0.1 -c:v mpeg4 -b:v 1000k \
-vf "hflip" -vf "scale=640:480" -sws_flags "neighbor" -f avi - | avplay -i -

... I would use it, but it has some problems with the framerate (asked here). So, I'm looking for an alternative in Gstreamer.


Solution

  • Here is the gst-launch command:

    gst-launch-1.0 ximagesrc startx=1280 use-damage=0 ! video/x-raw,framerate=30/1 ! videoscale method=0 ! video/x-raw,width=640,height=480  ! ximagesink
    

    Explanation:

    parameter startx = start recording from "pixel column" 1280 - that is if you have two 1280 width monitors it will start with the one on the right side.

    parameter use-damage set to 0 = do not use XDamage. damage counts only differences between subsequent frames which is apparantly quite CPU demanding.

    element ximagesink = X server created window as output - its less CPU demanding than glimagesink (opengl accelerated window).

    element videoscale parameter method to 0 meaning nearest neighbor as suggested by Mario Mey in comment. This resulted for me in CPU save from 17% to 12%.

    There is also configurable fps and height/width of display window(I think its clear enough).