Skip to content
Snippets Groups Projects
Commit 2d5a7a86 authored by Florian Meißner's avatar Florian Meißner
Browse files

add encode_games.fish

parent 4a4e7477
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env fish
set RULES encode_rules.conf
cd /run/media/ra1n/8tb_backup/Videos/Games
function handle_interrupt --on-signal SIGTERM --on-signal SIGINT
echo SIGTERM caught…
return
end
function get_length -a file
set -- FFPROBE_PARAMS -v error -select_streams v -show_entries stream_tags=DURATION -of default=noprint_wrappers=1
set FFPROBE_KEYS 'TAG:DURATION'
set ffprobe_out (ffprobe $FFPROBE_PARAMS $file)
for k in $FFPROBE_KEYS
set --local output (string match -rg '^'$k'=(.*)$' $ffprobe_out | string trim --right --chars '0' | string trim --right --chars '.')
[ "$pipestatus[1]" -eq 0 ] && set -a --function result $output
end
printf '%s\n' $result
end
function cleanup -a tmpfile
echo
echo -n "Removing temp… "
if rm $output
echo "DONE"
else
set_color brred
echo "ERROR"
set_color normal
end
notify-send "My name is fish and I rock da house"
# Optionally exit the script or do additional handling
end
function detect_svt_av1_psy
SvtAv1EncApp --version | grep -qF 'SVT-AV1-PSY'
end
function update_filelist --no-scope-shadowing
set filelist !raw/*.{mkv,mp4}
end
function game_config -a filename
while read config
set config (string split --max 1 -- = $config | string trim)
string match -qe -- $config[1] $filename && echo -- $config[2] | read --tokenize --list result
end <$RULES
string join -- \n $result
end
detect_svt_av1_psy && set psy_params 'tune=0:variance-boost-strength=2:sharpness=4:frame-luma-bias=15:tf-strength=0'
update_filelist
set longest (math max\( (string length $filelist | string join ,) \))
set to_pad (math $longest + 2)
set -q _DEBUG && echo longest=$longest
clear
while [ (count $filelist) -gt 0 ]
set -l f $filelist[1] && set -f filelist $filelist[2..]
printf '%s\r' (string repeat ' ' --max (tput cols))
set output (basename $f)
set_color -di
echo -n (string pad $output --right --width $to_pad)
string match --entire '[*]' $output >/dev/null || begin; set_color brblack; echo SKIPPING, not tagged; set_color normal; continue; end # file names without atleast one pair of [] brackets are not tagged and will be skipped
get_length $f
[ -e "$output" ] && continue
set_color normal
set P 5
set CRF 52
set GRAIN 35
set -- params -crf $CRF -preset $P -svtav1-params (string join : tune=0:film-grain=$GRAIN:film-grain-denoise=0 $psy_params)
set -- override_params (game_config $f)
[ -n "$override_params" ] && set -- params $override_params
# string match --entire '[System Shock]' $output && set CRF 39 # disabled as the effects are barely noticable but get really clear when I'm in cyberspace
set cmdline (string escape -- schedtool -D -e nice -n 19 ffmpeg -n -hide_banner -i $f -map 0 -c copy -c:v libsvtav1 -pix_fmt yuv420p10le -g 600 $params -f matroska)
set -a cmdline -metadata (string escape -- comment=(string join ' ' -- $cmdline $output))
set -a cmdline (string escape -- $output)
set -q DRY_RUN \
&& echo $cmdline \
|| eval $cmdline &| tr \n \r
if [ "$pipestatus[1]" != 0 ]
cleanup $output
break
end >&2
# after successful encode, we update the filelist and clear the screen
# that way, new files recorded inbetween will be added for processing, but
# if we encounter a file we don't encode, we `continue` earlier, so this
# doesn't get executed. otherwise the loop would always process (only) the
# first file.
set -q DRY_RUN || begin; update_filelist; clear; end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment