FFMPEG视频缩略图图像Php

时间:2014-07-20 08:27:37

标签: php video ffmpeg ffmpeg-php

我需要视频帧的中间位置取决于视频时长。

我设置$ frame = $ mov-> getFrame(480);它只有在480帧时才能获得。我需要设置帧图像的中间位置。这是代码:

    <?php

$W = intval($_GET['W']);
$H = intval($_GET['H']);
 $pic = ''.htmlspecialchars($_GET['file']).''; 
$name = 'wapadmin/'.str_replace('/','--',$pic).'.gif';
$location = 'http://'.str_replace(array('\\','//'),array('/','/'),$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.$name);

if(file_exists($name)){
header('Location: '.$location, true, 301);
exit;
}

$mov = new ffmpeg_movie($pic, false);
$wn = $mov->GetFrameWidth();
$hn = $mov->GetFrameHeight();


$frame = $mov->getFrame(480);

$gd = $frame->toGDImage();

if(!$W and !$H){
$a = "131*79";
$size = explode('*',$a);
$W = round(intval($size[0])); 
$H = round(intval($size[1])); 
}


$new = imageCreateTrueColor($W, $H);
imageCopyResampled($new, $gd, 0, 0, 0, 0, $W, $H, $wn, $hn);
imageGif($new, $name, 100);

header('Location: '.$location, true, 301);
?>

0 个答案:

没有答案