Files
Video-Processing-Scripts/skill/Get-VideoAudio.md
T

85 lines
2.3 KiB
Markdown

# 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 `.wav` or `.mp3` extension)
- **`-MP3`**: Extract audio as MP3 at 320 kbps instead of WAV
## Examples
**Extract audio as WAV (default):**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4
# Creates video.wav in the same directory
```
**Extract audio as MP3:**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4 -MP3
# Creates video.mp3 in the same directory
```
**Specify custom output path:**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4 -Output audio\soundtrack.wav
```
**Extract MP3 with custom output:**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4 -Output music.mp3 -MP3
```
**Using absolute paths:**
```powershell
.\Get-VideoAudio.ps1 -Video "C:\Videos\movie.mp4" -Output "D:\Audio\soundtrack.mp3" -MP3
```
**Using relative paths:**
```powershell
.\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>.wav` or `<video>.mp3`, or the `-Output` path, is **replaced** without a prompt. ffmpeg runs with `-y`, so the old file is lost. Use `-WhatIf` first, 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:**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4 -MP3 -WhatIf
```
**Prompt before extracting:**
```powershell
.\Get-VideoAudio.ps1 -Video video.mp4 -Output soundtrack.wav -Confirm
```
## Notes
Requires `ffmpeg` and `ffprobe` to be installed and available in the system PATH.