A Next.js API service that converts video files to MP3 audio format. Supports Google Drive public share links and other video platforms.
- Asynchronous Processing: Jobs are processed in the background with status tracking
- Google Drive Support: Handles public Google Drive share links automatically
- Progress Tracking: Real-time progress updates during conversion
- Temporary Storage: Uses Vercel Blob for temporary MP3 storage
- Error Handling: Comprehensive error handling and validation
- Automation Ready: Perfect for use with n8n and other automation tools
POST /api/extract-audio
Starts a new video-to-audio conversion job.
Request Body:
{
"videoUrl": "https://drive.google.com/file/d/YOUR_FILE_ID/view?usp=sharing"
}Response:
{
"success": true,
"jobId": "uuid-job-id",
"status": "queued",
"message": "Video processing started. Use the job ID to check status.",
"statusUrl": "/api/status/uuid-job-id",
"downloadUrl": "/api/download/uuid-job-id"
}GET /api/status/[jobId]
Check the status of a conversion job.
Response (Processing):
{
"jobId": "uuid-job-id",
"status": "processing",
"progress": 45,
"currentStep": "Extracting audio",
"progressMessage": "Converting video to audio... 45%",
"createdAt": "2023-12-01T10:00:00.000Z",
"updatedAt": "2023-12-01T10:02:30.000Z"
}Response (Completed):
{
"jobId": "uuid-job-id",
"status": "completed",
"progress": 100,
"message": "Job completed successfully",
"audioUrl": "https://blob.vercel-storage.com/audio.mp3",
"downloadUrl": "/api/download/uuid-job-id",
"completedAt": "2023-12-01T10:03:00.000Z"
}GET /api/download/[jobId]
Download the converted MP3 file.
Response: Binary MP3 file with appropriate headers.
queued: Job is waiting to be processedprocessing: Job is currently being processedcompleted: Job finished successfullyfailed: Job failed with an error
- Google Drive: Public share links (automatically converted to direct download)
- Direct URLs: Direct links to video files
- Other platforms: YouTube, Vimeo, Dropbox, OneDrive (with public access)
- MP4, AVI, MOV, WMV, FLV, WebM, MKV, M4V
Create a .env.local file with the following variables:
BLOB_READ_WRITE_TOKEN=your_vercel_blob_token- Clone and install dependencies:
npm install-
Set up environment variables: Create
.env.localwith your Vercel Blob token. -
Install FFmpeg: Make sure FFmpeg is installed on your system:
- macOS:
brew install ffmpeg - Ubuntu/Debian:
sudo apt install ffmpeg - Windows: Download from https://ffmpeg.org/
- Run development server:
npm run dev- Build for production:
npm run build
npm start# Start conversion
curl -X POST http://localhost:3000/api/extract-audio \
-H "Content-Type: application/json" \
-d '{"videoUrl": "https://drive.google.com/file/d/YOUR_FILE_ID/view"}'
# Check status
curl http://localhost:3000/api/status/YOUR_JOB_ID
# Download audio
curl -O http://localhost:3000/api/download/YOUR_JOB_ID- HTTP Request Node (POST to
/api/extract-audio) - Wait Node (optional delay)
- HTTP Request Node (GET status until completed)
- HTTP Request Node (GET download when ready)
async function convertVideoToAudio(videoUrl) {
// Start conversion
const startResponse = await fetch('/api/extract-audio', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ videoUrl })
});
const { jobId } = await startResponse.json();
// Poll for completion
let status = 'queued';
while (status !== 'completed' && status !== 'failed') {
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
const statusResponse = await fetch(`/api/status/${jobId}`);
const statusData = await statusResponse.json();
status = statusData.status;
console.log(`Progress: ${statusData.progress}%`);
}
if (status === 'completed') {
// Download the audio file
window.open(`/api/download/${jobId}`, '_blank');
}
}The API automatically handles these Google Drive URL formats:
https://drive.google.com/file/d/FILE_ID/view?usp=sharinghttps://drive.google.com/open?id=FILE_IDhttps://docs.google.com/file/d/FILE_ID/edit
The API provides detailed error messages for common issues:
- Invalid or missing video URL
- Unsupported video format
- Network/download errors
- FFmpeg processing errors
- Storage upload errors
- Install Vercel CLI:
npm i -g vercel- Deploy:
vercel- Set environment variables in Vercel dashboard:
BLOB_READ_WRITE_TOKEN
FROM node:18-alpine
RUN apk add --no-cache ffmpeg
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]- File Size: Limited by available memory and processing time
- Processing Time: 15-second timeout on Vercel (configurable)
- Concurrent Jobs: In-memory job storage (consider Redis for production)
- Storage: Temporary storage on Vercel Blob (files may be cleaned up)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the error messages in API responses
- Verify FFmpeg installation
- Ensure environment variables are set correctly
- Check Vercel Blob storage configuration