Created
January 7, 2014 20:03
-
-
Save James1x0/8305938 to your computer and use it in GitHub Desktop.
Wordpress Thumbnail Generation with ffmpeg-php.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ExtractThumb($in, $out) { | |
$thumb_stdout; | |
$errors; | |
$retval = 0; | |
// Delete the file if it already exists | |
if (file_exists($out)) { unlink($out); } | |
// Use ffmpeg to generate a thumbnail from the movie | |
$cmd = "ffmpeg -i $in -ss 00:00:01 -f image2 -vframes 1 -s 300x200 $out"; | |
exec($cmd, $thumb_stdout, $retval); | |
// Queue up the error for processing | |
if ($retval != 0) { $errors[] = "FFMPEG thumbnail generation failed"; } | |
if (!empty($thumb_stdout)) { | |
foreach ($thumb_stdout as $line) { | |
echo $line . "\n"; | |
} | |
} | |
if (!empty($errors)) { | |
foreach ($errors as $error) { | |
echo $error . "\n"; | |
} | |
echo $out . "\n"; | |
echo $in . "\n"; | |
} else { | |
echo "Thumbnail Generated Successfully <br />"; | |
} | |
} | |
//ffmpeg vars | |
$upload_dir = wp_upload_dir(); | |
$video = $url; //Video url | |
$thumbnail = $upload_dir['basedir'] . "/THUMBNAIL_DIR_HERE/" . $urlkey . ".png"; | |
//ffmpeg execution here | |
ExtractThumb($video, $thumbnail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment