triav1lity/src/static/triav1c.sh

82 lines
2.9 KiB
Bash
Raw Normal View History

2020-07-15 04:19:34 +02:00
#! /usr/bin/env bash
############################################################
# A simpler rewrite of av1master client.sh for prototyping #
############################################################
set -euo pipefail
IFS=$'\n\t'
#######################
# $1 - file #
# $2 - AOM Options #
# $3 - FFMPEG Options #
# $4 - do VMAF? #
#######################
encode_aomenc_two_pass() {
file="$1"
aom_options="$2"
# Remove any character that isn't a letter, an underscore, a dash, or =
# Hopefully "cleans" the commandline
# so that you can't just take over a system
# Still possible to misuse ffmpeg and aomenc to overwrite any file
# the user running the program has access to.
# THIS IS NOT SAFE
# But it's something
aom_options=${aom_options//[^a-zA-Z0-9_\- =]/}
# Same story as above but also
ffmpeg_options="$3"
2020-07-15 05:14:52 +02:00
ffmpeg_options=${ffmpeg_options//[^a-zA-Z0-9_\- =:]/}
2020-07-15 04:19:34 +02:00
# set to boolean
2020-07-15 05:14:52 +02:00
doVMAF="$4"
2020-07-15 04:19:34 +02:00
set +e
2020-07-15 05:14:52 +02:00
eval '#ffmpeg -nostats -hide_banner -loglevel warning \
-i '$file' $ffmpeg_options -f yuv4mpegpipe - | aomenc - '$aom_options' \
--pass=1 --passes=2 --fpf='$file'.fpf --ivf -o '$file'.out.ivf'
2020-07-15 04:19:34 +02:00
retval=$?
if [[ $retval -ne 0 ]]; then
echo "Error running aomenc pass 1 of 2" >&2
curl -s -L "$base_url"/edit_status/"$job_id"/error || true
echo "" >&2
return 1
fi
2020-07-15 05:14:52 +02:00
eval '#ffmpeg -nostats -hide_banner -loglevel warning \
-i '$file' $ffmpeg_options -f yuv4mpegpipe - | aomenc - '$aom_options' \
--pass=2 --passes=2 --fpf='$file'.fpf --ivf -o '$file'.out.ivf'
2020-07-15 04:19:34 +02:00
retval=$?
if [ $retval -ne 0 ]; then
echo "Error running aomenc pass 2 of 2" >&2
curl -s -L "$base_url"/edit_status/"$job_id"/error || true
echo "" >&2
return 2
fi
# This probably needs to be improved as well, so that it scales
# and sets the framerate automatically. This will likely never
# Actually get used though, so it's fine.
2020-07-15 05:14:52 +02:00
if [[ $doVMAF == "true" ]]; then
ffmpeg -nostats -hide_banner \
-r 24 -i $file.out.ivf -r 24 -i $file -filter_complex \
"[0:v][1:v]libvmaf=model_path=$MODEL_PATH/share/model/vmaf_v0.6.1.pkl:log_fmt=json:log_path=$file.vmaf.json" -f null - >/dev/null
2020-07-15 04:19:34 +02:00
retval=$?
if [ $retval -ne 0 ]; then
echo "Error running VMAF scan" >&2
curl -s -L "$base_url"/edit_status/"$job_id"/error || true
echo "" >&2
return 3
fi
cat "$file".vmaf.json
fi
set -e
rm -f \
2020-07-15 05:14:52 +02:00
# "$file" \
2020-07-15 04:19:34 +02:00
"$file".fpf \
"$file".vmaf.json
return 0
}
2020-07-15 05:14:52 +02:00
encode_aomenc_two_pass "$1" "-b 10 --cpu-used=5 --end-usage=q --cq-level=50 --tile-columns=0 --tile-rows=0 --lag-in-frames=35 --auto-alt-ref=1" "" true