Drupal php FFMPEG thumbnail extraction from a video

https://trac.ffmpeg.org/wiki/PHP
<?php
echo "Starting ffmpeg...\n\n";
echo shell_exec("ffmpeg -i input.avi output.avi &");
echo "Done.\n";
?>

<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);

$node = node_load($nid);
$field_name = 'field_video';
$invoked_video = field_get_items('node', $node, $field_name);

if ($format = 'url') {
$video_url = file_create_url($invoked_video[0]['uri']);

} else {
$video_url = $invoked_video[0][$format];
}

$ffmpeg = "/usr/bin/ffmpeg";
$thumbpath = "PALS/videos/thumbnail/" . $nid . "_thumb.jpg";

shell_exec($ffmpeg . " -i " . $video_url . " -ss 00:00:" . rand(13, 26) . "." . rand(111, 860). " -s 320x240 -vframes 1 " . $thumbpath);

return $thumbpath;
}

?>

Tags: