Write flexible programs that work together!
James
dbar, ffmpeg and mpv sitting in a tree, F.O.S.S.I.N.G.
Here's the crop-df script I showcased in the video. Keep in mind this code is much better suited to a "proper" programming language. If you are so inclined, extract the code into a better language, tweak the ffmpeg settings, use json
to communicate with mpv, and figure out how to play a sample length's worth of video without calling sleep
😬.
#! /usr/bin/bash
if [ $# -ne 2 ]; then
echo "Error: must provide 2 parameters (INPUT OUTPUT)"
exit 1
fi
get_time() {
length=2
if [ "$1" == "start" ]; then
i=0.0
v="%v"
else
i=1.0
v="%(v-$length)"
fi
seconds=$(dbar -f -v -i $i -C "echo \"seek $v absolute\" | socat - /tmp/mpvsocket && echo 'set pause no' | socat - /tmp/mpvsocket; sleep $length; echo 'set pause yes' | socat - /tmp/mpvsocket" -t "RET to confirm $1 time (seconds)" $2 $duration)
[ -z $seconds ] && echo 'quit' | socat - /tmp/mpvsocket && exit 0
time=$(echo $seconds | awk '{printf("%02d:%02d:%g",($1/60/60),($1/60%60),($1%60))}')
}
infile=$1
outfile=$2
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $infile)
# attach mpv instance to socket
mpv $infile --input-ipc-server=/tmp/mpvsocket --pause --keep-open --keep-open-pause=no --really-quiet &
get_time start 0
start=$time
get_time end $seconds
end=$time
# close mpv
echo 'quit' | socat - /tmp/mpvsocket
ffmpeg -y -i $infile -ss $start -to $end $outfile
2021-04-12
2.0 LBC
None
108770531 Bytes