Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,45 +1,58 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
# Video to Audio Extractor
|
| 3 |
|
| 4 |
-
A FastAPI-based web application that extracts audio from video files using FFmpeg.
|
| 5 |
|
| 6 |
-
## Features
|
| 7 |
|
| 8 |
-
- π₯
|
| 9 |
-
- π΅ Multiple audio
|
| 10 |
-
- π
|
| 11 |
-
- π
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
- π§Ή
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
|
| 24 |
-
## Usage
|
| 25 |
|
| 26 |
-
###
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
### API Usage
|
| 30 |
|
| 31 |
```bash
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
# Extract
|
| 38 |
-
|
| 39 |
-
response=$(curl -X POST -F "video=@large_video.mp4" -F "output_format=mp3" \
|
| 40 |
-
https://your-space.hf.space/extract-audio)
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
job_id=$(echo $response | jq -r '.job_id')
|
| 44 |
|
| 45 |
# Check status
|
|
@@ -49,64 +62,101 @@ curl https://your-space.hf.space/status/$job_id
|
|
| 49 |
curl https://your-space.hf.space/download/$job_id --output audio.mp3
|
| 50 |
```
|
| 51 |
|
| 52 |
-
### Python
|
| 53 |
|
| 54 |
```python
|
| 55 |
import requests
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
if response.headers.get('content-type', '').startswith('audio/'):
|
| 65 |
-
# Direct
|
| 66 |
-
|
| 67 |
-
out.write(response.content)
|
| 68 |
else:
|
| 69 |
-
#
|
| 70 |
job_data = response.json()
|
| 71 |
job_id = job_data['job_id']
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
```
|
| 74 |
|
| 75 |
-
##
|
| 76 |
|
| 77 |
-
-
|
| 78 |
-
-
|
| 79 |
-
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
##
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
- `Dockerfile`
|
| 89 |
-
- `README.md`
|
| 90 |
-
4. The Space will automatically build and deploy
|
| 91 |
|
| 92 |
-
## Local Development
|
| 93 |
|
| 94 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Install dependencies
|
| 96 |
pip install -r requirements.txt
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
# Ubuntu/Debian
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
# Run the
|
| 103 |
-
|
| 104 |
```
|
| 105 |
|
| 106 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
|
| 110 |
-
##
|
| 111 |
|
| 112 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Video to Audio Extractor
|
| 3 |
+
emoji: π΅
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
# Video to Audio Extractor
|
| 12 |
|
| 13 |
+
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.
|
| 14 |
|
| 15 |
+
## π― Features
|
| 16 |
|
| 17 |
+
- π₯ **Multiple video formats**: MP4, AVI, MOV, MKV, WebM, FLV, WMV, M4V
|
| 18 |
+
- π΅ **Multiple audio formats**: MP3, AAC, WAV, FLAC, M4A, OGG
|
| 19 |
+
- π **Quality levels**: High, Medium, Low
|
| 20 |
+
- π **Smart processing**: Direct response for small files, background jobs for large files
|
| 21 |
+
- π **Web interface**: User-friendly UI with real-time progress
|
| 22 |
+
- π **REST API**: Full API access for programmatic use
|
| 23 |
+
- π§Ή **Auto-cleanup**: Temporary files cleaned automatically
|
| 24 |
|
| 25 |
+
## π₯οΈ Web Interface
|
| 26 |
|
| 27 |
+
Visit the Space URL to access the web interface where you can:
|
| 28 |
+
- Upload video files via drag-and-drop or file selection
|
| 29 |
+
- Choose output format and quality
|
| 30 |
+
- Preview and download extracted audio
|
| 31 |
+
- See real-time processing status
|
| 32 |
|
| 33 |
+
## π‘ API Usage
|
| 34 |
|
| 35 |
+
### Extract Audio (Direct Response)
|
| 36 |
+
For files under 10MB, get immediate response:
|
|
|
|
|
|
|
| 37 |
|
| 38 |
```bash
|
| 39 |
+
curl -X POST -F "video=@video.mp4" \
|
| 40 |
+
-F "output_format=mp3" \
|
| 41 |
+
-F "quality=high" \
|
| 42 |
+
https://your-space.hf.space/extract-audio \
|
| 43 |
+
--output audio.mp3
|
| 44 |
+
```
|
| 45 |
|
| 46 |
+
### Extract Audio (Background Job)
|
| 47 |
+
For larger files:
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
```bash
|
| 50 |
+
# Submit job
|
| 51 |
+
response=$(curl -X POST -F "video=@large_video.mp4" \
|
| 52 |
+
-F "output_format=mp3" \
|
| 53 |
+
https://your-space.hf.space/extract-audio)
|
| 54 |
+
|
| 55 |
+
# Get job ID
|
| 56 |
job_id=$(echo $response | jq -r '.job_id')
|
| 57 |
|
| 58 |
# Check status
|
|
|
|
| 62 |
curl https://your-space.hf.space/download/$job_id --output audio.mp3
|
| 63 |
```
|
| 64 |
|
| 65 |
+
### Python Example
|
| 66 |
|
| 67 |
```python
|
| 68 |
import requests
|
| 69 |
+
import time
|
| 70 |
|
| 71 |
+
def extract_audio(video_path, output_format='mp3', quality='medium'):
|
| 72 |
+
url = 'https://your-space.hf.space/extract-audio'
|
| 73 |
+
|
| 74 |
+
with open(video_path, 'rb') as f:
|
| 75 |
+
files = {'video': f}
|
| 76 |
+
data = {'output_format': output_format, 'quality': quality}
|
| 77 |
+
response = requests.post(url, files=files, data=data)
|
| 78 |
|
| 79 |
if response.headers.get('content-type', '').startswith('audio/'):
|
| 80 |
+
# Direct response - save file
|
| 81 |
+
return response.content
|
|
|
|
| 82 |
else:
|
| 83 |
+
# Background job - poll for completion
|
| 84 |
job_data = response.json()
|
| 85 |
job_id = job_data['job_id']
|
| 86 |
+
|
| 87 |
+
while True:
|
| 88 |
+
status = requests.get(f'{url.replace("/extract-audio", "")}/status/{job_id}').json()
|
| 89 |
+
if status['status'] == 'completed':
|
| 90 |
+
audio = requests.get(f'{url.replace("/extract-audio", "")}/download/{job_id}')
|
| 91 |
+
return audio.content
|
| 92 |
+
elif status['status'] == 'failed':
|
| 93 |
+
raise Exception(f"Processing failed: {status.get('error')}")
|
| 94 |
+
time.sleep(2)
|
| 95 |
+
|
| 96 |
+
# Usage
|
| 97 |
+
audio_data = extract_audio('my_video.mp4', 'mp3', 'high')
|
| 98 |
+
with open('output.mp3', 'wb') as f:
|
| 99 |
+
f.write(audio_data)
|
| 100 |
```
|
| 101 |
|
| 102 |
+
## π§ API Endpoints
|
| 103 |
|
| 104 |
+
- `GET /` - Web interface
|
| 105 |
+
- `POST /extract-audio` - Extract audio from video
|
| 106 |
+
- `GET /status/{job_id}` - Check job status
|
| 107 |
+
- `GET /download/{job_id}` - Download processed audio
|
| 108 |
+
- `GET /api/info` - API information and supported formats
|
| 109 |
|
| 110 |
+
## π Quality Settings
|
| 111 |
|
| 112 |
+
| Quality | MP3 Bitrate | AAC Bitrate | Description |
|
| 113 |
+
|---------|-------------|-------------|-------------|
|
| 114 |
+
| High | 320 kbps | 256 kbps | Best quality, larger files |
|
| 115 |
+
| Medium | 192 kbps | 192 kbps | Balanced (default) |
|
| 116 |
+
| Low | 128 kbps | 128 kbps | Smaller files |
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
## π Local Development
|
| 119 |
|
| 120 |
```bash
|
| 121 |
+
# Clone the repository
|
| 122 |
+
git clone <your-repo>
|
| 123 |
+
cd video-to-audio-extractor
|
| 124 |
+
|
| 125 |
# Install dependencies
|
| 126 |
pip install -r requirements.txt
|
| 127 |
|
| 128 |
+
# Install FFmpeg
|
| 129 |
+
# Ubuntu/Debian
|
| 130 |
+
sudo apt-get update && sudo apt-get install ffmpeg
|
| 131 |
+
|
| 132 |
+
# macOS
|
| 133 |
+
brew install ffmpeg
|
| 134 |
+
|
| 135 |
+
# Windows
|
| 136 |
+
# Download from https://ffmpeg.org/download.html
|
| 137 |
+
|
| 138 |
+
# Run the application
|
| 139 |
+
uvicorn app:app --reload --host 0.0.0.0 --port 7860
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
## π³ Docker Deployment
|
| 143 |
+
|
| 144 |
+
```bash
|
| 145 |
+
# Build the image
|
| 146 |
+
docker build -t video-to-audio-extractor .
|
| 147 |
|
| 148 |
+
# Run the container
|
| 149 |
+
docker run -p 7860:7860 video-to-audio-extractor
|
| 150 |
```
|
| 151 |
|
| 152 |
+
## π License
|
| 153 |
+
|
| 154 |
+
This project is licensed under the MIT License.
|
| 155 |
+
|
| 156 |
+
## π€ Contributing
|
| 157 |
|
| 158 |
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
| 159 |
|
| 160 |
+
## π Issues
|
| 161 |
|
| 162 |
+
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.
|