Автоматична генерація скріншотів (+HDR). Скрипт для PowerShell

Нові коментарі

Нова тема   Відповісти
Автор Повідомлення
4br4h4m 
VIP


З нами з: 29.04.22
Востаннє: 29.04.24
Повідомлень: 346

2023-09-11 02:04  
Вітаю.
Ще раніше помічав, що у релізах з HDR люди часто роблять не зовсім коректні скріншоти через особливості "глибини кольору".

https://toloka.to/t672390
https://toloka.to/t670763
https://toloka.to/t670199

В мене були аналогічні проблеми з PotPlayer, тому шукав альтернативу, бажано взагалі напівавтоматизовану.

В результаті знайшовся такий скрипт:
https://gist.github.com/lambdan/70a36e53b90ebbff97bc9e73b2fa4414

Трішки його підправив і вирішив викласти.
Шляхи до Info.exe (CLI) і ffmpeg.exe вкажіть свої.
Скачати останні офіційні версії можна тут
зберегти як hdr.ps1 і запускати так:
powershell -ExecutionPolicy Bypass -File d:\hdr.ps1 "The.Hurt.Locker.2008..4K.2160p.x265.10bit.HDR10+.Ukr.Eng.Sub.Eng."

Можна задати параметр how_many фіксованим значенням.
PowerShell скрипт

# For batch:
# foreach($f in Get-ChildItem .) { .\hdr.ps1 $f }

$infile = $Args[0] # Input video

# Get some video length info using Info
$Info = "d:\Portable\FFMpeg\MediaInfo_CLI_23.07_Windows_x64\Info.exe"
$ffmpeg = "d:\Portable\FFMpeg\ffmpeg-2023-09-07-git-9c9f48e7f2-full_build\bin\ffmpeg.exe"
#$length_in_ms = $Info --Output='General;%Duration%' "$infile" | Out-String
$length_in_ms = & $Info --Language=raw --Full --Inform='Video;%Duration%' "$infile" | Out-String
#Info";%Duration/String4%"
$length_in_secs = $length_in_ms/1000

# Create output folder
$outfolder = "./screenshots/"
If(!(test-path $outfolder)) {
md $outfolder
}

# Create this many screenshots, or base it on video length
#$how_many = 20 # maybe make this the 2nd arg in the future?
$how_many = [math]::Round($length_in_secs/100)
Write-Host "Will create $how_many screenshots"

$used_seconds = @()
$i = 1
while($i -le $how_many) {
# Get a random second of the video that hasnt been already used
$random_sec = get-random -maximum $length_in_secs
$rounded = [math]::Round($random_sec)
if ($used_seconds.Contains($rounded) -eq $True) {
while ($used_seconds.Contains($rounded) -eq $True) {
#Write-Host $rounded "already used"
#Write-Host $used_seconds
$random_sec = get-random -maximum $length_in_secs
$rounded = [math]::Round($random_sec)
}
#Write-Host "Found unused" $rounded
}
$used_seconds += $rounded

# Outfile that screenshot will be saved as
$outfile = $outfolder + $infile + "_" + $rounded + ".png"

Write-Host $i/$how_many $outfile
#$result = & $ffmpeg -loglevel error -ss $rounded -i "$infile" -frames:v 1 $outfile | Out-String
& $ffmpeg -loglevel error -ss $rounded -i "$infile" -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -frames:v 1 $outfile

$i++
}
Результат використання скрипта можна побачити тут:
https://toloka.to/t672395

Для не HDR прибрати оце:
Цитата:
-vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p


Використана інфа:
https://stackoverflow.com/questions/70544342/ffmpeg-why-is-output-video-contrast-brightness-too-bright
https://stackoverflow.com/questions/19091771/how-to-find-duration-of-a-video-file-using-Info-in-seconds-or-other-formats
Ваш часовий пояс: GMT + 2 Години

Нова тема   Відповісти