Auto-boost algorithm 2.0 fixes

This commit is contained in:
trix
2024-07-03 11:58:44 +02:00
parent ed8ee42593
commit 9b4ffc9773
2 changed files with 12 additions and 10 deletions

View File

@@ -30,16 +30,16 @@ _Inspiration was drawn from the original Av1an (python) boosting code_
## Version 2.0: SSIMULACRA2-based ## Version 2.0: SSIMULACRA2-based
> Does a fast encode of the provided file, calculates SSIMULACRA2 scores of each chunks and adjusts CRF per-scene to be closer to the average total score, in a _zones.txt_ file to feed Av1an. > Does a fast encode of the provided file, calculates SSIMULACRA2 scores of each chunks and adjusts CRF per-scene to be closer to the average total score, in a _zones.txt_ file to feed Av1an.
The requirements are Vapoursynth, vstools, LSMASHSource, Av1an and vapoursynth-ssimulacra2. The requirements are Vapoursynth, vstools, LSMASHSource, fmtconv, Av1an and vapoursynth-ssimulacra2.
__Usage:__ __Usage:__
``` ```
python auto-boost_2.0.py "{animu.mkv}" "{scenes.json}" {base CQ/CRF/Q} python auto-boost_2.0.py "{animu.mkv}" {base CQ/CRF/Q}
``` ```
__Example:__ __Example:__
``` ```
python auto-boost_2.0.py "path/to/nice_boat.mkv" "path/to/scenes.json" 30 python auto-boost_2.0.py "path/to/nice_boat.mkv" 30
``` ```
__Advantages:__ __Advantages:__

View File

@@ -2,15 +2,17 @@ import statistics
from math import ceil from math import ceil
import json import json
import sys import sys
from vapoursynth import vs, core import subprocess
import vapoursynth as vs
core = vs.core
if "--help" in sys.argv[1:]: if "--help" in sys.argv[1:]:
print('Usage:\npython auto-boost_2.0.py "{animu.mkv}" "{scenes.json}" {base CQ/CRF/Q}"\n\nExample:\npython "auto-boost_2.0.py" "path/to/nice_boat.mkv" "path/to/scenes.json" 30') print('Usage:\npython auto-boost_2.0.py "{animu.mkv}" {base CQ/CRF/Q}"\n\nExample:\npython "auto-boost_2.0.py" "path/to/nice_boat.mkv" 30')
exit(0) exit(0)
else: else:
pass pass
og_cq = int(sys.argv[3]) # CQ to start from og_cq = int(sys.argv[2]) # CQ to start from
br = 10 # maximum CQ change from original br = 10 # maximum CQ change from original
def get_ranges(scenes): def get_ranges(scenes):
@@ -36,10 +38,7 @@ def calculate_standard_deviation(score_list: list[int]):
average = sum(filtered_score_list)/len(filtered_score_list) average = sum(filtered_score_list)/len(filtered_score_list)
return (average, sorted_score_list[len(filtered_score_list)//20]) return (average, sorted_score_list[len(filtered_score_list)//20])
scenes_loc = sys.argv[2] # scene file is expected to be named 'scenes.json' fast_av1an_command = f'av1an -i "{sys.argv[1]}" --temp "{sys.argv[1][:-4]}/temp/" -y \
ranges = get_ranges(scenes_loc)
fast_av1an_command = f'av1an -i "{sys.argv[1]}" --temp "{scenes_loc[:-11]}/temp/" -y \
--verbose --keep --split-method av-scenechange -m lsmash \ --verbose --keep --split-method av-scenechange -m lsmash \
--min-scene-len 12 -c mkvmerge --sc-downscale-height 480 \ --min-scene-len 12 -c mkvmerge --sc-downscale-height 480 \
--set-thread-affinity 2 -e svt-av1 --force -v \" \ --set-thread-affinity 2 -e svt-av1 --force -v \" \
@@ -56,6 +55,9 @@ if exit_code != 0:
print("Av1an encountered an error, exiting.") print("Av1an encountered an error, exiting.")
exit(-2) exit(-2)
scenes_loc = f"{sys.argv[1][:-4]}/temp/scenes.json"
ranges = get_ranges(scenes_loc)
src = core.lsmas.LWLibavSource(source=sys.argv[1], cache=0) src = core.lsmas.LWLibavSource(source=sys.argv[1], cache=0)
enc = core.lsmas.LWLibavSource(source=f"{sys.argv[1][:-4]}_fastpass.mkv", cache=0) enc = core.lsmas.LWLibavSource(source=f"{sys.argv[1][:-4]}_fastpass.mkv", cache=0)