0

I need to get middle of video frame depend on video duration.

I set the $frame = $mov->getFrame(480); it's get only when the 480 frame. I need to set middle of the frame image. Here is code:

    <?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);
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
rdxhere
  • 11
  • 3
  • What do you mean by "middle" - do you mean the image at 30 seconds in a one minute clip? Or a specific rectangular section from the first frame? – halfer Jul 20 '14 at 08:33
  • yes on one minute video can take the frame 30 second – rdxhere Jul 20 '14 at 13:22
  • Simple logic first you need to get the total duration of the video and multiply it by 0.5 now you get the half total of duration. Set your frame to the new total duration. – Grald Aug 21 '15 at 12:07

0 Answers0