PHP code example of stef77dd / videothumbnailsprite

1. Go to this page and download the library: Download stef77dd/videothumbnailsprite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stef77dd / videothumbnailsprite example snippets


use \Stef77dd\Video\ThumbnailSprite\ThumbnailSprite;

$sprite = new ThumbnailSprite();
$ret = $sprite->setSource('path-to-source-video.mp4')
       ->setOutputDirectory('dir-to-store-sprite-and-vtt')
       // filename prefix for image sprite and WebVTT file (defaults to "sprite", resulting in "sprite.jpg" and "sprite.vtt")
       ->setPrefix('sprite') 
       // absolute URL of sprite image or relative to where the WebVTT file is stored
       ->setUrlPrefix('http://example.org/sprites')
       // sampling rate in seconds 
       ->setRate(10) 
       // minimum number of images (will modify sampling rate accordingly if it would result in fewer images than this)
       ->setMinThumbs(20)
       // width of a single thumbnail in px 
       ->setWidth(120) 
       ->generate();
       
// $ret = ['vttFile' => 'path-to-vtt-file', 'sprite' => 'path-to-sprite-file'] 

// default, is set implicitly if not provided
$sprite->setThumbnailer(new Thumbnailer\Ffmpeg());
// change thumbnailer to ffmpegthumbnailer
$sprite->setThumbnailer(new Thumbnailer\FfmpegThumbnailer());

$sprite->setOutputImageDirectory('dir-to-store-images');