0

I want to grab the coordinates of a rectangular box which the user selects on a display. Like in screen recording programs, when you choose the "record area only" option. It allows you to select which area you want to capture instead of the whole screen.

This is an example: https://i.stack.imgur.com/v82yV.jpg

Now, programmatically, how such thing can be retrieved? I mean, is there any library I can use? Python bindings would be great.

Madno
  • 910
  • 2
  • 12
  • 27
  • This may be (close to) a duplicate of: http://stackoverflow.com/questions/8249669/how-do-take-a-screenshot-correctly-with-xlib. There's quite a few questions on this topic – DavidW Feb 18 '17 at 16:20
  • @DavidW No. That's totally in C. And I am not looking for the "screencasting" method. I am looking for a method to get the coordinates only. In Python. Searching for a library which may do so. – Madno Feb 18 '17 at 16:29
  • Sorry yes I misunderstood I think. – DavidW Feb 19 '17 at 08:55
  • https://github.com/kekeimiku/slurp-x solves it in Rust. It depends on `xcb` which in turn is a replacement of `Xlib` – darw Jul 06 '22 at 21:49

1 Answers1

1

GStreamer allows you to achieve this. Here is an example command line for Linux:

gst-launch-1.0 ximagesrc ! videocrop left=125 right=500 top=200 bottom=200 ! autovideosink

Python binding exist for this framework. Here is a tutorial you can use to port the pipeline I propose into Python: http://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.pdf

The random values I set for cropping might be updated according to the resolution of your screen and mouse pointer position you get with python-xlib. Related question here:

Monitor mouse coordinates in real-time in Linux

Community
  • 1
  • 1
Ahresse
  • 497
  • 4
  • 17
  • But this is not what I am looking for. I am looking for that thing which will give me the cropping. Not I provide it. And the document you sent doesn't give an example on this. – Madno Feb 19 '17 at 10:18