Skip to content

Instantly share code, notes, and snippets.

@JonLevin25
Created September 17, 2020 22:05
Show Gist options
  • Save JonLevin25/513fd676f6e61b25b50e23285795afd1 to your computer and use it in GitHub Desktop.
Save JonLevin25/513fd676f6e61b25b50e23285795afd1 to your computer and use it in GitHub Desktop.
Unity - Transcode .wavs to .mp3s with ffmpeg
while ( $deleteInp -notmatch "[yYnN]" ) {
$deleteInp = Read-Host -Prompt "Delete files when done? [y/n]"
}
$delete = $deleteInp -match "[yY]"
$deleteInp = "" # reset this since its global
echo "------ Transcoding MP3s -------"
$oldFileEnding='.wav'
$newFileEnding='.mp3'
Get-ChildItem -File -Recurse | Where-Object { $_.FullName.EndsWith($oldFileEnding) } | ForEach-Object {
$old=$_.FullName
$new = $old.Substring(0, $old.Length - $oldFileEnding.Length) + $newFileEnding
ffmpeg -i $old $new
if ($delete) {
echo "Deleting WAV $old"
Remove-Item $old
}
}
echo "------ Renaming metas -------"
$oldFileEnding='.wav.meta'
$newFileEnding='.mp3.meta'
Get-ChildItem -File -Recurse | Where-Object { $_.FullName.EndsWith($oldFileEnding) } | ForEach-Object {
$old=$_.FullName
$new = $old.Substring(0, $old.Length - $oldFileEnding.Length) + $newFileEnding
Copy-Item $old $new
if ($delete) {
echo "Deleting meta $old"
Remove-Item $old
}
}
@JonLevin25
Copy link
Author

Quick script to transcode all .wavs to .mp3s recursively.

  • Uses ffmpeg default settings (inferred from extension)
  • Also renames Unity .meta files to mp3 so project keeps all references

Could reuse some stuff with a function but it works and isnt important enough to research more Powershell syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment