任何人都解释了为什么 exec(),shell_exec(), system() 在执行 ffmpeg 命令时不能返回任何返回值。
IE:
exec("我是谁", $output = array());
//这里执行成功,$output设置了一个数组值
$output= shell_exec("我是谁");
//这里执行成功,$output设置了一个数组值
system("我是谁", $output = array());
//这里执行成功,$output设置了一个数组值
但
exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"', $output = array());
//here execution is success but $output is not set an array value
$output= shell_exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"');
//here execution is success but $output is not set an array value
system('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"', $output = array());
//here execution is success but $output is not set an array value
我不知道为什么..!?
请任何人帮助我。
最佳答案
这是因为 ffmpeg 不会向标准输出输出任何内容。它的输出被打印到 stderr。
如果您使用的是非 Windows 系统,则可以执行 exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg 2>&1"', $output = array());
或者你可以使用 proc_open()
关于ffmpeg - 在 exec() php 函数上使用 ffmpeg 进行音频转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20491796/