私はphpが初めてです。ローカル iis に ffmpeg をインストールしました。flv ファイルのサムネイル画像を生成することはできますか? 助けてください..
5 に答える
これを試して
$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`;
コマンドオプションの説明:
-i filename (ソース ビデオのファイル パス)
-deinterlace (インターレース ビデオを非インターレース形式に変換します)
-an (オーディオ録音は無効です。サムネイルには必要ありません)
-ss位置(入力ビデオはデコードされ、タイムスタンプはpositionに達します。サムネイルの位置は秒単位です)
-f出力ファイル形式
-t duration (出力ファイルは、 duration秒後に書き込みを停止します)
-r fps (書き込むフレーム レートを設定します。fpsはヘルツ (1/秒) で表されます) ); 1 フレームのみを取得するために 1 を使用します)
-y(出力ファイルが既に存在する場合は上書きします)
-s widthxheight (ピクセル単位のフレームのサイズ)
PHP FFMPEG Library を使用して作成された次のスクリプト ic 。指定された関数を使用して、ビデオ情報とサムネイルを取得できます
<?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 に指定する必要はありません。ffmpeg API は、image2 のフォーマットと -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);