HOME - My Linux Toy Box

Screen Capture Script

CAPhere gives you the option to save your full screen or to save a 1280x720 area
starting from 36 pixels from the top Thirty six pixels from the top:
-video_size 1280x720 -i :0.0+0,36
For my computer 36 pixels from the top excludes my top panel which I do
not want in my videos.
The script saves ultrafast with minimum compression for speed. When it is re-encoded it will diminish in size with unnoticeable lost in resolution.

Just to add as a note. Your camera does the same thing. For speed the files
are saved large. A simple recoding compresses them without quality loss when
speed and time is not critical.

To find you microphone or headset use the command:
$  arecord --list-devices
This is a result of the command when run:
**** List of CAPTURE Hardware Devices ****
card 0: CinemaTM [Microsoft® LifeCam Cinema(TM)], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: H340 [Logitech USB Headset H340], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Generic [HD-Audio Generic], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Generic [HD-Audio Generic], device 2: ALC662 rev1 Alt Analog [ALC662 rev1 Alt Analog]
  Subdevices: 1/1
Notice this section of the ffmpeg command:
-i hw:1,0
That means card 1: H340 [Logitech USB Headset H340], device 0:
Use this guide to detect your microphone or headset mic.
In [3]:
%%writefile CAPhere
#!/bin/bash
#  Bash Prompt Menu
PS3='Choose screen capture size: '
# PS3 means (Prompt String 3) a Shell prompts available for Linux. 
# The PS3 prompt is useful in scripts that use the select command in order to select a value.
options=("FullScreen" "1280x720" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "1280x720")
            sleep 8
            espeak "beep"
            ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 \
            -video_size 1280x720 -i :0.0+0,36 \
            -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast $(date +%s)_1280x720.mkv
            break
            ;;
        "FullScreen")
            sleep 8
            espeak "beep"
            ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 \
            -video_size 1360x768 -i :0.0 \
            -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast $(date +%s)_Fullscreen.mkv
            break
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done
 
ls -rant 
echo "The last video created is listed on the bottom. "
Writing CAPhere
In [3]:
!chmod +x CAPhere
In [4]:
The command ./CAPhere
run in the terminal results in this output:
    
1) FullScreen
2) 1280x720
3) Quit
Choose screen capture size: 
    
You simpily enter a:  1  2 or 3    
1) FullScreen
2) 1280x720
3) Quit
Choose screen capture size: ^C

This command requires an input so it may not be run in the Notebook:

You Must Use A Terminal in this Same directory

In [6]:
# This script run gives you the current directory
import os
os.getcwd()
Out[6]:
'/home/jack/Desktop/Images'
In [ ]: