Skip to content

Instantly share code, notes, and snippets.

@coverprice
Created May 21, 2022 02:54
Show Gist options
  • Save coverprice/df71396e7951998ee04ed0063aa00992 to your computer and use it in GitHub Desktop.
Save coverprice/df71396e7951998ee04ed0063aa00992 to your computer and use it in GitHub Desktop.
Powershell script to extract the audio from a downloaded video file (e.g. a Youtube video).
[CmdletBinding()]
param (
[Parameter(ValueFromRemainingArguments=$true)]
$Path
)
# This script extracts the audio content from downloaded videos. It's meant to be run by drag-and-dropping the video
# onto the script. However since you can't do that directly to Powershell scripts, set it up this way:
# 1. Install Powershell
# 2. Make a shortcut to this script on your Desktop (call it what you like)
# 3. Edit the shortcut and change the target to:
# pwsh.exe -file "C:\path\to\this\powershell_script.ps1"
if ( $Path -eq '') {
write-host -ForegroundColor Red 'Error, no input file provided'
pause
exit
}
$source_file=$Path
if ($source_file.ToLower().EndsWith('.mp4') -or $source_file.ToLower().EndsWith('.avi')) {
$dest_file = $source_file.substring(0, $source_file.Length - 4) + '.m4a'
} else {
write-host -ForegroundColor Red "Unsupported file type, sorry"
pause
exit
}
Start-Process -Wait -NoNewWindow -FilePath 'E:\ffmpeg\bin\ffmpeg.exe' -ArgumentList "-i","`"$source_file`"","-vn","-acodec","copy","`"$dest_file`""
write-host -ForegroundColor Green "Output file is: " $dest_file
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment