13

Is it possible with ffmpeg grab a window that is minimized or that not has the focus (there is another window over but ffmpeg records only the window which is below)?

With a command like ffmpeg -f x11grab -r 30 -i :0.0+x,y -f flv rtmp://url?

Pioz
  • 233
  • 1
  • 2
  • 9

2 Answers2

13

AFAIK it's not possible to capture a specific window with ffmpeg, the x11grab entry in the manual only refers to screens https://www.ffmpeg.org/ffmpeg-devices.html#x11grab and it suggests that the region you specify is static (if you move the window ffmpeg does not follow it):

However GStreamer offers some more flexibility in this case:

gst-launch-1.0 ximagesrc xid=0x04000007 ! videoconvert ! autovideosink

This works with out-of focus windows and you can even move them but it does NOT work with minimized windows.

As you may know, you can get the window id with wmctrl -l.

You can see the options supported by GStreamer elements using the gst-inspect-1.0 program, e.g.:

gst-inspect-1.0 ximagesrc
Antonio Ospite
  • 191
  • 2
  • 5
4

I do not know if it was possible when this question was asked long time ago, but for the sake of completeness I had now success with:

ffmpeg -f x11grab -framerate 25 $(slop -D -f '-video_size %wx%h -i +%x,%y') out.mp4

Having slop installed makes this much easier, but the coordinates can also entered by hand of cause. It is then something like -video_size 640x480 -i +0,100 to capture a 640x480 sized video with the topper left corner in position x=0 and y=100 (screen coordinates). The -i [X],[Y] syntax is not really intuitive.

user298427
  • 149
  • 4
  • 2
    This appears to be capturing a specific area of the screen, rather than a particular window (meaning if you move the window, you'll now be recording whatever was behind the window). – larsks Mar 09 '21 at 12:57
  • I have improved my answer and added the -D flag to slop. It allows a double click on a window and was introduced nine month ago in https://github.com/naelstrof/slop/commit/978e6e8d24cf74b365d2ee39a6fed36022dcf661 – user298427 Mar 12 '21 at 18:47
  • 1
    This answer assumes that you have graphics env which could not be always the case. – rkachach Aug 25 '21 at 08:33