2.3 KiB
2.3 KiB
Get-VideoAudio.ps1
Extracts audio in either WAV or MP3 format from a video file.
Parameters
-Video(required): Path to input video file (absolute or relative)-Output(optional): Path to output audio file (defaults to video filename with.wavor.mp3extension)-MP3: Extract audio as MP3 at 320 kbps instead of WAV
Examples
Extract audio as WAV (default):
.\Get-VideoAudio.ps1 -Video video.mp4
# Creates video.wav in the same directory
Extract audio as MP3:
.\Get-VideoAudio.ps1 -Video video.mp4 -MP3
# Creates video.mp3 in the same directory
Specify custom output path:
.\Get-VideoAudio.ps1 -Video video.mp4 -Output audio\soundtrack.wav
Extract MP3 with custom output:
.\Get-VideoAudio.ps1 -Video video.mp4 -Output music.mp3 -MP3
Using absolute paths:
.\Get-VideoAudio.ps1 -Video "C:\Videos\movie.mp4" -Output "D:\Audio\soundtrack.mp3" -MP3
Using relative paths:
.\Get-VideoAudio.ps1 -Video ..\videos\clip.mp4 -Output .\audio\clip.wav
Behavior
- If the video file has no audio stream, the script displays a message and exits without creating an output file
- WAV format uses PCM 16-bit encoding (lossless)
- MP3 format uses 320 kbps bitrate (highest quality)
Existing Files
- An existing output file, the default
<video>.wavor<video>.mp3, or the-Outputpath, is replaced without a prompt. ffmpeg runs with-y, so the old file is lost. Use-WhatIffirst, or write to a new name. - If the output folder does not exist, ffmpeg fails and the script stops with an error.
- If the video has no audio stream, the script prints a message and exits successfully. It creates no file and leaves any existing output untouched.
Safe Execution
This script supports -WhatIf and -Confirm for safe execution:
-WhatIf: Simulate the operation without actually creating files. Shows what would be done.-Confirm: Prompt for confirmation before extracting audio.
Simulate without making changes:
.\Get-VideoAudio.ps1 -Video video.mp4 -MP3 -WhatIf
Prompt before extracting:
.\Get-VideoAudio.ps1 -Video video.mp4 -Output soundtrack.wav -Confirm
Notes
Requires ffmpeg and ffprobe to be installed and available in the system PATH.