A Python API that extracts a frame from a video at a specific time.
pip install -r requirements.txtuvicorn main:app --reloadThe API will be available at http://localhost:8000
Extract a frame from a video URL at a specific time.
Request Body:
{
"video_url": "https://example.com/video.mp4",
"time": 5.5
}Parameters:
video_url(string): URL of the video filetime(float): Time in seconds (e.g., 5.5 for 5.5 seconds)
Response:
- Returns a PNG image of the frame at the specified time
Example using curl:
curl -X POST "http://localhost:8000/extract-frame" \
-H "Content-Type: application/json" \
-d '{"video_url": "https://example.com/video.mp4", "time": 5.5}' \
--output frame.pngExample using Python:
import requests
response = requests.post(
"http://localhost:8000/extract-frame",
json={
"video_url": "https://example.com/video.mp4",
"time": 5.5
}
)
with open("frame.png", "wb") as f:
f.write(response.content)Once the server is running, you can access:
- Interactive API docs:
http://localhost:8000/docs - Alternative docs:
http://localhost:8000/redoc
- Install Google Cloud SDK
- Install Docker
- Authenticate with Google Cloud:
gcloud auth login gcloud auth configure-docker
-
Set your Google Cloud project ID:
export GOOGLE_CLOUD_PROJECT="your-project-id"
-
Make the script executable and run it:
chmod +x deploy.sh ./deploy.sh
-
Set your Google Cloud project ID:
export GOOGLE_CLOUD_PROJECT="your-project-id"
-
Make the script executable and run it:
chmod +x deploy-cloud-build.sh ./deploy-cloud-build.sh
-
Build and push the Docker image:
export PROJECT_ID="your-project-id" docker build -t gcr.io/${PROJECT_ID}/video-frame-extractor:latest . docker push gcr.io/${PROJECT_ID}/video-frame-extractor:latest
-
Deploy to Cloud Run:
gcloud run deploy video-frame-extractor \ --image gcr.io/${PROJECT_ID}/video-frame-extractor:latest \ --platform managed \ --region us-central1 \ --allow-unauthenticated \ --memory 2Gi \ --cpu 2 \ --timeout 300
The deployment uses:
- Memory: 2GB (adjustable for larger videos)
- CPU: 2 cores
- Timeout: 300 seconds (5 minutes)
- Region: us-central1 (changeable)
After deployment, you'll receive a URL like:
https://video-frame-extractor-xxxxx-uc.a.run.app
You can then use this URL instead of localhost:8000 in your API calls.