Created
October 19, 2024 19:03
-
-
Save ellartdev/a1d32f2d29f2cc9d9cc02eba6d65495b to your computer and use it in GitHub Desktop.
Converts WAV files to WAV with 48000Hz sampling rate
This file contains 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
<# | |
# ConvertWAV-to48000.ps1 | |
# Converts WAV files to WAV with 48000Hz sampling rate | |
# ==================================================================== | |
# I made it specifically for GTA V / Online's Self Radio because | |
# it cannot process WAV files with high bit rate (2116 kb/s). | |
# These start to play static with some hints of original track in the | |
# background, very vaguely can be heard. | |
# 1536 kb/s bit rate seems to be a sweet spot for the game's radio. | |
# ==================================================================== | |
# Make sure ffmpeg and Get-MediaInfo (Module from PSGallery) is | |
# installed. | |
# ==================================================================== | |
# ellartdev 2024 | |
#> | |
$path = $env:USERPROFILE + '\Documents\Rockstar Games\GTA V\User Music' | |
$moveto_path = $env:USERPROFILE + '\Music\from_Convert-to48000' | |
$move_music = $true | |
if (Get-Module -ListAvailable -Name Get-MediaInfo) { | |
Get-ChildItem -Path $path -Filter *.wav -Recurse -File -Name | ForEach-Object { | |
$bitrate = "$path\$_" | Get-MediaInfoValue -Kind Audio -Parameter 'BitRate' | |
Write-Host "> $_" | |
Write-Host "> BitRate: $bitrate" | |
if ($bitrate -le 1536000 -or $_.EndsWith('-original.wav') -or $_.EndsWith('-48000.wav')) { Write-Host "> No action required :)" -ForegroundColor green } | |
else { | |
$track = [System.IO.Path]::GetFileNameWithoutExtension($_) | |
Write-Host "$_ to be converted" -ForegroundColor yellow | |
ffmpeg -loglevel quiet -i "$path\$_" -osr 48000 "$path\$track-48000.wav" | Out-Null | |
if ($move_music) { | |
Write-Host "> Moving $_ to $moveto_path" -ForegroundColor cyan | |
Move-Item -Path "$path\$_" -Destination $moveto_path | |
} else { | |
Write-Host "> Renaming $_ to $track-original.wav" -ForegroundColor cyan | |
Rename-Item -Path "$path\$_" -NewName "$track-original.wav" | |
} | |
} | |
Write-Host "" | |
} | |
} else { | |
Write-Host "> Get-MediaInfo module is missing." -ForegroundColor red | |
Write-Host "> Install module through PowerShell with admin rights: ""Install-Module Get-MediaInfo""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment