Adobe Captivate

Time:2021-4-30

In the postscript of “using bash script to write a screen capture tool”, I changed the screen capture script slightly and got a script that can record the specified window area in the screen. Turn your hand over to cloud, cover your hand with rain, thanks to ffmpeg.

Adobe Captivate

I have no new idea to name the script of this recording screen recorder, and the content is as follows:

#!/bin/bash
NAME=$(date +"%Y-%m-%d %T" | sed -e "s/ /-/g; s/:/-/g")
RECORD=/tmp/${NAME}.mkv
OUTPUT=/tmp/output-${NAME}.mkv

#Get screen resolution
SCREEN=$(xrandr | grep -o "current [0-9]* x [0-9]*" | sed -e 's/current *//g')
SCREEN_W=$(echo $SCREEN | sed -e 's/ x [0-9]*//')
SCREEN_H=$(echo $SCREEN | sed -e 's/[0-9]* x //')

#Get window geometry parameters
declare -a WIN_PARAMS
WIN_PARAMS=($(xwininfo | sed -n -e '/^[[:space:]]*Absolute ..*[XY]/p; 
                      /^[[:space:]]*Relative ..*[XY]/p; 
                      /^[[:space:]]*Width:/p; 
                      /^[[:space:]]*Height:/p' | awk 'BEGIN{FS=":"}{print $2}'))

#Construct the ideal screenshot area.
#The reason for this is related to the relative coordinates of the upper left corner of the window output by xwininfo.
MARGIN=${WIN_PARAMS[2]}
WIN_X=$((${WIN_PARAMS[0]} - ${WIN_PARAMS[2]}))
WIN_Y=$((${WIN_PARAMS[1]} - ${WIN_PARAMS[3]}))
WIN_W=$((${WIN_PARAMS[4]} + ${WIN_PARAMS[2]} + $MARGIN))
WIN_H=$((${WIN_PARAMS[5]} + ${WIN_PARAMS[3]} + $MARGIN))

#Cross border processing of screenshot area
if (($WIN_X < 0)); then WIN_X=0; fi
if (($WIN_Y < 0)); then WIN_Y=0; fi
if (($WIN_W + $WIN_X > $SCREEN_W)); then WIN_W=$(($SCREEN_W - $WIN_X)); fi
if (($WIN_H + $WIN_Y > $SCREEN_H)); then WIN_H=$(($SCREEN_H - $WIN_Y)); fi

#Record the specified window area
ffmpeg -video_size ${WIN_W}x${WIN_H} \
       -framerate 30 -f x11grab \
       -i :0.0+${WIN_X},${WIN_Y} \
       -c:v libx264rgb -crf 0 -preset ultrafast $RECORD

#Video post processing
ffmpeg -i $RECORD -c:v libx264rgb -crf 0 -preset veryslow $OUTPUT

Then I feel sorry that I can’t bind to a shortcut key in the desktop environment like the screen capture script. The reason is that when ffmpeg is recording the screen, I need to press it in the command line windowqKey to end the screen recording. At that time, I felt that there was no solution. Screen capture script will automatically exit after catching the screen, so there is no such problem.

But when I was just about to go to bed, I suddenly felt that I was really pedantic. I can bind the shortcut key of the desktop environment to a script that can run the command line window, and then connect the command line window with the recorder in this script.

Once the brain hole is opened, I went to investigate the command-line window program mate terminal in my desktop environment and found that it really allows me to pass the record script to it in the form of parameters and run it

$ mate-terminal -e recorder

In fact, in my desktop environment, there is no need to write a script to run mate terminal, just bind a shortcut key for mate terminal with parameters in the desktop shortcut key binding settings.

Adobe Captivate

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]