Last active
July 21, 2024 15:57
-
-
Save IrealiTY/1d2c9a4ca09d42d0d01c1b49c0bc489b to your computer and use it in GitHub Desktop.
Converts audio FLAC to ac3 via Powershell and FFMPEG
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
Get-ChildItem -Filter *.mkv | ForEach-Object { | |
$outputFile = $_.BaseName + "_ac3.mkv" | |
# Get information about audio streams | |
$audioStreams = ffprobe -v error -select_streams a -show_entries stream=index,codec_name -of csv=p=0 $_.FullName | ForEach-Object { | |
$stream = $_ -split ',' | |
[PSCustomObject]@{ | |
Index = [int]$stream[0] | |
Codec = $stream[1] | |
} | |
} | |
$ffmpegCommand = "ffmpeg -i `"$($_.FullName)`" -map 0 -c copy" | |
foreach ($stream in $audioStreams) { | |
if ($stream.Codec -eq 'flac') { | |
$ffmpegCommand += " -c:a:$($stream.Index) ac3" | |
} | |
} | |
$ffmpegCommand += " `"$outputFile`"" | |
Write-Host "Processing file: $($_.Name)" | |
Write-Host "Command: $ffmpegCommand" | |
Invoke-Expression $ffmpegCommand | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment