2011-02-09 133 views
1

想知道如何執行ffmpeg命令以在此代碼中執行屏幕截圖。我無法弄清截圖是在什麼時候創建,通過哪個函數或通過哪一行完成的。如何在此代碼中執行ffmpeg命令

$ffmpeg = '/usr/bin/ffmpeg'; 
     $video = $sourceUrl;// the input video file 
     $thumbId = uniqid(); 
     $thumbId .= ".jpg"; 
     // where you'll save the image 
     $image = "uploads/$thumbId"; 
     // default time to get the image 
     $second = 1; 
     // get the duration and a random place within that 
     $cmd = "$ffmpeg -i $video 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)); 
     } 

     // get the screenshot 
     $cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -s 120x90 -vcodec mjpeg -f mjpeg $image 2>&1"; 
     $return = `$cmd`; 
     $thumbLink = ""; 
+0

@丹感謝編輯想要寫出適當的拼寫。 – XMen 2011-02-09 07:11:17

回答

3

此行執行您存儲在變量$cmd命令:

$return = `$cmd`; 

在PHP中,倒引號是execution operator,它的使用是相同的主叫shell_exec

+0

謝謝。學到了東西:) – DhruvPathak 2011-02-09 07:37:50