2012-02-01 6 views
5

Je suis nouveau sur php. J'ai installé ffmpeg dans mon iis local. Est-il possible de générer une image miniature pour un fichier flv.? S'il vous plaît aider ..FFMpeg - Créer une vignette pour le fichier vidéo

+0

double possible [lecteur vidéo miniature en PHP] (http://stackoverflow.com/questions/2913172/thumbnail-video-player-in-php) – mario

+0

en double possible de [Générer l'image de prévisualisation du fichier vidéo ?] (http://stackoverflow.com/questions/2043007/generate-preview-image-from-video-file) –

Répondre

11

Essayez cette

$ffmpeg = 'ffmpeg.exe'; 

//video dir 
$video = 'video.flv'; 

//where to save the image 
$image = 'image.jpg'; 

//time to take screenshot at 
$interval = 5; 

//screenshot size 
$size = '320x240'; 

//ffmpeg command 
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";  
$return = `$cmd`; 

Une explication des options de commande:

-i nom (chemin du fichier de la vidéo source)
-interface (convertit la vidéo entrelacée en une forme non entrelacée)
-an (l'enregistrement audio est désactivé; nous ne avons pas besoin pour les vignettes)
-ss Position (entrée vidéo est décodé et vidé jusqu'à ce que l'horodatage atteint la position, notre position de vignettes en quelques secondes)
-f format de fichier de sortie
-t durée (le fichier de sortie cesse d'écrire après durée secondes)
-r fps (définit la fréquence d'image à écrire à; fps est exprimé en Hertz (1/seconde); nous utilisons 1 pour que nous saisissons une seule image)
-y (remplace le fichier de sortie si elle existe déjà)
-s de largeurxhauteur (taille du cadre en pixels)

+1

Indice: Mettez la valeur ** ** après ** - ** pour accélérer considérablement le processus. –

0

Oui. Vous pouvez exécuter ffmpeg à partir de PHP en utilisant le right parameters. En utilisant ffmpeg-php, vous pouvez utiliser $ movie-> getFrame() pour obtenir une image, et $ frame-> toGDImage() pour obtenir GD image.

+0

Comment utiliser $ movie-> getFrame().? – user1006460

3

Le script suivant a été créé en utilisant PHP FFMPEG Library. Vous pouvez saisir les informations vidéo et miniatures à l'aide des fonctions données

<?php 

class PHP_FFMPEG 
{ 

function getVideoInformation($videoPath) 
{ 
$movie = new ffmpeg_movie($videoPath,false); 

$this->videoDuration = $movie->getDuration(); 
$this->frameCount = $movie->getFrameCount(); 
$this->frameRate = $movie->getFrameRate(); 
$this->videoTitle = $movie->getTitle(); 
$this->author = $movie->getAuthor() ; 
$this->copyright = $movie->getCopyright(); 
$this->frameHeight = $movie->getFrameHeight(); 
$this->frameWidth = $movie->getFrameWidth(); 
$this->pixelFormat = $movie->getPixelFormat(); 
$this->bitRate = $movie->getVideoBitRate(); 
$this->videoCodec = $movie->getVideoCodec(); 
$this->audioCodec = $movie->getAudioCodec(); 
$this->hasAudio = $movie->hasAudio(); 
$this->audSampleRate = $movie->getAudioSampleRate(); 
$this->audBitRate = $movie->getAudioBitRate(); 


} 


function getAudioInformation($videoPath) 
{ 
$movie = new ffmpeg_movie($videoPath,false); 

$this->audioDuration = $movie->getDuration(); 
$this->frameCount = $movie->getFrameCount(); 
$this->frameRate = $movie->getFrameRate(); 
$this->audioTitle = $movie->getTitle(); 
$this->author = $movie->getAuthor() ; 
$this->copyright = $movie->getCopyright(); 
$this->artist = $movie->getArtist(); 
$this->track = $movie->getTrackNumber(); 
$this->bitRate = $movie->getBitRate(); 
$this->audioChannels = $movie->getAudioChannels(); 
$this->audioCodec = $movie->getAudioCodec(); 
$this->audSampleRate = $movie->getAudioSampleRate(); 
$this->audBitRate = $movie->getAudioBitRate(); 

} 

function getThumbImage($videoPath) 
{ 
$movie = new ffmpeg_movie($videoPath,false); 
$this->videoDuration = $movie->getDuration(); 
$this->frameCount = $movie->getFrameCount(); 
$this->frameRate = $movie->getFrameRate(); 
$this->videoTitle = $movie->getTitle(); 
$this->author = $movie->getAuthor() ; 
$this->copyright = $movie->getCopyright(); 
$this->frameHeight = $movie->getFrameHeight(); 
$this->frameWidth = $movie->getFrameWidth(); 

$capPos = ceil($this->frameCount/4); 

if($this->frameWidth>120) 
{ 
$cropWidth = ceil(($this->frameWidth-120)/2); 
} 
else 
{ 
$cropWidth =0; 
} 
if($this->frameHeight>90) 
{ 
$cropHeight = ceil(($this->frameHeight-90)/2); 
} 
else 
{ 
$cropHeight = 0; 
} 
if($cropWidth%2!=0) 
{ 
$cropWidth = $cropWidth-1; 
} 
if($cropHeight%2!=0) 
{ 
$cropHeight = $cropHeight-1; 
} 

$frameObject = $movie->getFrame($capPos); 


if($frameObject) 
{ 
$imageName = "tmb_vid_"1212.jpg"; 
$tmbPath = "/home/home_Dir/public_html/uploads/thumb/".$imageName; 
$frameObject->resize(120,90,0,0,0,0); 
imagejpeg($frameObject->toGDImage(),$tmbPath); 
} 
else 
{ 
$imageName=""; 
} 


return $imageName; 

} 






} 




?> 

Fonction

getThumbImage($videoPath); //pass path to video file // 

va créer nombre de vignettes dans le dossier spécifié dans la fonction. Vous pouvez modifier le code en fonction de vos besoins. Cela fonctionne si vous avez installé la bibliothèque ffmpeg et php ffmpeg.

Référez ce lien http://tecserver.blogspot.in/2009/07/ffmpeg-video-conversion-tool.html

1
<?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

ce code n'est pas compelete. vous devriez ajouter $ mov = new ffmpeg_movie ('./ Wildlife.wmv'); au lieu de "$ mov = new ffmpeg_movie ($ pic, false);" cela signifie que vous utilisez "Wildlife.wmv" exactement sur votre racine drectory près du fichier .php. et aussi vous devriez changer "imageGif ($ new, $ name, 100);" à "imageGif ($ new," yourname.gif ", 100);" il va créer un fichier nommé "yourname.gif" près de votre fichier php. espérons aider quelqu'un –

0

Il n'est pas nécessaire de spécifier un temps de 1. L'API ffmpeg fournit un format de image2 et la possibilité de passer des -vframes 1.

$time = 3; 
$infile = 'in.mp4'; 
$thumbnail = 'my_thumbnail.png'; 

$cmd = sprintf(
    'ffmpeg -i %s -ss %s -f image2 -vframes 1 %s', 
    $infile, $time, $thumbnail 
); 

exec($cmd); 
Questions connexes