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

feat(video/encode_games.fish): add zones with special encoding params from...

feat(video/encode_games.fish): add zones with special encoding params from chapters; easily set chapters with mpv script
parent 2d5a7a86
Branches
No related tags found
No related merge requests found
......@@ -2,6 +2,11 @@
set helpers (status dirname)/../helpers
. $helpers/_error.function.fish
. $helpers/_defer.function.fish
set RULES encode_rules.conf
......@@ -55,6 +60,59 @@ function game_config -a filename
string join -- \n $result
end
# --- Zone stuff ---
function get_frame_rate -a file
ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate $file
end
function get_frame_count -a file
set -f output (mediainfo --Output="Video;%FrameCount%" $file)
string match -rq '^\\d+$' $output || begin; echo frame count of $file invalid: $output; return 1; end
echo $output
end
function hhmmss_to_secs -a timestamp
set time (string match -rg '(\d+):(\d{2}):(\d{2}).(\d{3})' $timestamp)
[ (count $time) -eq 4 ] || begin; echo $timestamp '->' $time: len != 4; return 1; end
math $time[1] \* 3600 + $time[2] \* 60 + $time[3] + $time[4] / 1000
end
function extract_zones_from_chapters -a file
#set fish_trace on
[ -e "$file" ] || begin; echo extract_zones_from_chapters(): $file: doesn\'t exist; return 1; end
set chapters (mkvextract $file chapters --simple)
set -q _DEBUG && echo --- Chapter OGM \($file\) ---\n $chapters\n --- END --- >&2
[ "$chapters" = "" ] && return 2
set frame_rate (get_frame_rate $file)
set frame_count (get_frame_count $file)
set chapters (string join \n $chapters | while read -L timestamp name
set timestamp (string match -rg 'CHAPTER\d{2}=(.*)' $timestamp)
set name (string match -rg 'CHAPTER\d{2}NAME=(.*)' $name)
echo (math floor\((hhmmss_to_secs $timestamp) \* $frame_rate\))\|$name
end)
set -a chapters (math $frame_count - 1)\| # \| dummy separator for splitting below
for i in (seq 1 (count $chapters[2..]))
set input (string split --max 1 \| $chapters[$i])
set start_frame $input[1]
set end_frame (string split --max 1 --fields 1 \| $chapters[(math $i +1)])
set zone_marker $input[2]
set encoder svt-av1
[ $zone_marker = "_pause_" ] || continue
# TODO make encoder not hard-coded
# start_frame end_frame encoder reset(opt) video_params
set params
echo $start_frame $end_frame $encoder reset --extra-split (math $frame_rate \* 60) --keyint 0 --crf 70 --preset 10
end
#set -e fish_trace
end
detect_svt_av1_psy && set psy_params 'tune=0:variance-boost-strength=2:sharpness=4:frame-luma-bias=15:tf-strength=0'
......@@ -84,20 +142,39 @@ while [ (count $filelist) -gt 0 ]
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
extract_zones_from_chapters $f
if set -q AV1AN
set N_THREADS 7
set WORKERS 3
set G 600
set P 5
set CRF 58
set cmdline (string escape -- schedtool -B -e nice -n 19 \
av1an -n -i $f -o $output \
--log-file $output''.log --log-level debug --resume --workers $WORKERS (: --set-thread-affinity $N_THREADS "not effective _ set to same as --lp on svt") \
--extra-split (math '60*60+1' (: "60 sec chunks, should be 6 keyframes with `-g 600`")) --split-method none (: "no scenechange as we follow SVT instructions to split at defined intervals") \
--encoder svt-av1 --passes 1 (: "two-pass doesn't seem to work on SvtAv1Psy, maybe because av1an passes in --pass 3, or simply wrong documentation") \
--video-params "--lp "(math "$N_THREADS")" --keyint $G --crf $CRF --tune 0 --preset $P --sharpness 2 --film-grain 20 --film-grain-denoise 0 --enable-variance-boost 1 --variance-octile 5 --frame-luma-bias 27" \
--concat mkvmerge (: "appearently the best") \
--vmaf --vmaf-threads 2 (: "just guessing, we don't want to steal too much CPU from encoding and vmaf scales logarithmically or so"))
set fish_trace on
else
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)
end
set -q DRY_RUN \
&& echo $cmdline \
|| eval $cmdline &| tr \n \r
|| eval $cmdline #&| tr \n \r
if [ "$pipestatus[1]" != 0 ]
cleanup $output
break
end >&2
set -e fish_trace
# after successful encode, we update the filelist and clear the screen
# that way, new files recorded inbetween will be added for processing, but
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment