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

1

9

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.

Helicoid answered 17/11, 2015 at 1:9 Comment(2)
please provide mcve, if you have something and its not working we can move on with answers. But I will give you a hint, good luckHighup
@otopolsky: I edited the question, trying to provide mcve. I had already searched for you hint and that's how I had found the gst-launch command that I just added.Helicoid
H
21

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).

Highup answered 20/11, 2015 at 8:24 Comment(5)
This is what I need, thank you! I had to use ximagesink instead of glimagesink (it says WARNING: erroneous pipeline: no element "glimagesink"). And I added "method=0" to use a nearest-neighbour interpolation to videoscale, to make it even cheaper (from here)Helicoid
thanks @MarioMey I updated the answer. so you are missing glimagesink. But funny enough - I made some tests and its much faster with ximagesink than glimagesink - I will further edit my answer.Highup
I was trying to swap ximagesink with v4l2sink device=/dev/video1. This doesn't produce any errors, except the "webcam" doesn't actually work in Firefox or Chrome. Any chance you could help?Rambert
@ratskin well you should create another question for that.. its quite different from this oneHighup
@Highup You're right, and I already did unix.stackexchange.com/questions/528400/…Rambert

© 2022 - 2024 — McMap. All rights reserved.