【发布时间】:2013-07-11 13:29:03
【问题描述】:
我拥有网站 www.goploom.com,该网站类似于 youtube,允许用户上传和观看视频。上传的视频会转换为 mp4 格式,以便与我们网站的 html5 视频播放器兼容。我的问题是,虽然 FFmpeg 成功地从上传的视频生成视频缩略图并将图像存储在正确的目录中,但我的代码的视频转换方面不会产生任何输出。我已经调整了几个小时的代码,但我无法解决这个问题,但是,我被告知我可以使用 html、php 和 ffmpeg 执行视频转换。
我的 ffmpeg 路径是正确的,因为缩略图生成完美。
**上传时从上传的视频中收集的信息。
$name = $_FILES['video']['name'];
$title = $_POST['videotitle'];
$type = explode('.', $name);
$type = end($type);
$size = $_FILES['video']['size'];
$random_name = rand();
$tmp = $_FILES['video']['tmp_name'];
if($type != 'mp4' && $type != 'MP4' && $type != 'flv' && $type != 'FLV' && $type != 'mov' && $type != 'MOV'){
$message = "Video Format Not Supported<br>";
} else {
$username_query = mysql_query("SELECT `username` FROM `users` WHERE `user_id` = $session_user_id");
$username = mysql_fetch_assoc($username_query);
$username = $username['username'];
**完美运行的缩略图生成。
$ffmpeg = "/usr/local/bin/ffmpeg";
$videoFile = $_FILES['video']['tmp_name'];
$imageFile = "上传/".$username."/thumbnails/".$random_name.".jpg";
$size = "160x90";
$getFromSecond = 5;
$cmd = "$ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile";
如果(!shell_exec($cmd)){
echo "缩略图已创建!
";
} 别的 {
echo "创建缩略图时出错!";
}
**将上传的文件移动到其永久目录以进行视频转换。 $newFileLocation = "上传/".$username."/temp".$random_name.".".$type; move_uploaded_file($tmp, $newFileLocation);
*视频转换代码。
$outputFile = "上传/".$username."/".$random_name.".mp4";
$databaseStoredVideoUrl = "上传/".$username."/".$random_name.".mp4";
$video_cmd = "$ffmpeg -i $newFileLocation $outputFile";
回声 $video_cmd;
如果(!shell_exec($video_cmd)){
echo "视频转换!
";
} 别的 {
echo "创建缩略图时出错!";
}
**正确的将输出的src链接存入数据库,但是视频因为不存在而无法查看。
// 视频存储到数据库中正确的用户名和用户目录下
mysql_query("INSERT INTO videos VALUES('$session_user_id','', '$name', '$outputFile', '$title', '', '$imageFile')");
$message = "视频上传成功。
";
任何帮助或见解都会很棒。 谢谢。
**EDIT:通过使用以下行修复。 $video_cmd = "$ffmpeg -i $newFileLocation -vcodec libx264 -vpre normal -acodec libfaac $outputFile";
然后将 $video_cmd 输入到 shell_exec 中
【问题讨论】:
标签: ffmpeg