简体   繁体   English

检查php exec的输出始终返回空数组

[英]check the output of php exec always returns empty array

I'm converting some movies and want to make sure the conversion went through without errors: 我正在转换一些电影,并希望确保转换顺利进行:

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);

but when checking $output its always empty: 但是当检查$ output时,它总是空的:

Output:array(0) { } 

How do I check to make sure everything went ok? 如何检查以确保一切正常?

You will have much more control using PHP's proc_open function. 使用PHP的proc_open函数将拥有更多的控制权。 It allows you to write/read standard input/output in a very controlled way: 它允许您以非常可控的方式写入/读取标准输入/输出:

$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
}         
exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}

use php's function 使用PHP的功能

system();

instead. 代替。 Rather then just having exit code you'll may compare ffmpeg's output against desired value. 而是只有退​​出代码,您才可以将ffmpeg的输出与所需值进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM