2009-08-10 20 views

答えて

8

$cmdを実際に実行するには、popen(),proc_open()、またはexec()のいずれかを使用する必要があります。

この機能をお試しください。 ffmpegがアクセス可能であれば、画像を生成するはずです。アクセス可能にするには、linuxの$pathに追加してください。これをWindowsのwindows/system32フォルダにドロップしてください。または、Windowsのコントロールパネルの環境変数に追加します。

 
/** 
* ExtractThumb, extracts a thumbnail from a video 
* 
* This function loads a video and extracts an image from a frame 4 
* seconds into the clip 
* @param $in string the input path to the video being processed 
* @param $out string the path where the output image is saved 
*/ 
function ExtractThumb($in, $out) 
{ 
    $thumb_stdout; 
    $errors; 
    $retval = 0; 

    // Delete the file if it already exists 
    if (file_exists($out)) { unlink($out); } 

    // Use ffmpeg to generate a thumbnail from the movie 
    $cmd = "ffmpeg -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1"; 
    exec($cmd, $thumb_stdout, $retval); 

    // Queue up the error for processing 
    if ($retval != 0) { $errors[] = "FFMPEG thumbnail generation failed"; } 

    if (!empty($thumb_stdout)) 
    { 
     foreach ($thumb_stdout as $line) 
     { 
      echo $line . "
\n"; } } if (!empty($errors)) { foreach ($errors as $error) { echo $error . "
\n"; } } }

$thumb_stdout - 出力はCLIと同じです。これは、ffmpegが何をしているのかを確認したり、動作していないとクラッシュする場所を知るのに便利です。

$errors - CLIがエラーコード(IE、ffmpegがクラッシュした場合)で終了すると、エラーが表示されます。

+0

非常に非常に感謝2 u – webkul

+0

他のいくつかのオプションの中でも 'system()'を使用することができます – cregox

2

PHPプログラムは基本的に/usr/bin/ffmpegを2回呼び出します。最初にコマンドラインで試してみてください!あなたは

echo "<pre>$cmd</pre>" 

正確にあなたのPHPスクリプトがやっているものを見つけるし、コマンドラインでその正確なコマンドを試してみることができます。

最初のコマンドは、これはあなたがecho Sを置く場所です

/usr/bin/ffmpeg -i /var/www/beta/clock.avi 2>&1 

次のようになります。あなたが$cmdを実行したことがないので、それは働いていない

// get the duration and a random place within that 
$cmd = "$ffmpeg -i $video 2>&1"; 
echo "<pre>$cmd</pre>" 

if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) { 
    $total = ($time[2] * 3600) + ($time[3] * 60) + $time[4]; 
    $second = rand(1, ($total - 1)); 
} 

// get the screenshot 
$cmd = "$ffmpeg -i $video -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1"; 
echo "<pre>$cmd</pre>" 
$return = `$cmd`; 
0

まずffmpegの-PHP(http://ffmpeg-php.sourceforge.net/

をインストールしてから、あなたはこの単純なコードを使用することができます:それは本質的に、あなたの特定のPHPのインストールにリンクされているよう

<?php 
$frame = 10; 
$movie = 'test.mp4'; 
$thumbnail = 'thumbnail.png'; 

$mov = new ffmpeg_movie($movie); 
$frame = $mov->getFrame($frame); 
if ($frame) { 
    $gd_image = $frame->toGDImage(); 
    if ($gd_image) { 
     imagepng($gd_image, $thumbnail); 
     imagedestroy($gd_image); 
     echo '<img src="'.$thumbnail.'">'; 
    } 
} 
?> 
関連する問題