Skip to content

Instantly share code, notes, and snippets.

@DejayRezme
Created January 22, 2022 19:51
Show Gist options
  • Save DejayRezme/c6c657dfcd5a6f613f5fd20e5fc5656c to your computer and use it in GitHub Desktop.
Save DejayRezme/c6c657dfcd5a6f613f5fd20e5fc5656c to your computer and use it in GitHub Desktop.
Script to encode a bunch of files with SvtAv1EncApp and ffmpeg from command line
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[string] $inputPath,
[int] $sp = 7,
[int] $crf = 28,
[int] $fg = 0,
[switch] $af,
[switch] $wi
)
if ($af) {$audioOptions = "-af channelmap=channel_layout=5.1"}
#$encodeCommand = "ffmpeg -i `"$inputFile`" -loglevel warning -nostdin -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p10le - | SvtAv1EncApp.exe -i stdin --passes 1 --progress 2 --input-depth 10 --keyint 240 --crf $crf --preset $speed -i stdin -b stdout | ffmpeg -loglevel warning -i - -vn -i `"$inputFile`" -y -c copy -c:a libopus $audioOptions `"$outputFile`""
Get-ChildItem $inputPath | Foreach-Object {
$inputFile=$_.Name
$outputFile = $_.BaseName #.Replace(' ','.').Replace('.-.','.').Replace('.h264','').Replace('.H.264','').Replace('.h265','').Replace('.x265','')
$outputFile += ".AV1.SVT.CRF" + $crf + ".SP" + $sp
if ($fg -ne 0) {$outputFile += ".FG" + $fg}
$outputFile += ".Opus.mkv"
if ($inputFile.ToLower().Contains("av1") -or (Test-Path $outputFile)) {
Write-Host "Skipping: " $inputFile
} else {
$encodeCommand = "ffmpeg -i `"$inputFile`" -loglevel warning -nostdin -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p10le - | SvtAv1EncApp.exe -i stdin --progress 2 --input-depth 10 --keyint 240 --crf $crf --preset $sp --film-grain $fg -i stdin -b stdout | ffmpeg -loglevel warning -i - -vn -i `"$inputFile`" -y -c copy -c:a libopus $audioOptions `"$outputFile`""
# --enable-overlays 1 (screws up playback?)
Write-Host $encodeCommand
if (-not $wi) {
$Process = Start-Process "cmd.exe" -ArgumentList "/c", $encodeCommand -NoNewWindow -PassThru
$Process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::BelowNormal
Wait-Process -InputObject $Process
}
Write-Host "Done encoding"
Sleep 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment