Scripts I wrote for screen recording.
setup-record.sh
: st, x11fsmerge.sh
,re-encode.sh
, andrecord.sh
: FFmpegwin-resize.sh
: wmctrl
The contents in this repository have been placed in public domain, or via UNLICENSE, if not applicable.
Scripts I wrote for screen recording.
setup-record.sh
: st, x11fsmerge.sh
, re-encode.sh
, and record.sh
: FFmpegwin-resize.sh
: wmctrlThe contents in this repository have been placed in public domain, or via UNLICENSE, if not applicable.
#!/bin/bash | |
source $HOME/.bashrc | |
PS1="\[\e[1;32m\]$(basename -- "$PWD")\[\e[0m\] \[\e[1;34m\]$\[\e[0m\] " |
#!/bin/bash | |
# Simple clips merger, only support video streams | |
# Written by Yu-Jie Lin in 2013, 2015-2016 | |
# Public domain, or via UNLICENSE, if not applicable | |
OUTFILE="output.re-encoded.mkv" | |
while getopts 'f:o:n' opt; do | |
case "$opt" in | |
f) | |
FPS="-r $OPTARG" | |
;; | |
o) | |
OUTFILE="$OPTARG" | |
;; | |
n) | |
ECHO=echo | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
INPUTS=("$@") | |
I=() | |
F_C=() | |
# generating | |
# -i file1 -i file2 ... | |
# | | | |
# +---+ +------+ | |
# | | | |
# v v | |
# [0:0] [1:0] [...] concat=n=#:v=1:a=0 [v] | |
for ((i=0; i<${#INPUTS[@]}; i++)); do | |
I+=('-i' "${INPUTS[i]}") | |
F_C+=("[$i:0]") | |
done | |
$ECHO \ | |
ffmpeg \ | |
"${I[@]}" \ | |
-filter_complex "${F_C[*]} concat=n=${#INPUTS[@]}:v=1:a=0 [v]" \ | |
-map '[v]' \ | |
-c:v libx264 \ | |
-preset veryfast \ | |
-crf 18 \ | |
-pix_fmt yuv420p \ | |
$FPS \ | |
"$OUTFILE" |
#!/bin/bash | |
# Written by Yu-Jie Lin in 2015 | |
# Public domain, or via UNLICENSE, if not applicable | |
# command display delay | |
delay=1 | |
# command execution delay | |
DELAY=1 | |
while getopts 'd:D:' opt; do | |
case "$opt" in | |
d) | |
delay=$OPTARG | |
;; | |
D) | |
DELAY=$OPTARG | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
exec 3<&0 | |
grep -v '^#' <"$1" | | |
while read cmd; do | |
clear | |
echo "***** NEXT UP *****" | |
echo "$cmd" | pygmentize -l bash | |
until read desc; [[ -z "$desc" ]]; do | |
echo "$desc" | |
done | |
read -u 3 -t $delay | |
sh -c "$cmd" 0<&3 | |
read -u 3 -t $DELAY | |
done | |
exec 3<&- |
#!/bin/bash | |
# Written by Yu-Jie Lin in 2013, 2015-2016 | |
# Public domain, or via UNLICENSE, if not applicable | |
while getopts 'n' opt; do | |
case "$opt" in | |
n) | |
ECHO=echo | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# https://trac.ffmpeg.org/wiki/EncodeforYouTube | |
INFILE="$1" | |
OUTFILE="${INFILE%.*}.re-encoded.mkv" | |
$ECHO \ | |
ffmpeg \ | |
-i "$INFILE" \ | |
-c:v libx264 \ | |
-preset veryfast \ | |
-crf 18 \ | |
-pix_fmt yuv420p \ | |
"$OUTFILE" |
#!/bin/bash | |
# Written by Yu-Jie Lin in 2013-2016 | |
# Public domain, or via UNLICENSE, if not applicable | |
OUTFILE=out.mkv | |
LOPTS="-loglevel warning -stats" | |
IOPTS="-show_region 1" | |
DEF_COPTS='-vcodec ffvhuff -threads 0' | |
COPTS="$DEF_COPTS" | |
OOPTS="" | |
POS=2,20 | |
FPS=5 | |
SIZE=1280x720 | |
THREAD_SIZE='-thread_queue_size 16384' | |
while getopts 'f:s:p:y:t:o:L:I:C:O:an' opt; do | |
case "$opt" in | |
f) | |
FPS=$OPTARG | |
;; | |
s) | |
SIZE=$OPTARG | |
;; | |
p) | |
POS=$OPTARG | |
;; | |
t) | |
T="-t $OPTARG" | |
;; | |
o) | |
OUTFILE="$OPTARG" | |
;; | |
L) | |
LOPTS="$OPTARG" | |
;; | |
I) | |
IOPTS="$IOPTS $OPTARG" | |
;; | |
C) | |
COPTS="$OPTARG" | |
;; | |
O) | |
OOPTS="$OOPTS $OPTARG" | |
;; | |
a) | |
COPTS= | |
AOPTS="-f alsa $THREAD_SIZE -i pulse" | |
;; | |
n) | |
ECHO=echo | |
;; | |
esac | |
done | |
REGION=":0.0+$POS" | |
if [[ $OUTFILE = *.gif ]]; then | |
OUTFILE_GIF="$OUTFILE" | |
OUTFILE="$OUTFILE.mkv" | |
AOPTS= | |
elif [[ $OUTFILE = *.mp4 ]]; then | |
# if recording as .mp4, just record x264 | |
COPTS="-c:v libx264 -preset ultrafast -g $((FPS * 2)) -keyint_min $FPS -pix_fmt yuv420p ${COPTS/$DEF_COPTS/}" | |
fi | |
if [[ $AOPTS ]]; then | |
if [[ -z "$T" ]]; then | |
echo -e "Recommend setting: \e[1;32m-t ##\e[0m. Or FFmpeg may produce a flawed audio." >&2 | |
fi | |
# play a 1000 second 1Hz sine wave in the background for helping FFmpeg A/V | |
# out-of-sync issue | |
echo 48000000 0 1 | wave | aplay -f FLOAT_LE -r 48000 -c 1 -q & | |
APID=$! | |
fi | |
# http://stackoverflow.com/questions/10166204/ffmpeg-screencast-recording-which-codecs-to-use | |
$ECHO \ | |
ffmpeg \ | |
$LOPTS \ | |
-f x11grab \ | |
$IOPTS \ | |
-r "$FPS" -s "$SIZE" $THREAD_SIZE -i "$REGION" \ | |
$AOPTS \ | |
$COPTS \ | |
$T \ | |
$OOPTS \ | |
"$OUTFILE" | |
if [[ $APID ]]; then | |
kill $APID | |
fi | |
if [[ $OUTFILE_GIF ]]; then | |
PALETTE="$OUTFILE.palette.png" | |
ffmpeg $LOPTS -i "$OUTFILE" -vf "palettegen" -y "$PALETTE" | |
ffmpeg $LOPTS -i "$OUTFILE" -i "$PALETTE" -lavfi 'copy [x]; [x][1:v] paletteuse' "$OUTFILE_GIF" | |
rm -i "$OUTFILE" | |
rm -i "$PALETTE" | |
fi |
#!/bin/bash | |
# Set up a st window to get started with recording | |
# | |
# Required switching to floating layout in DWM. | |
# | |
# Written by Yu-Jie Lin in 2014-2016 | |
# Public domain, or via UNLICENSE, if not applicable | |
############ | |
# Settings # | |
############ | |
# Screeen size and border width | |
SW=1680 | |
SH=1050 | |
B=2 | |
# Geometry for new terminal window | |
W=1280 | |
H=720 | |
X=0 | |
Y=18 | |
# Path for Akemi | |
X11FS=/tmp/.x11fs | |
# Font setting | |
###################### | |
# Initializing Akemi # | |
###################### | |
mkdir -p "$X11FS" | |
x11fs "$X11FS" -o auto_unmount | |
########################### | |
# Move the current window # | |
########################### | |
cd "$X11FS"/$(<$X11FS/focused)/geometry | |
echo "$((SW - 2 * B))" > width | |
echo "$((SH - Y - (H + 2 * B) - 2 * B))" > height | |
echo "0" > x | |
echo "$((Y + H + 2 * B))" > y | |
cd "$OLDPWD" | |
#################################### | |
# Creating the new terminal window # | |
#################################### | |
FONT="Envy Code R:size=26:antialias=false:autohint=false" | |
BSRC="$HOME/p/gist/record-scripts/bashrc" | |
TMUX= nohup st -f "$FONT" bash --rcfile "$BSRC" &>/dev/null & | |
sleep 1 | |
############################################## | |
# Resizing and re-positioning the new window # | |
############################################## | |
cd "$X11FS"/$(<$X11FS/focused)/geometry | |
echo "$W" > width | |
echo "$H" > height | |
echo "$X" > x | |
echo "$Y" > y | |
cd "$OLDPWD" | |
############# | |
# Finishing # | |
############# | |
pkill x11fs | |
sleep 1 | |
rmdir "$X11FS" |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> |
#!/bin/bash | |
# Using xwininfo and wmctrl to resize a window | |
# Written by Yu-Jie Lin in 2012, 2013, 2015 | |
# Public domain, or via UNLICENSE, if not applicable | |
W=$1 | |
H=$2 | |
X=${3:--1} | |
Y=${4:--1} | |
wmctrl -r :SELECT: -e 0,$X,$Y,$W,$H |