A lightweight API built with Elysia that provides automated video screenshot capture and GIF generation using FFmpeg. Perfect for quickly extracting key frames or creating GIF previews from video files.
- Capture screenshots at specific points in a video (beginning, quarter, midpoint, three-quarters, end).
- Generate GIFs from any segment of a video with customizable duration, frame rate (FPS), and width.
- Temporarily cache screenshots for quick access (10-minute automatic cleanup).
- Handles base64-encoded video URLs for secure transmission.
- Error handling for invalid parameters, unsupported video formats, and short videos.
-
Clone the repository
git clone https://github.com/shimizudev/episodes cd episodes -
Install dependencies
bun install
-
Ensure FFmpeg is installed The API relies on
ffmpegandffprobeavailable in your system path.ffmpeg -version ffprobe -version
-
Start the server
bun run start
By default, the server listens on port
3000. You can override with thePORTenvironment variable:PORT=8080 bun run start
GET /api/screenshot?url=<base64_encoded_url>
- Captures a screenshot at 75% of the video duration.
- Response:
image/png - Errors: Invalid URL, inaccessible video, or FFmpeg failure.
GET /api/gif?url=<base64_encoded_url>&duration=10&fps=10&width=480
-
Parameters:
duration(seconds, default: 10, range: 1–30)fps(frames per second, default: 10, range: 5–30)width(pixels, default: 480, range: 240–1920)
-
Response:
image/gif -
Headers include video duration, GIF start time, FPS, width, and GIF duration.
-
Errors: Video shorter than requested GIF duration, invalid parameters, FFmpeg failure.
GET /api/screenshots?url=<base64_encoded_url>
-
Captures screenshots at key positions:
- Beginning (5 seconds)
- First quarter
- Midpoint
- Three-quarters
- End (5 seconds before completion)
-
Response: JSON with screenshot metadata including:
id(unique identifier)positiondescriptiontimestampurl(endpoint to retrieve screenshot/api/image?id=<id>)
-
Screenshots are cached for 10 minutes.
GET /api/image?id=<screenshot_id>
- Fetches a previously captured screenshot.
- Response:
image/png - Errors: Missing ID or expired screenshot.
- Base64-encoded URLs: All video URLs must be base64-encoded to prevent issues with URL special characters.
- Time formatting: Converts seconds into
HH:MM:SSformat. - Unique IDs: Generated for screenshot caching using SHA-256 hashing of timestamp, position, and randomness.
-
Periodic Cleanup: Cached screenshots are cleared every 10 minutes to free memory.
-
Dependencies:
elysia– Fast and minimal web frameworkchild_process– For spawning FFmpeg processescrypto– For unique ID generation
-
Video Handling: Fully relies on FFmpeg for screenshot and GIF extraction.
- Ensure the video URL is accessible and properly encoded.
- Verify FFmpeg supports the video format.
- Ensure the video duration is sufficient for requested GIFs or screenshots.
Made by Sohom829