This Docker container hosts a Flask-based API service for generating video previews in WebP format. The service takes in a video URL or file, preview length, width, and height, and returns a thumbnail image in WebP format. The container also supports port mappings to integrate with platforms like Plesk.
To build the Docker image and push it to Docker Hub:
docker build -t d9media/webp_video_previews:latest .
docker login
docker push d9media/webp_video_previews:latest
Run the container, mapping the desired port:
docker run -p 3003:3003 -e FLASK_PORT=3003 d9media/webp_video_previews:latest
Endpoint: /generate-preview
Method: POST
Parameters:
video_url (string): URL of the video file to previewlength (integer): Length of the preview in secondswidth (integer): Width of the preview thumbnailheight (integer): Height of the preview thumbnailResponse: Returns a WebP image file of the specified preview.
Below is a PHP example showing how to call the /generate-preview endpoint.
<?php
$apiUrl = 'http://localhost:3003/generate-preview';
$videoUrl = 'https://example.com/video.mp4';
$length = 5; // Preview length in seconds
$width = 320; // Preview width
$height = 180; // Preview height
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'video_url' => $videoUrl,
'length' => $length,
'width' => $width,
'height' => $height
]);
// Execute and fetch response
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
echo 'cURL Error: ' . curl_error($ch);
} else {
// Save the WebP thumbnail to a file
file_put_contents('thumbnail.webp', $response);
echo 'Thumbnail saved as thumbnail.webp';
}
// Close cURL session
curl_close($ch);
ffmpeg is installed in the container as it is required for generating video previews.thumbnail.webp in the local directory.Content type
Image
Digest
sha256:2c3405b73…
Size
278.4 MB
Last updated
almost 2 years ago
docker pull d9media/webp_video_previews