1

我有一个使用 ffmpeg 转换 avi 的基本 php 脚本:

<?php
if (exec("/usr/bin/ffmpeg -i testvideo.avi -sameq -ar 22050 convertvideo.mp4 2> logfile.log")){ 
echo "Success";
}else{ 
    echo "Error"; 
}
?>

现在作为对此的扩展,我想使用 php 检查文件是否仍在转换,如果不应该发送电子邮件,谁能告诉我如何实现这一点?

此外,尽管使用了上面的代码并且文件被成功转换,我总是得到的输出是“错误”,任何人都可以帮助解决这个问题吗?

谢谢

4

1 回答 1

2

以下应该有效:

exec("/usr/bin/ffmpeg -i testvideo.avi -sameq -ar 22050 convertvideo.mp4 2> logfile.log", $ret, $val);

if ($val != 0) {        
    // Video conversion fail for some reason
    $msg = "Error converting video: $ret" . "\n";
    echo ($msg);

    // send the email
    mail("no@body.com", "Error convering video", $msg);
}

如果要为 ffmpeg 进程设置超时,请考虑使用proc_open方式(参见示例)。

于 2012-06-14T06:23:54.013 回答