【发布时间】:2017-08-19 13:02:06
【问题描述】:
这是我的问题:在我的网站上,我希望允许用户上传任何类型的视频。但是对于 HTML5 标签,只能使用 .mp4 视频。 所以我想将用户提交的任何类型的视频转换为 MP4,然后将路径添加到数据库。
我读过一些关于 FFmpeg 的文章,但我不知道如何使用它。我尝试使用 shell_exec("ffmpeg -i ".$vid." -vcodec libx264 -crf 20 out.mp4 2>&1") 没有成功。
html
<form method="post" enctype="multipart/form-data" name="form" action="post.php">
<input type="file" name="media-vid" class=" file_multi_video" accept="video/*">
</form>
php 脚本:
if(file_exists($_FILES['media-vid']['tmp_name']) && is_uploaded_file($_FILES['media-vid']['tmp_name']))
{
$targetvid = md5(time());
$target_dirvid = "videos/";
$target_filevid = $targetvid.basename($_FILES["media-vid"]["name"]);
$uploadOk = 1;
$videotype = pathinfo($target_filevid,PATHINFO_EXTENSION);
if ($_FILES["media-vid"]["size"] > 500000000) {
$uploadOk = 0;
echo "Sorry, your file is too large.";
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your video was not uploaded.";
// if everything is ok, try to upload file
} else {
$target_filevid = strtr($target_filevid,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$target_filevid = preg_replace('/([^.a-z0-9]+)/i', '_', $target_filevid);
if (!move_uploaded_file($_FILES["media-vid"]["tmp_name"], $target_dirvid. $target_filevid)) {
echo "Sorry, there was an error uploading your file. Please retry.";
}else{
$vid= $target_dirvid.$target_filevid;
shell_exec("ffmpeg -i ".$vid." -vcodec libx264 -crf 20 out.mp4 2>&1");
}
}
}
【问题讨论】:
-
我们无法查看
shell_exec的结果。试试看怎么样? -
它实际上什么也没做。我使用正确吗?
-
再次:打印函数结果。
-
我该怎么做?
标签: javascript php html