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.

Community
  • 1
  • 1
Mario Mey
  • 1,582
  • 3
  • 13
  • 13
  • please provide [mcve](http://stackoverflow.com/help/mcve), if you have something and its not working we can move on with answers. But I will give you a [hint](https://www.google.com/search?q=linux+gstreamer+screen+capture), good luck – nayana Nov 18 '15 at 13:20
  • @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. – Mario Mey Nov 19 '15 at 14:06

1 Answers1

20

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

nayana
  • 3,787
  • 3
  • 20
  • 51
  • 2
    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](https://groups.google.com/d/msg/gstreamer-java/1WiZrIy9ziM/8P293-sLR4EJ)) – Mario Mey Nov 24 '15 at 14:16
  • 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. – nayana Nov 24 '15 at 15:02
  • 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? – dǝɥɔS ʇoıןןƎ Jul 04 '19 at 13:47
  • @ratskin well you should create another question for that.. its quite different from this one – nayana Jul 09 '19 at 09:23
  • @nayana You're right, and I already did https://unix.stackexchange.com/questions/528400/how-can-i-stream-my-desktop-screen-to-dev-video1-as-a-fake-webcam-on-linux – dǝɥɔS ʇoıןןƎ Jul 09 '19 at 09:48