[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


I have refined my SSIM/AV1 windows batch script.

@echo off & setlocal enabledelayedexpansion & set "crf=60" & set "mincrf=20"

set "base_av1=-c:v libsvtav1 -preset 10 -pix_fmt yuv420p10le -svtav1-params"
set "psy_av1=keyint=2s:lookahead=120:tune=0:enable-variance-boost=1:variance-boost-strength=3:variance-octile=4"
set "opus=-c:a libopus -b:a 128k" & set "ffquiet=-hide_banner -loglevel quiet"

echo Weclome to my auto-SSIM AV1 encoder, only input.mp4 accepted, choose desired SSIM:
echo 1= 0.995 (autism quality) & echo 2= 0.990 (very high quality) & echo 3= 0.980 (high quality)
choice /c 123 /m "Enter number option on keyboard: "
if errorlevel 3 set ssim_target=980
if errorlevel 2 set ssim_target=990
if errorlevel 1 set ssim_target=995

:loop
ffmpeg !ffquiet! -i input.mp4 -crf !crf! !base_av1! !psy_av1! !opus! -y AV1_CRF-!crf!.webm 2>nul

for /f "delims=" %%A in ('ffmpeg -nostdin -r 30 -i AV1_CRF-!crf!.webm -nostdin -r 30 -i input.mp4 ^
-lavfi "[0:v]settb=AVTB,setpts=PTS-STARTPTS,format=yuv420p10le[main];[1:v]settb=AVTB,setpts=PTS-STARTPTS,format=yuv420p10le[ref];[main][ref]ssim=eof_action=endall:stats_file=-" ^
-f null - 2^>^&1 ^| findstr "All:"') do set "a=%%A"

set "a=!a:*All:0.=!" & set "ssim=!a:~0,3!" & echo SSIM: 0.!ssim! @ CRF !crf! & echo:

if !ssim! lss !ssim_target! (if !crf! gtr !mincrf! (del /s /q AV1_CRF-!crf!.webm >nul 2>&1 & set /a crf-=2 & goto loop) )
:end

for %%Y in ("input.mp4") do set /a kb_mp4=(%%~zY+1023)/1024 & for %%Y in ("AV1_CRF-!crf!.webm") do set /a kb_webm=(%%~zY+1023)/1024
set /a saved_pct=(kb_mp4-kb_webm)*100/kb_mp4 & echo MP4= !kb_mp4! KB & echo AV1= !kb_webm! KB
echo **** !saved_pct!%% filesize reduction achieved with AV1 **** & echo:

pause
>>
tl;dr
>auto adjusts CRF until SSIM is reached
>no temp files
>more resistent to damaged MP4s (ie wrong frame timing)
>failed encodes get auto deleted
>input/output filesize reported
>percent filesize saved reported

Just like last thread, I have disabled SSIM cheating in AV1. I'll be posting AV1 webms on umigalaxy here:
https://umigalaxy.com/explore/general/595-ssimav1-script-v20

These parameters force AV1 to heavily optimize for perceptual quality and generate x264-like SSIM scores.
>>
Is av1 the best option nowadays? I thought hevc was the high end stuff
>>
File: download.png (117 KB, 1200x630)
117 KB PNG
>>108898405
It also takes forever to encode.
>>
>>108898424
I wanted to do av1 encoding with my GPU, heard it was crazy fast, but mine doesn't support it
>>
>>108898449
NVIDIA won't ever release a RTX 6000 series
>>
File: 1773978934107236.webm (728 KB, 640x480)
728 KB
728 KB WEBM
Dam I got something wrong.

SSIM: 0.999 @ CRF 60

MP4= 67478 KB
AV1= 2749 KB
**** 95% filesize reduction achieved with AV1 ****


If anyone could help me figure out why the SSIM is being parsed so completely wrong, I'd really appreciate it senpai.
>>
Sweet merciful Joseph, where is this 0.999 SSIM score coming from. There shouldn't be a 0.999 SSIM score on a preset 10 CRF 60 AV1 encode, like AT ALL.

Nothing in this script assigns SSIM as 0.999 as far as I can tell...
>>
File: 1779556659035948.png (90 KB, 1349x632)
90 KB PNG
>>108898449
>I wanted to do av1 encoding with my GPU
GPU AV1 video encoding is becoming obsolete.
>>
>>108898487
Part 1
@echo off & setlocal enabledelayedexpansion
set "crf=60" & set "mincrf=20"
set "base_av1=-c:v libsvtav1 -preset 10 -pix_fmt yuv420p10le -svtav1-params"
set "psy_av1=keyint=2s:lookahead=120:tune=0:enable-variance-boost=1:variance-boost-strength=3:variance-octile=4"
set "opus=-c:a libopus -b:a 128k" & set "ffquiet=-hide_banner -loglevel quiet"

:: Drag and drop a file onto this script, or pass it as an argument.
if "%~1"=="" (
echo Error: No input file specified.
echo Drag and drop a video file onto this script to encode it.
pause
exit /b
)
set "input_file=%~1"

:: Verify the file exists
if not exist "!input_file!" (
echo Error: File not found - !input_file!
pause
exit /b
)

:: Extract directory and name parts
for %%I in ("!input_file!") do (
set "input_dir=%%~dpI"
set "input_name=%%~nI"
)

:: Dynamically query the exact frame rate of the video using ffprobe
:: Falls back to 30 if ffprobe is not available or errors out
set "fps=30"
for /f "delims=" %%F in ('ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 "!input_file!" 2^>nul') do set "fps=%%F"

echo Welcome to my auto-SSIM AV1 encoder
echo Input file: !input_file!
echo Output folder: !input_dir!
echo Detected Frame Rate: !fps!
echo:
echo Choose desired SSIM target:
echo 1= 0.995 (extremely high quality)
echo 2= 0.990 (very high quality)
echo 3= 0.980 (high quality)
choice /c 123 /m "Enter option: "
if %errorlevel%==1 set ssim_target=995
if %errorlevel%==2 set ssim_target=990
if %errorlevel%==3 set ssim_target=980
>>
>>108898684
:loop
:: Temporary output named with the current CRF
set "temp_file=!input_dir!!input_name!_av1_crf-!crf!.webm"

echo Encoding test at CRF !crf! ...
(
echo $input_file = '!input_file!'
echo $temp_file = '!temp_file!'
echo $crf = !crf!
echo $base_av1 = '-c:v libsvtav1 -preset 10 -pix_fmt yuv420p10le -svtav1-params'
echo $psy_av1 = 'keyint=2s:lookahead=120:tune=0:enable-variance-boost=1:variance-boost-strength=3:variance-octile=4'
echo $has_audio = ^(ffprobe -v error -select_streams a -show_entries stream=codec_type -of default=noprint_wrappers=1:nokey=1 "$input_file" 2^>$null^)
echo $audio_opts = if ^($has_audio^) { "-c:a libopus -b:a 128k" } else { "-an" }
echo $duration = [double]^(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input_file"^)
echo if ^($duration -le 0^) { $duration = 1 }
echo $total_us = $duration * 1000000
echo $pinfo = New-Object System.Diagnostics.ProcessStartInfo
echo $pinfo.FileName = "ffmpeg"
echo $pinfo.Arguments = "-hide_banner -y -i `"$input_file`" -crf $crf $base_av1 $psy_av1 $audio_opts `"$temp_file`" -progress pipe:1 -nostats -loglevel quiet"
echo $pinfo.UseShellExecute = $false
echo $pinfo.RedirectStandardOutput = $true
echo $pinfo.CreateNoWindow = $true
echo $process = New-Object System.Diagnostics.Process
echo $process.StartInfo = $pinfo
echo $process.Start^(^) ^| Out-Null
echo $reader = $process.StandardOutput
echo while ^(-not $reader.EndOfStream^) {
echo $line = $reader.ReadLine^(^)
echo if ^($line -match "out_time_us=(\d+)"^) {
echo $us = [double]$Matches[1]
echo $pct = [math]::Round^(^($us / $total_us^) * 100, 1^)
echo if ^($pct -gt 100^) { $pct = 100 }
echo $filled = [int][math]::Floor^($pct / 5^)
echo $empty = 20 - $filled
echo $bar = ^([string][char]0x2588 * $filled^) + ^([string][char]0x2591 * $empty^)
echo Write-Host -NoNewline "`rEncoding: [$bar] $pct%% "
echo }
echo }
>>
>>108898698
echo $process.WaitForExit^(^)
echo Write-Host ""
) > "%temp%\encode_progress.ps1"

powershell -NoProfile -ExecutionPolicy Bypass -File "%temp%\encode_progress.ps1"
del "%temp%\encode_progress.ps1" >nul 2>&1

:: Calculate SSIM (synchronized at the exact frame rate of the video)
for /f "delims=" %%A in ('ffmpeg -nostdin -i "!temp_file!" -i "!input_file!" -lavfi "[0:v]fps=fps=!fps!,settb=AVTB,setpts=PTS-STARTPTS,format=yuv420p10le[main];[1:v]fps=fps=!fps!,settb=AVTB,setpts=PTS-STARTPTS,format=yuv420p10le[ref];[main][ref]ssim=eof_action=endall" -f null - 2^>^&1 ^| findstr "All:"') do set "a=%%A"

:: Parse the SSIM values cleanly
set "a=!a:*All:=!"
set "integer_part=!a:~0,1!"
set "decimal_part=!a:~2,3!"
set "ssim=!integer_part!!decimal_part!"

:: Strip leading zeros to avoid Windows octal arithmetic errors
for /f "tokens=* delims=0" %%# in ("!ssim!") do set "ssim_num=%%#"
if not defined ssim_num set "ssim_num=0"

echo SSIM: !integer_part!.!decimal_part! @ CRF !crf!
echo:

:: If SSIM is less than target, delete temporary file, lower CRF by 2, and try again
if !ssim_num! lss !ssim_target! (
if !crf! gtr !mincrf! (
del /q "!temp_file!" >nul 2>&1
set /a crf-=2
goto loop
)
)

:: Optimal file found! Rename it to the final version
set "final_output=!input_dir!!input_name!_av1.webm"
move /y "!temp_file!" "!final_output!" >nul 2>&1

:end
for %%Y in ("!input_file!") do set /a kb_mp4=(%%~zY+1023)/1024
for %%Y in ("!final_output!") do set /a kb_webm=(%%~zY+1023)/1024
set /a saved_pct=(kb_mp4-kb_webm)*100/kb_mp4

echo:
echo =======================================================
echo DONE!
echo Original MP4 = !kb_mp4! KB
echo AV1 Compressed = !kb_webm! KB
echo **** !saved_pct!%% filesize reduction achieved with AV1 ****
echo =======================================================
echo:
pause
>>
>>108898405
HEVC is better. AV1 doesn't play on my iPhone
>>
>>108898638
Now you need to dance with me :)
https://www.youtube.com/watch?v=wf421JsG004
>>
File: 1766082755509358.webm (1.3 MB, 960x540)
1.3 MB
1.3 MB WEBM
>>108898684
>>108898698
>>108898704
OP here: is that from chatgpt? I appreciate you trying to help but it's mixing up windows batch scripting with powershell, I'm only using windows batch scripting (ie the .cmd extension thing).

I've handmade my script for days now. What's beyond confusing is some videos do seem to be reporting accurate SSIM scores most of the time. It's like there's a demon insertng 0.999 into my script randomly.

HOLY SHIT I THINK MY COMPUTER IS HAUNTED
>>
>>108898732
Sorry anon, I thought the latest models could help, but it's really hard to fix
>>
>>108898761
Yeah if a jeet hasn't figured it out yet, then AI is kind of worthless right now since jeet answers is what AI is trained on irl. Modern ones just seem to be getting better at realizing most of those jeet answers are wrong and trying to correct them. Don't trust it too much, at least for now man.

Anyway I'm gonna take a long walk and have a big dinner, I tend to panic and overcomplicate things to the point of never fixing them when I'm stressed. I know for a fact it has something to do with that SSIM parser, the demon is hidden in that thing somewhere...
>>
>>108898467
But they *will* release an RTX PRO 6000.

https://www.nvidia.com/en-us/products/workstations/professional-desktop-gpus/rtx-pro-6000/
>>
>>108898329
dear op,are you chasing for high ssim score or something else? I thought SVT-AV1-Essential does something similar?
>>
>>108900318
Not OP but Av1an seems to do what OP wants.

https://rust-av.github.io/Av1an/Cli/target_quality.html

However I can't get it working on windows, I get this error:

thread 'main' (2136) panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\vapoursynth-0.5.6\src\vsscript\environment.rs:70:38:
VSScript API not available
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It seems that the most exotic aspects of AV1 video encoding are currently only attainable for Linux users.
>>
>>108898706
>AV1 doesn't play on my iPhone
huh? my 3 year old iphone does av1 just fine
>>
>>108900378
No? AV1 encoding had been easy for windows but you do need to do some research
https://github.com/LastBreeze/Auto-Boost-Av1an-portable
Here a script that does av1an and autoboost if needed on windows,even option to pick which svt-av1 fork
>>
>>108898487
why are they kidnapping a penguin wtf
>>
>>108898704
nice ai slop faggot
>>
>>108898329
see
>>108900763
There are better metrics and better scripts for automating av1 encoding. CRF 60 will block nearly anything at 1080p and isn't even worth encoding/scoring. Likewise preset 10 disables many important parameters for miniscule speed gains.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.