I'm trying to encode video while uploading but not able to do what i want. Here is my code for upload.
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);
}
}
I was searching and found that I need to place this code somewhere but don't know where and how
exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv");
Can someone give me hint! Thank you
It is not really clear, what's your target with the code. I read the following:
You can try this:
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);
}
But be careful. Currently you are saving the wrong extension into your database (avi instead of flv). And you should use absolute paths in your exec-command.
To answer on how the ffmmpeg-Command should look like is hard, because this can be very dynamic and depends on the source. https://www.ffmpeg.org/documentation.html should help you more.