audio-processor / README.md
tedowski's picture
Update README.md
66f9ab9 verified
---
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:
```bash
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:
```bash
# 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
```python
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 interface
- `POST /extract-audio` - Extract audio from video
- `GET /status/{job_id}` - Check job status
- `GET /download/{job_id}` - Download processed audio
- `GET /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
```bash
# 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
```bash
# 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](https://huggingface.co/spaces/your-username/your-space-name/discussions) section.