Skip to content

Instantly share code, notes, and snippets.

@James1x0
Created January 7, 2014 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save James1x0/8305938 to your computer and use it in GitHub Desktop.
Save James1x0/8305938 to your computer and use it in GitHub Desktop.
Wordpress Thumbnail Generation with ffmpeg-php.
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