Created
November 15, 2025 09:21
-
-
Save tnraro/3780e7fa970863d257bb5a7b227fcb96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Param( | |
| [Parameter(Mandatory=$true)] [string]$path | |
| ) | |
| $raw_fps = ffprobe -v 0 -of csv=p=0 -select_streams 0 -show_entries stream=r_frame_rate $path | |
| if ($raw_fps -eq $null) { | |
| Write-Host -ForegroundColor red "Invalid video format: '$path'" | |
| exit 1 | |
| } | |
| $parts = $raw_fps.Split('/') | |
| [int]$fps = [double]$parts[0] / [double]$parts[1] | |
| [int]$resolution = ffprobe -v 0 -select_streams v:0 -show_entries stream=height -of csv=s=x:p=0 $path | |
| Write-Output "Video: $($resolution)p$($fps)" | |
| if ($fps -le 30) { | |
| $br = switch ($resolution) { | |
| 360 { 1 } | |
| 480 { 2.5 } | |
| 720 { 5 } | |
| 1080 { 8 } | |
| 1440 { 16 } | |
| 2160 { 35 } | |
| 2880 { 80 } | |
| } | |
| } elseif ($fps -le 60) { | |
| $br = switch ($resolution) { | |
| 360 { 1.5 } | |
| 480 { 4 } | |
| 720 { 7.5 } | |
| 1080 { 12 } | |
| 1440 { 24 } | |
| 2160 { 53 } | |
| 2880 { 120 } | |
| } | |
| } | |
| if ($br -eq $null) { | |
| Write-Host -ForegroundColor red "Invalid video resolution or fps: '$($resolution)p$($fps)'" | |
| exit 2 | |
| } | |
| $brs = "$($br)M" | |
| $brm = "$($br * 1.5)M" | |
| $brb = "$($br * 2)M" | |
| Write-Host "Bitrate: $brs, $brm, $brb" | |
| ffmpeg -hwaccel cuda -hwaccel_output_format cuda ` | |
| -hide_banner ` | |
| -i $path ` | |
| -c:v h264_nvenc ` | |
| -preset p7 -profile:v high -tune hq -multipass fullres ` | |
| -pix_fmt yuv420p ` | |
| -rc vbr -cq 19 -b:v $brs -maxrate $brm -bufsize $brb ` | |
| -rc-lookahead 32 -spatial-aq 1 ` | |
| -r $fps -g $($fps / 2) -bf 2 ` | |
| -colorspace bt709 -color_primaries bt709 -color_trc bt709 ` | |
| -c:a aac -b:a 384k -ar 48000 -ac 2 ` | |
| -movflags +faststart ` | |
| output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment