我正在转换一些电影,并希望确保转换顺利进行:
exec("ffmpeg -i ".$orgVideoFile." -vcodec libx264 -crf 21 -acodec aac -ac 2 -ab 192000 -strict experimental -vpre hq -vpre veryfast -refs 3 -threads 4 -s 320x240 ".$newVideoFile, $output);
echo "Output:";
var_dump($output);
但是在检查$ output时它总是空的:
Output:array(0) { }
如何检查以确保一切正常?
答案 0 :(得分:4)
使用PHP的proc_open函数可以获得更多控制权。它允许您以非常受控的方式写入/读取标准输入/输出:
$tunnels=array(
0 => array('pipe','r'), // Process std input
1 => array('pipe','w'), // Process std output
2 => array('pipe','w') // Process std error
);
$io=array();
$resource=proc_open("command with parameters...etc",$tunnels,$io);
if(!is_resource($resource)) {
// Throw exception or something...
}
// Write to process standard input and close stream
fwrite($io[0],"Some data...");
fclose($io[0]);
// We are not interested in process standard output.. close it
fclose($io[1]);
// Get process std error
$errors=stream_get_contents($io[2]);
fclose($io[2]);
// Close process reousrce
$result=proc_close($resource);
if($result != 0) {
// There where errors. Grab the error string from $errors
}
答案 1 :(得分:2)
exec('ffmpeg ...', $output, $return);
if ($return != 0) {
// an error occurred
}
答案 2 :(得分:0)
使用php的功能
system();
代替。而不是只有退出代码,你可以将ffmpeg的输出与期望值进行比较。