Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video thumbnail

I am working on a site that people can submit the video's link. Then I just embed it. However, I want to get the thumbnail of the videos without saving the videos in my server. So that when I list the vidoes, I can use the thumbnails instead of embedding all videos.

My serve uses PHP. Assume the video is in SWF format.

is there anything in the or tag that I can 'grap' the thumbnail? or in PHP, is there anything that I can remotely get the thumbnail (or a frame ) of the remote video?

any idea?

like image 232
Murvinlai Avatar asked Jun 05 '26 22:06

Murvinlai


1 Answers

You can use 'ffmpeg'. by using PHP to call it.

shell_exec  ("ffmpeg -i \"$FILENAME.flv\" -ss 00:00:04 -f image2 \"$FILENAME.jpg\"");

I am sorry to say that I've not test it so try it first.

EDIT: Just for fun, I make it a function. Here it is:

<?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\".";
 
?>

This function also cache the thumbnail and also ensure that the update thumbnail is recreated if the VDO is modified.

Enjoy

like image 87
NawaMan Avatar answered Jun 08 '26 12:06

NawaMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!