Skip to content

Instantly share code, notes, and snippets.

@gpoulter
Last active May 2, 2023 10:45
Show Gist options
  • Save gpoulter/3698b01a7e70ad3805fea0fbcdeb89d9 to your computer and use it in GitHub Desktop.
Save gpoulter/3698b01a7e70ad3805fea0fbcdeb89d9 to your computer and use it in GitHub Desktop.
Debian Screen Recording
#!/usr/bin/fish
# Uses ffmpeg to record a timelapse video of the X11 screen.
#
# Global Flags:
# -loglevel: Verbosity
#
# Input Flags:
# -framerate: screenshots to capture per second
# -f: input format
# -video_size: screen capture size
# -i: screen capture offset
#
# Output Flags:
# -vf: video codec filtesr
# screen_size: video output size
# format: color space
# settb: set timebase for output frame timestamp
# setpts: set presentation timestamp (expr for output frame timestamp)
# -r: output framerate (frames drawn per second)
# -vcodec: video codec
# -crf: quality (constant rate factor), typically 18 (high) to 28 (low)
# -preset: encoding speed preset (faster -> larger file)
# -tune: tuning for image types
# -threads: number of threads to use for encoding (cores)
# Name of project to include in file name.
set project "none"
# Number of screen frames to capture per second.
set framerate 0.5
# Frames per second to write to output video file.
set fps 60
# The speedup factor is $fps/$framerate.
# X11 display to capture.
set display ":1"
# Screen resolution of X11 display.
set screen_size "3840x2160"
# Output directory for videos.
set outdir "$HOME/Videos/Timelapse"
# Date and time to put in the file name.
set datetime (date +'%Y%m%d-%H%M%S')
# Parse command-line arguments
argparse -n timelapse 'p/project=' 'f/fps=' 'r/framerate=' 'd/dir=' -- $argv or exit 1
set -q _flag_project; and set project $_flag_project
set -q _flag_fps; and set fps $_flag_fps
set -q _flag_framerate; and set framerate $_flag_framerate
set -q _flag_dir; and set outdir $_flag_dir
# Video output file
set outfile "$outdir/$datetime $project.mkv"
echo (printf "Recording to \"%s\" at %sx" $outfile (math $fps / $framerate))
# Options are applied to the next specified file.
/usr/bin/ffmpeg \
-loglevel error \
-framerate $framerate \
-f x11grab \
-video_size $screen_size \
-probesize 10M \
-i $display \
-vf scale=$screen_size,format=yuv420p,settb=(math 1 / $fps),setpts=N/TB/$fps \
-r $fps \
-vcodec libx264 \
-crf 16 \
-preset ultrafast \
-tune stillimage \
-threads 0 \
$outfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment