您的問題背後的原因是特定於您的系統,我可以輕鬆地運行您的代碼和生成的.ogg文件。下面是我得到的,當我在它運行你的代碼的PHP文件:
dir2ogg 0.11.8 (2009-08-04), converts audio files into ogg vorbis.
INFO: Converting "/home/mehran/001.mp3" (using mpg123 as decoder)...
正如我在以前001.ogg
表示創建成功。無論您的執行情況如何,都與您的配置有關。調試它的方法是獲取並打印該過程的stderr
。這裏是你如何能得到它(shell_exec
和exec
功能不給你說):
<?php
function _pipeExec($cmd, $input = '')
{
$proc = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
fwrite($pipes[0], $input);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$rtn = proc_close($proc);
$result = array(
'stdout' => $stdout
, 'stderr' => $stderr
, 'return' => $rtn
);
return $result;
}
$command = 'dir2ogg /home/mehran/"001.mp3"';
$output = _pipeExec($command);
print_r($output);
你可以找到proc_open here更多信息。但是簡短的描述是它完全符合你的要求,它給你一個過程產生的所有輸出。在我的電腦上面的代碼生成:
Array
(
[stdout] => dir2ogg 0.11.8 (2009-08-04), converts audio files into ogg vorbis.
INFO: Converting "/home/mehran/001.mp3" (using mpg123 as decoder)...
[stderr] => [wav.c:371] warning: Cannot rewind WAV file. File-format isn't fully conform now.
Encoding standard input to
"/home/mehran/001.ogg"
at quality 3.00
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m00s so far]/
Encoding [ 0m00s so far] -
Encoding [ 0m00s so far] \
Encoding [ 0m00s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m01s so far] \
Encoding [ 0m01s so far] |
Encoding [ 0m01s so far]/
Encoding [ 0m01s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m02s so far]/
Encoding [ 0m02s so far] -
Encoding [ 0m02s so far] \
Encoding [ 0m02s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m03s so far] -
Encoding [ 0m03s so far] \
Encoding [ 0m03s so far] |
Encoding [ 0m03s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m04s so far]/
Encoding [ 0m04s so far] -
Encoding [ 0m04s so far] \
Encoding [ 0m04s so far] |
Encoding [ 0m05s so far]/
Encoding [ 0m05s so far] -
Encoding [ 0m05s so far] \
Encoding [ 0m05s so far] |
Encoding [ 0m05s so far]/[wav.c:371] warning: Cannot rewind WAV file. File-format isn't fully conform now.
Encoding [ 0m05s so far] -
Done encoding file "/home/mehran/001.ogg"
File length: 3m 13.0s
Elapsed time: 0m 05.1s
Rate: 37.8620
Average bitrate: 110.9 kb/s
[return] => 0
)
可以使用return
值來檢查進程的成功,並且你可以看到,即使進度指示器也被打印。不過,您可以查看stderr
並查找代碼中的錯誤。
[更新]
不幸的是,我不能複製你的錯誤。我只是試圖做你正在做的事情,並面臨我自己的問題,我認爲這是值得分享的。這是我的完整,工作代碼上傳和轉換音頻文件:
<?php
function _pipeExec($cmd, $input = '')
{
$proc = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
fwrite($pipes[0], $input);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$rtn = proc_close($proc);
$result = array(
'stdout' => $stdout
, 'stderr' => $stderr
, 'return' => $rtn
);
return $result;
}
?>
<html>
<body>
<form method="post" action="./ogg.php" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="music" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_FILES['music'])) {
$des = $_FILES['music']['tmp_name'] .'.'. pathinfo($_FILES['music']['name'], PATHINFO_EXTENSION);
rename($_FILES['music']['tmp_name'], $des);
$command = 'dir2ogg "' . $des . '"';
$output = _pipeExec($command);
echo "<div style='height: 500px; overflow: auto;'><pre>";
print_r($output);
echo "</pre></div>";
}
?>
</body>
</html>
的一部分,如果你省略將導致一個問題是:
$des = $_FILES['music']['tmp_name'] .'.'. pathinfo($_FILES['music']['name'], PATHINFO_EXTENSION);
rename($_FILES['music']['tmp_name'], $des);
這將重命名臨時上傳文件,以便它將具有與其原始文件名相同的擴展名,即它將追加.mp3
到上傳的文件。沒有這個,我無法將文件轉換爲.ogg
文件。
關於你的錯誤還有一件事,確保你上傳的文件與dir2ogg
兼容,因爲我在這裏和那裏看到一些文章不兼容,因此dir2ogg
輸出類似你的錯誤。
最後,請確保您的文件大小不超過您的上傳大小和/或郵寄大小限制。 A phpinfo()
會提示您當前的upload_max_filesize
和post_max_size
。也許你的文件沒有上傳!您可以通過查看$_FILES['music']['error']
來確保您的文件上傳成功。
就是這些!
以root身份運行PHP時會發生什麼? – Brad
而我更新了我的回答 – Mehran