Last active
January 4, 2025 15:57
-
-
Save alighafoori/318624a988cfbf6409271a146685f69c to your computer and use it in GitHub Desktop.
PowerShell Script to Convert Video Files to MP3 Using 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
# Path to FFmpeg executable | |
$FFmpegPath = "Path\To\ffmpeg.exe" | |
# Path to the folder containing video files | |
$InputFolder = "Path\To\InputFolder" | |
# Path to the output folder for MP3 files | |
$OutputFolder = "Path\To\OutputFolder" | |
# Ensure the output folder exists | |
if (-not (Test-Path -Path $OutputFolder)) { | |
New-Item -ItemType Directory -Path $OutputFolder | Out-Null | |
} | |
# Get all video files in the input folder | |
$VideoFiles = Get-ChildItem -Path $InputFolder -Recurse -File | Where-Object { | |
$_.Extension -match '\.mp4|\.mkv|\.avi|\.mov|\.webm|\.ts' | |
} | |
foreach ($VideoFile in $VideoFiles) { | |
# Construct the output file path | |
$OutputFile = Join-Path -Path $OutputFolder -ChildPath ($VideoFile.BaseName + ".mp3") | |
# Check if the output file already exists | |
if (Test-Path -Path $OutputFile) { | |
Write-Host "Skipping (already exists): $($VideoFile.Name)" -ForegroundColor Yellow | |
continue | |
} | |
# FFmpeg arguments | |
$Arguments = @( | |
"-i", $VideoFile.FullName, | |
"-q:a", "0", | |
"-map", "a", | |
$OutputFile | |
) | |
# Run the FFmpeg command | |
Write-Host "Processing: $($VideoFile.Name)" -ForegroundColor Cyan | |
& $FFmpegPath @Arguments | |
Write-Host "Completed: $($VideoFile.Name)" -ForegroundColor Green | |
} | |
Write-Host "All conversions completed." -ForegroundColor Yellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment