metadata
title: Video to Audio Extractor
emoji: π΅
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
Video to Audio Extractor
A FastAPI-based web application that extracts audio from video files using FFmpeg. Convert your videos to audio in various formats with customizable quality settings.
π― Features
- π₯ Multiple video formats: MP4, AVI, MOV, MKV, WebM, FLV, WMV, M4V
- π΅ Multiple audio formats: MP3, AAC, WAV, FLAC, M4A, OGG
- π Quality levels: High, Medium, Low
- π Smart processing: Direct response for small files, background jobs for large files
- π Web interface: User-friendly UI with real-time progress
- π REST API: Full API access for programmatic use
- π§Ή Auto-cleanup: Temporary files cleaned automatically
π₯οΈ Web Interface
Visit the Space URL to access the web interface where you can:
- Upload video files via drag-and-drop or file selection
- Choose output format and quality
- Preview and download extracted audio
- See real-time processing status
π‘ API Usage
Extract Audio (Direct Response)
For files under 10MB, get immediate response:
curl -X POST -F "video=@video.mp4" \
-F "output_format=mp3" \
-F "quality=high" \
https://your-space.hf.space/extract-audio \
--output audio.mp3
Extract Audio (Background Job)
For larger files:
# Submit job
response=$(curl -X POST -F "video=@large_video.mp4" \
-F "output_format=mp3" \
https://your-space.hf.space/extract-audio)
# Get job ID
job_id=$(echo $response | jq -r '.job_id')
# Check status
curl https://your-space.hf.space/status/$job_id
# Download when ready
curl https://your-space.hf.space/download/$job_id --output audio.mp3
Python Example
import requests
import time
def extract_audio(video_path, output_format='mp3', quality='medium'):
url = 'https://your-space.hf.space/extract-audio'
with open(video_path, 'rb') as f:
files = {'video': f}
data = {'output_format': output_format, 'quality': quality}
response = requests.post(url, files=files, data=data)
if response.headers.get('content-type', '').startswith('audio/'):
# Direct response - save file
return response.content
else:
# Background job - poll for completion
job_data = response.json()
job_id = job_data['job_id']
while True:
status = requests.get(f'{url.replace("/extract-audio", "")}/status/{job_id}').json()
if status['status'] == 'completed':
audio = requests.get(f'{url.replace("/extract-audio", "")}/download/{job_id}')
return audio.content
elif status['status'] == 'failed':
raise Exception(f"Processing failed: {status.get('error')}")
time.sleep(2)
# Usage
audio_data = extract_audio('my_video.mp4', 'mp3', 'high')
with open('output.mp3', 'wb') as f:
f.write(audio_data)
π§ API Endpoints
GET /- Web interfacePOST /extract-audio- Extract audio from videoGET /status/{job_id}- Check job statusGET /download/{job_id}- Download processed audioGET /api/info- API information and supported formats
π Quality Settings
| Quality | MP3 Bitrate | AAC Bitrate | Description |
|---|---|---|---|
| High | 320 kbps | 256 kbps | Best quality, larger files |
| Medium | 192 kbps | 192 kbps | Balanced (default) |
| Low | 128 kbps | 128 kbps | Smaller files |
π Local Development
# Clone the repository
git clone <your-repo>
cd video-to-audio-extractor
# Install dependencies
pip install -r requirements.txt
# Install FFmpeg
# Ubuntu/Debian
sudo apt-get update && sudo apt-get install ffmpeg
# macOS
brew install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.html
# Run the application
uvicorn app:app --reload --host 0.0.0.0 --port 7860
π³ Docker Deployment
# Build the image
docker build -t video-to-audio-extractor .
# Run the container
docker run -p 7860:7860 video-to-audio-extractor
π License
This project is licensed under the MIT License.
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π Issues
If you encounter any issues or have feature requests, please file them in the Issues section.