0

I am trying to write my own screencast script based on FFmpeg. I want to be able to draw a rectangle on the screen and force FFmpeg to make a screencast of this area only, for that I would need the coordinates of x,y of the starting point, and the resolution of the selected area. I can draw a rectangular area with scrot -s and I can also get the coordinates with xdotool getmouselocation but I don't know how I can save the location of the scrot start location.

I am imagining my script will be something like this:

  1. scrot -s - draw a rectangular area on the screen
  2. save start_x, start_y locations in a variable
  3. ffmpeg -i scrot_screenshot - to get resolution of the selected area
  4. ffmpeg -video_size $area_resolution -f x11grab -i :0.0+start_x,start_y screen_capture.mp4 - to create the screencast

So I need a solution for 2 only, I can do the rest of the script on my own.

I can, of course, use a different than scrot command for drawing the rectangular area of the screen, but so far, I didn't find a suitable replacement.

The final goal is to create such a script and I will for sure publish it on my Github account with the respective documentation on how to use it.

Georgi Stoyanov
  • 790
  • 4
  • 16
  • 41

1 Answers1

1

Try this;

#!/bin/bash

echo click T.L.
echo -ne "\e[?1000h"
while read -srn 6; do
    eval "$(xdotool getmouselocation --shell)"
    TL=$X,$Y
    echo -ne "\e[?1000l"
    break
done
sleep 0.5
echo click B.R.
echo -ne "\e[?1000h"
while read -srn 6; do
    eval "$(xdotool getmouselocation --shell)"
    BR=$X,$Y
    echo -ne "\e[?1000l"
    break
done
echo "$TL.$BR"

with a transparent term over the area you want to record.

ref; https://stackoverflow.com/a/5970472/1133275

user1133275
  • 5,488
  • 1
  • 19
  • 37
  • I think this solution is only working if you are clicking inside the terminal window and if you click outside of it it doesn't register the click so it won't really work in my case. Plus, I want to be able to execute a rectangular select of an area similar to `scrot -s` eventually even changing the mouse cursor. I am using `urxvt` by the way. – Georgi Stoyanov Apr 26 '20 at 15:14
  • 1
    @George did you understand the "transparent term" workaround? – user1133275 Apr 27 '20 at 01:28
  • ah, yes, you are right, I missed that part @user1133275 – Georgi Stoyanov Apr 27 '20 at 07:00