这是主要的index.php文件,我运行我的代码生成一个视频缩略图与ffmpeg,但它没有运气,我一直在网上搜索很多解决方案,但没有出来,我会非常感激,如果你们能帮助我出来。shell_exec()一直给我错误
<html>
<head>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><input type="submit" name="submit" value="upload">
</form>
<?php
if(isset($_POST['submit'])){
$ffmpeg = "/Users/mac/Documents/ffmpeg/3.1.4/bin/ffmpeg";
$videoFile = $_FILES["file"]["tmp_name"];
$imageFile = "1.jpg";
$size = "320x240";
$getFromSecond = 5;
$cmd = "$ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile 2>&1";
echo shell_exec($cmd);
echo shell_exec('whoami');
if(!shell_exec($cmd)){
echo "thumbnail created";
}else{
echo "error creating thumbnail";
}
}
?>
</body>
</html>
试图运行该文件的用户没有正确的权限(通常是www-data
)。要测试这个理论,请尝试运行sudo
:
shell_exec('sudo -u user -p pass -s $ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile 2>&1');
您还可以配置Apache以不同于www-data
的用户运行虚拟主机,或者更改您希望www-data
访问的文件的权限:
您的www-data可能没有权限运行ffmpeg。
对于ubuntu 22.10,编辑权限运行ffmpeg无需密码,
vim /etc/sudoers.d
添加一行,
www-data ALL=(ALL) NOPASSWD: /usr/bin/ffmpeg
然后将ffmpeg命令更改为
"sudo -u root/full/path/to/ffmpeg -i xyz... ...2祝辞,1"
2>&1显示执行时出现的错误。