E' necessario disporre nel server (locale o internet) dell'estensione FFMPEG.
Per ulteriori funzionalità è possibile visitare al link che segue la pagina della documentazione delle API: http://ffmpeg-php.sourceforge.net/
Riporto di seguito un esempio di come sia possibile estrarre il primo frame di un video e generare quindi un file JPG da visualizzare, ad esempio, come preview del video stesso:
//Creo una funzione che ha tutti i prametri per estrarre un determinato frame e lo salva:
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
function _createStill($sVideoPath, $nSeconds, $sImgPath)
{
{
$oMovie = new ffmpeg_movie($sVideoPath);
if(is_null($oMovie)){
throw new Exception(
'FFMPEG failed to load the movie file'
);
}
if(is_null($oMovie)){
throw new Exception(
'FFMPEG failed to load the movie file'
);
}
if($nSeconds == 0){
$nSeconds = 1;
}
$nFrameRate = 20; // JW Player uses 20FPS
$nFrameNum = floor($nFrameRate * $nSeconds);
$nSeconds = 1;
}
$nFrameRate = 20; // JW Player uses 20FPS
$nFrameNum = floor($nFrameRate * $nSeconds);
if(!$oFrame = $oMovie->getFrame($nFrameNum)){
throw new Exception(
'Could not get stil frame from movie'
);
}else{
$oImage = $oFrame->toGDImage();
$sImgFile = $sImgPath;
imagejpeg($oImage, $sImgFile);
return $sImgFile;
}
}
throw new Exception(
'Could not get stil frame from movie'
);
}else{
$oImage = $oFrame->toGDImage();
$sImgFile = $sImgPath;
imagejpeg($oImage, $sImgFile);
return $sImgFile;
}
}
Nessun commento:
Posta un commento