reduce mp3 file size using ffmpeg
Sat Aug 05 2023 02:32:15 GMT+0000 (Coordinated Universal Time)
Saved by
@vs
# Set the path to the folder containing the MP3 files
$folderPath = "C:\Path\to\your\Files"
# Check if ffmpeg is installed
if (-Not (Test-Path (Join-Path $env:ProgramFiles "ffmpeg\bin\ffmpeg.exe"))) {
Write-Host "ffmpeg not found. Please install ffmpeg and make sure it's added to the PATH."
exit
}
# Get a list of all MP3 files in the folder excluding *small.mp3 files
$mp3Files = Get-ChildItem -Path $folderPath -Filter "*.mp3" | Where-Object { $_.Name -notlike "*small.mp3" }
# Loop through each MP3 file and compress it if the compressed file doesn't exist
foreach ($file in $mp3Files) {
$inputFilePath = $file.FullName
$outputFilePath = [System.IO.Path]::ChangeExtension($inputFilePath, "small.mp3")
# Check if the compressed file already exists
if (-Not (Test-Path -Path $outputFilePath)) {
# Compress the MP3 using ffmpeg
$ffmpegCommand = "ffmpeg -i `"$inputFilePath`" -b:a 64k `"$outputFilePath`""
Start-Process -FilePath "cmd.exe" -ArgumentList "/c", $ffmpegCommand -Wait
Write-Host "Compressed file created: $outputFilePath"
} else {
Write-Host "Compressed file already exists: $outputFilePath"
}
}
content_copyCOPY
Comments