Home > Uncategorized > Get a thumbnail of a VDO file.

Get a thumbnail of a VDO file.

September 24th, 2009 nawaman Leave a comment Go to comments

Here is a PHP code on how to get a thumbnail picture of a VDO file.

It basically uses `ffmpeg` which you need it installed. This works with almost every file including flv.


<?php

function GetThumbnailFileName($FileName, $ScreenShortSecond = 10) {
    $VDOLastModifiedDate = filemtime($FileName);
    $Thumbnail_FileName  = sprintf("%s-(%s::%02d).jpg", $FileName, $VDOLastModifiedDate, $ScreenShortSecond);

    if (!file_exists($Thumbnail_FileName)) {
        $FFMPEG_Command = sprintf(
            "ffmpeg -i \"%s\" -y -ss \"00:00:%02d\" -f image2 \"%s\" > /dev/null 2>&1",
            $FileName, 0 + $ScreenShortSecond, $Thumbnail_FileName
        );
        system($FFMPEG_Command);
    }

    if (!file_exists($Thumbnail_FileName))
        return null;

    return $Thumbnail_FileName;
}

$FileName  = "Test.flv";
$Thumbnail = GetThumbnailFileName($FileName);
if ($Thumbnail != null)
     echo "Thumbnail file is: \"$Thumbnail\"\n";
else echo "Fail creating a Thumbnail of \"$FileName\".";

?>

Enjoy coding.

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.