我正在尝试在上传时对视频进行编码,但无法按照我的意愿进行操作。这是我的上传代码。
if(isset($_FILES['video_profile'])){
$errors= array();
$file_name = $_FILES['video_profile']['name'];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$newName = time();
$file_size =$_FILES['video_profile']['size'];
$file_tmp =$_FILES['video_profile']['tmp_name'];
$file_type =$_FILES['video_profile']['type'];
$file_ext =strtolower(end(explode('.',$_FILES['video_profile']['name'])));
$expensions = array("webm","mp4", "avi", "mov", "flv", "swf", "mpg", "mpeg", "mpeg-4", "wmv");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 524288000){ // 2097152 //
$errors[]='File size must be smaller than 500 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"upload_data/site_video/".$newName.'_video.'.$ext);
//var_dump($file_tmp,"upload_data/site_video/".$newName.'_video.'.$ext);
echo "<p class=\"success\">You have successfully uploaded video</p>";
Db::query('INSERT INTO site_video SET table_name = "profile_video", user_id = '.$_SESSION['user']['id'].', video_name = "'.$newName.'_video.'.$ext.'" ');
$orderby = Db::insert_id();
Db::query('UPDATE site_video SET orderby = '.$orderby.' WHERE id = '.$orderby);
}
else{
//print_r($errors);
}
}
我正在搜索并发现我需要将此代码放在某处,但不知道在哪里以及如何
exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv");
有人可以给我一些暗示!谢谢
答案 0 :(得分:1)
目前还不清楚,您的代码目标是什么。 我读了以下内容:
你可以试试这个:
if (move_uploaded_file($file_tmp,"upload_data/site_video/".$newName.'_video.'.$ext)) {
exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv");
echo "<p class=\"success\">You have successfully uploaded video</p>";
Db::query('INSERT INTO site_video SET table_name = "profile_video", user_id = '.$_SESSION['user']['id'].', video_name = "'.$newName.'_video.'.$ext.'" ');
$orderby = Db::insert_id();
Db::query('UPDATE site_video SET orderby = '.$orderby.' WHERE id = '.$orderby);
}
但要小心。目前,您正在将错误的扩展名保存到数据库中(avi而不是flv)。你应该在你的exec命令中使用绝对路径。
回答ffmmpeg-Command应该是什么样子很难,因为这可能是非常动态的,取决于源。 https://www.ffmpeg.org/documentation.html可以为您提供更多帮助。