我有一个基本的php脚本,它使用ffmpeg转换avi:
<?php
if (exec("/usr/bin/ffmpeg -i testvideo.avi -sameq -ar 22050 convertvideo.mp4 2> logfile.log")){
echo "Success";
}else{
echo "Error";
}
?>
现在作为对此的扩展,我想使用 php 检查文件是否仍在转换,如果不应该发送电子邮件,谁能建议我如何实现这一目标?
此外,尽管使用了上面的代码并且文件转换成功,但我总是得到的输出是"错误",任何人都可以帮忙吗?
谢谢
以下内容
应该可以工作:
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方法(请参阅示例)。