blob: 5a0128b5a98878c03da412e77fd6c7a37797eda7 (
plain) (
tree)
|
|
#!/usr/bin/env bash
set -euo pipefail
# Defaults
q=32
cpu=4
time_limit=""
print_only=false
limit_resolution=1080
limit_fps=30.01
while getopts :q:c:t:s OPT; do
case $OPT in
q|+q)
q="$OPTARG"
;;
c|+c)
cpu="$OPTARG"
;;
t|+t)
time_limit="-to $OPTARG"
;;
s)
print_only=true
;;
*)
echo "usage: `basename $0` [+-q ARG] [+-c ARG} [--] ARGS..."
exit 2
esac
done
shift `expr $OPTIND - 1`
OPTIND=1
input="$1"
output="$2"
command="$(cat<<EOF
ffmpeg -y -i "$input" $time_limit \
-vf "scale='-1':'min($limit_resolution,ih)',
select='eq(n,0)+if(gt(t-prev_selected_t,1/$limit_fps),1,0)'" \
-c:v libvpx-vp9 -b:v 0 -crf $q -an \
-row-mt 1 -tile-columns 2 -tile-rows 2 -cpu-used $cpu -g 240 \
-pass 1 -f webm -threads $cpu /dev/null &&
ffmpeg -y -i "$input" $time_limit \
-vf "scale='-1':'min($limit_resolution,ih)',
select='eq(n,0)+if(gt(t-prev_selected_t,1/$limit_fps),1,0)'" \
-c:v libvpx-vp9 -b:v 0 -crf $q -c:a libopus \
-row-mt 1 -tile-columns 2 -tile-rows 2 -cpu-used $cpu \
-pass 2 -threads $cpu -- "$output"
EOF
)"
if [ $print_only == true ]; then
echo "$command"
else
eval "$command"
fi
|