質問
私は、サーバーにアップロードされたFLVファイルを持っています。私は、次の形式でその期間を表示したいと思います「分:秒」。これで缶誰の助け私?
ありがとうございます。
解決
ここではフレームをつかみ、動画から画像を生成するために私のコードがある...
// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
exec($cmd);
// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");
$第二変数は、0と全継続時間との間の乱数です。 第二のexec()が選択されたフレームから画像ファイルを作成することです。
$ imageOutputは、生成された画像への絶対パスの場所です。 例えば:/home/ariawan/image-generated.jpg
他のヒント
FFMPEG PHP拡張すなわちもあります。 apt-get install php5-ffmpeg
し、
$movie = new ffmepg_movie("path/to/movie.flv"); $duration_in_seconds = $movie->getDuration();
これは、以前に私のために働いています。拡張子がメタデータを検索し、アップロードされたファイルは、FLV、などの場合はテストのために良いです。
I'dは依存せず、昔ながらのPHPで書かれた、 getID3 PHP library
のを使用しています。
それだけでなく、あなた秒で.flv
ムービーの継続時間を与えるが、すでにminute:seconds
形式に変換、それを。ここでvでコードサンプルがある1.7.9(getid3
の最新の安定版):ます。
<?php
// getId3 library uses deprecated eregi_* functions
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL ^ E_DEPRECATED);
// just for debugging/sample
header('Content-Type: text/plain');
// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');
// path to your .flv file
$filename = './sample.flv';
$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);
// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds'];
print chr(10);
// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
私は、ビデオの継続時間を取得するためにPHPとffmpegのを使用しています。
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
}
exec($cmd);
ますprint_r()$時間変数を確認します。 ffmpegのは、あなたのマシンにインストールしてください。.. この意志の助けを願っています。
所属していません StackOverflow