2016-11-22 65 views
-2

代碼工作正常,但如果文件名只有一個qoute就像「Britney's video.mp4」一樣無效。在ffmpeg文件名變量中轉義單個qoute php

$ffmpeg = "/usb/bin/local/ffmpeg"; 
$videos = "/videos/*.mp4"; 
$ouput_path = "/videos/thumbnails/"; 


foreach(glob($videos) as $video_file){ 

$lfilename = basename($video_file); 
$filename = basename($video_file, ".mp4"); 
$thumbnail = $ouput_path.$filename.'.jpg'; 
if (!file_exists($filename)) { 
#$thumbnail = str_replace("'", "%27", $thumbnail); 
exec("/usr/local/bin/ffmpeg -i '$video_file' -an -y -f mjpeg -ss 00:00:30 -vframes 1 '$thumbnail'"); 
} 
echo "<a href='$lfilename'>$filename<img src='thumbnails/$filename.jpg' width='350'>"; 
+0

你可以使用http://php.net/manual/en/function.escapeshellarg.php上'$ video_file'和'$ thumbnail'。 – chris85

+0

謝謝,我不知道如何使用它或把它。只是似乎過於複雜.. – DOMDocumentVideoSource

+0

點擊鏈接提供?它解釋了它的作用。 'escapeshellarg()在字符串周圍添加單引號,並引號/轉義任何現有的單引號,允許您將字符串直接傳遞給shell函數,並將其視爲單個安全參數。「#: – chris85

回答

-1

正如評論所說,你可以只包住escapeshellarg()內所有的殼命令字符串,如下圖所示。

<?php 

    foreach(glob($videos) as $video_file){ 
     $lfilename = basename($video_file); 
     $filename = basename($video_file, ".mp4"); 
     $thumbnail = $ouput_path.$filename.'.jpg'; 

     if (!file_exists($filename)) { 
      $cmd   = "/usr/local/bin/ffmpeg -i "; 
      $cmd  .= $video_file . " -an -y -f mjpeg -ss 00:00:30 "; 
      $cmd  .= "-vframes 1 " . $thumbnail; 

      exec(escapeshellarg($cmd)); 
     } 
+1

謝謝,但沒有在這個版本運行。 – DOMDocumentVideoSource

+0

如果我將escapeshellarg移除到exec(($ cmd));它的工作原理,但仍然不能與文件名''如布蘭妮的視頻 – DOMDocumentVideoSource

+0

我使用$ comd =「/ usr/local/bin/ffmpeg -i \」$ video_file \「-y -f mjpeg -ss 00 :00:30 -vframes 1 \「$ thumbnail \」2> &1"; shell_exec($ comd); – DOMDocumentVideoSource

1

我得到它的工作,但沒有使用過於複雜的東西。 感謝所有

$comd = "/usr/local/bin/ffmpeg -i \"$video_file\" -y -f mjpeg -ss 00:00:30 -vframes 1 \"$thumbnail\" 2>&1"; shell_exec($comd); 
shell_exec($comd);