Generate preview image from Video file?


Is there a way in PHP given a video file (.mov, .mp4) to generate a thumbnail image preview?

6/22/2015 8:40:23 AM

Accepted Answer

10/14/2013 6:56:05 PM

Firstly install ffmpeg-php project (

And then you can use of this simple code:

$frame = 10;
$movie = 'test.mp4';
$thumbnail = 'thumbnail.png';

$mov = new ffmpeg_movie($movie);
$frame = $mov->getFrame($frame);
if ($frame) {
    $gd_image = $frame->toGDImage();
    if ($gd_image) {
        imagepng($gd_image, $thumbnail);
        echo '<img src="'.$thumbnail.'">';

Description: This project use binary extension .so file, It's very old and last update was for 2008. So, maybe don't works with newer version of FFMpeg or PHP.

Firstly install PHP-FFMpeg project (
(just run for install: composer require php-ffmpeg/php-ffmpeg)

And then you can use of this simple code:

require 'vendor/autoload.php';

$sec = 10;
$movie = 'test.mp4';
$thumbnail = 'thumbnail.png';

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($movie);
$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($sec));
echo '<img src="'.$thumbnail.'">';

Description: It's newer and more modern project and works with latest version of FFMpeg and PHP. Note that it's required to proc_open() PHP function.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow