Sign inSign up

d9media/webp_video_previews

By d9media

•Updated almost 2 years ago

Image
0

1.2K

d9media/webp_video_previews repository overview

⁠WebP Video Previews

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.

⁠Getting Started

⁠Prerequisites
  • Docker
  • Docker Hub account
⁠Build and Push to Docker Hub

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

Run the container, mapping the desired port:

docker run -p 3003:3003 -e FLASK_PORT=3003 d9media/webp_video_previews:latest
⁠API Endpoint
  • Endpoint: /generate-preview

  • Method: POST

  • Parameters:

    • video_url (string): URL of the video file to preview
    • length (integer): Length of the preview in seconds
    • width (integer): Width of the preview thumbnail
    • height (integer): Height of the preview thumbnail
  • Response: Returns a WebP image file of the specified preview.

⁠PHP Usage Example

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);
⁠Notes
  • Ensure ffmpeg is installed in the container as it is required for generating video previews.
  • The image will be saved as thumbnail.webp in the local directory.

Tag summary

Content type

Image

Digest

sha256:2c3405b73…

Size

278.4 MB

Last updated

almost 2 years ago

docker pull d9media/webp_video_previews