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

发布于 2024-12-12 15:13:53 字数 376 浏览 3 评论 0原文

我正在转换一些电影并希望确保转换顺利进行:

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) { } 

如何检查以确保一切正常?

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:array(0) { } 

How do I check to make sure everything went ok?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深者入戏 2024-12-19 15:13:53

使用 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
}         

You will have much more control using PHP's proc_open function. 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
}         
绅刃 2024-12-19 15:13:53
exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}
exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}
肥爪爪 2024-12-19 15:13:53

使用php的函数

system();

来代替。您可以将 ffmpeg 的输出与所需值进行比较,而不仅仅是退出代码。

use php's function

system();

instead. Rather then just having exit code you'll may compare ffmpeg's output against desired value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文