Audio Extractor
A Python tool for extracting and managing audio tracks from video files using FFmpeg.
Features
- Extract Audio: Extract all audio channels from video files as individual files
- Preserve Quality: Maintains original bitrate and codec without re-encoding
- Batch Processing: Process multiple video files from a folder
- Multi-track Support: Automatically handles videos with multiple audio tracks
- Flexible Output: Specify custom output folder
Future Features
- Add Tracks: Add individual audio files as new tracks to video files
- Track Titles: Assign custom titles/names to audio tracks
- Batch Operations: Apply operations to multiple files with matching base names
Installation
Prerequisites
- Python 3.6+
- FFmpeg installed and accessible in your PATH
- FFprobe (usually included with FFmpeg)
Install FFmpeg
macOS (using Homebrew):
brew install ffmpeg
Ubuntu/Debian:
sudo apt-get install ffmpeg
Windows (using Chocolatey):
choco install ffmpeg
Or download from: https://ffmpeg.org/download.html
Usage
Extract Audio from a Single Video
python main.py extract "path/to/video.mp4" -o ./audio_output
Extract Audio from All Videos in a Folder
python main.py extract "./videos_folder" -o ./audio_output
Legacy Command Format
The tool also supports the original command format:
python main.py --extract "target" -o output_folder
Examples
Extract from single file:
python main.py extract "movie.mp4" -o ./extracted_audio
Extract from entire folder:
python main.py extract "./my_videos" -o "./audio_tracks"
Extract with default output folder (./audio_output):
python main.py extract "video.mkv"
How It Works
- Identifies video files in the target path
- Analyzes audio streams using ffprobe to detect codec and bitrate information
- Extracts each audio track using FFmpeg's codec copy mode (no re-encoding)
- Preserves quality by maintaining original bitrate and codec
- Names files appropriately based on source video and track number
Output
Extracted audio files are saved with the following naming:
- Single audio track:
video_name.aac(or appropriate extension) - Multiple audio tracks:
video_name_audio_0.aac,video_name_audio_1.aac, etc.
Troubleshooting
"ffmpeg is not installed or not found in PATH"
- Ensure FFmpeg is installed and the
ffmpegcommand is accessible from your terminal - Test with:
ffmpeg -version
"No audio streams found"
- The video file may not contain any audio tracks
- Try analyzing the file with:
ffprobe "video.mp4"
Extraction fails
- Check that the video file is not corrupted
- Try opening it with a media player first
- Check disk space in the output folder
Development
Project Structure
audio-extractor/
├── main.py # Entry point and CLI argument parsing
├── audio_extractor/
│ ├── __init__.py
│ ├── cli.py # CLI interface
│ └── extractor.py # Core extraction logic
├── requirements.txt
└── README.md
Adding Features
To add new features:
- Add command logic to
audio_extractor/extractor.py - Add CLI interface to
audio_extractor/cli.py - Add new command to the argument parser in
main.py
License
MIT
Description
Languages
Python
100%