#!/bin/sh ## Config output_dir=~/videos/screencasts sound_device=/dev/dsp5 ## Start recording start_recording() { touch /tmp/cast.mkv notify-send -t 3000 "Starting screencast." "3...2...1..." sleep 4 pkill -76 i3blocks ffmpeg -video_size 1920x1080 \ -framerate 50 \ -thread_queue_size 512 -f x11grab -i :0.0+0,0 \ -thread_queue_size 512 -f oss -i "$sound_device" \ -vcodec libx264rgb -crf 0 -preset:v ultrafast \ -acodec pcm_s16le \ -af aresample=async=1:first_pts=0 \ -y \ /tmp/cast.mkv } ## Stop recording stop_recording() { pkill -2 ffmpeg output_file="$output_dir"/cast_"$(date '+%F-%H-%M-%S')".mkv mv /tmp/cast.mkv "$output_file" notify-send "Screencast saved" "$output_file" pkill -76 i3blocks exit } ## Main mkdir -p "$output_dir" [ -f /tmp/cast.mkv ] && stop_recording || start_recording