File size: 4,522 Bytes
66f9ab9
 
 
 
 
 
 
 
 
 
99e4038
 
66f9ab9
99e4038
66f9ab9
99e4038
66f9ab9
 
 
 
 
 
 
99e4038
66f9ab9
99e4038
66f9ab9
 
 
 
 
99e4038
66f9ab9
99e4038
66f9ab9
 
99e4038
 
66f9ab9
 
 
 
 
 
99e4038
66f9ab9
 
99e4038
66f9ab9
 
 
 
 
 
 
99e4038
 
 
 
 
 
 
 
 
66f9ab9
99e4038
 
 
66f9ab9
99e4038
66f9ab9
 
 
 
 
 
 
99e4038
 
66f9ab9
 
99e4038
66f9ab9
99e4038
 
66f9ab9
 
 
 
 
 
 
 
 
 
 
 
 
 
99e4038
 
66f9ab9
99e4038
66f9ab9
 
 
 
 
99e4038
66f9ab9
99e4038
66f9ab9
 
 
 
 
99e4038
66f9ab9
99e4038
 
66f9ab9
 
 
 
99e4038
 
 
66f9ab9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99e4038
66f9ab9
 
99e4038
 
66f9ab9
 
 
 
 
99e4038
66f9ab9
99e4038
66f9ab9
99e4038
66f9ab9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
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.