2012-02-01 10 views
5

के लिए थंबनेल बनाने मैं php के लिए नया हूँ। मैंने अपने स्थानीय आईआईएस में ffmpeg स्थापित किया है .. क्या एक फ्लैव फ़ाइल के लिए थंबनेल छवि उत्पन्न करना संभव है। कृपया मदद ..ffmpeg - वीडियो फ़ाइल

+0

[PHP में थंबनेल वीडियो प्लेयर] (http://stackoverflow.com/questions/2913172/thumbnail-video-player-in-php) की – mario

+0

संभावित डुप्लिकेट के संभावित डुप्लिकेट [वीडियो फ़ाइल से पूर्वावलोकन छवि उत्पन्न ?] (http://stackoverflow.com/questions/2043007/generate-preview-image-from-video-file) –

उत्तर

11

प्रयास करें इस

$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`; 

आदेश विकल्पों में से एक व्याख्या:

मैं फ़ाइल नाम (स्रोत वीडियो के फ़ाइल पथ)
-डिंटरलेस
-एक (ऑडियो रिकॉर्डिंग अक्षम किया गया है (गैर इंटरलेस्ड फार्म के लिए जुड़े हुए वीडियो धर्मान्तरित); हम थंबनेल के लिए इसकी आवश्यकता नहीं है)
-ss स्थिति (इनपुट वीडियो डीकोड और फेंक दिया जब तक टाइमस्टैम्प तक पहुँच जाता है स्थिति, सेकंड में हमारे थंबनेल की स्थिति)
-f आउटपुट फ़ाइल स्वरूप है
आयकर अवधि
-r (आउटपुट फ़ाइल लेखन बंद हो जाता है अवधि सेकंड के बाद) एफपीएस (कम से लिखने के लिए फ्रेम दर सेट; एफपीएस हर्ट्ज (1/सेकंड) में व्यक्त किया है; हम 1 का उपयोग करें ताकि हम केवल एक फ्रेम) हड़पने
-y (अधिलेखित कर देता है आउटपुट फ़ाइल अगर यह पहले से मौजूद है)
-s WIDTHxHEIGHT (पिक्सेल में फ्रेम का आकार)

+1

संकेत: इन्फाइल ** - i ** ** ** एसएस ** के बाद मूल्य को प्रक्रिया को तेज करने के लिए रखें। –

0

हां। आप right parameters का उपयोग करके PHP से ffmpeg चला सकते हैं।

ffmpeg-php का उपयोग करके, आप GD image प्राप्त करने के लिए फ्रेम प्राप्त करने के लिए $ movie-> getFrame() का उपयोग कर सकते हैं, और $ frame-> toGDImage()।

+0

$ मूवी-> getFrame()। का उपयोग कैसे करें? – user1006460

3

के बाद स्क्रिप्ट आईसी पीएचपी FFMPEG पुस्तकालय का उपयोग कर बनाया। आप दिए गए कार्यों

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

} 






} 




?> 

समारोह

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

समारोह में निर्दिष्ट फ़ोल्डर में थंबनेल की संख्या पैदा करेगा का उपयोग कर वीडियो जानकारी और थंबनेल हड़पने कर सकते हैं। आप अपनी आवश्यकता के अनुसार कोड बदल सकते हैं। यह काम करता है अगर आपने ffmpeg और php ffmpeg लाइब्रेरी स्थापित की है।

इस लिंक का संदर्भ लें 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

यह कोड compelete नहीं है। आपको $ mov = new ffmpeg_movie ('./ Wildlife.wmv') जोड़ना चाहिए; "$ mov = new ffmpeg_movie ($ pic, false) के बजाय;" इसका मतलब है कि आप .php फ़ाइल के करीब अपने रूट डैक्टोरी पर "Wildlife.wmv" का उपयोग कर रहे हैं। और आपको "imageGif ($ नया, $ नाम, 100) बदलना चाहिए;" "imageGif ($ नया," yourname.gif ", 100);" यह आपकी php फ़ाइल के करीब "yourname.gif" नाम की एक फ़ाइल तैयार करेगा। आशा किसी की मदद करें –

0

वहाँ 1 का समय निर्दिष्ट करने की आवश्यकता नहीं है। ffmpeg api image2 का प्रारूप प्रदान करता है और -फ्रेम 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);