Team Ai
Apppublic

unveilAiDotOrg/audio-processor

sourceHugging Facemitupdated 1y agoView on Hugging Face
4likes
App README

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

QualityMP3 BitrateAAC BitrateDescription
High320 kbps256 kbpsBest quality, larger files
Medium192 kbps192 kbpsBalanced (default)
Low128 kbps128 kbpsSmaller 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 section.