压缩视频和上传到PHP

时间:2016-11-17 16:45:49

标签: php video

您好已经成功构建了一个允许用户上传视频的Web应用程序,但我尝试在上传之前压缩视频以节省带宽。请问我该怎么做?例如,在图片压缩中,它是GD库,但在Youtube上的视频搜索和堆栈溢出,没有人回答我的问题这些是我的代码。注意:这些代码完美无缺,但我试图在上传之前压缩视频。提前谢谢..

我看了这篇文章Server-side video conversion and compression并不是我真正想要的,因为我从未真正使用过ffmpeg

               <?php include "connect.php"; ?>

 <?php 
if ((isset($_POST['videoname'])) && (isset($_POST['aboutvideo'])) && (isset($_POST['timestart'])) && (isset($_POST['timestop'])) && (isset($_POST['streamersid']))){

$videoname=$_POST['videoname']; 
$aboutvideo=$_POST['aboutvideo'];
$timestart=$_POST['timestart'];
$timestop=$_POST['timestop'];
$streamersid=$_POST['streamersid'];
$streamerstype=$_POST['streamerstype'];
$streamersname=$_POST['streamersname'];
$date=$_POST['date'];

 $fileName = $_FILES["file1"]["name"]; //file name
 $fileTmpLoc = $_FILES["file1"]["tmp_name"]; //file in the php tmp folder
 $fileType = $_FILES["file1"]["type"];   //the type of file it is
 $fileSize = $_FILES["file1"]["size"]; //File size in bytes
 $fileErrorMsg = $_FILES["file1"]["error"];  //0 for false and 1 for true

$tex = pathinfo($fileName, PATHINFO_EXTENSION); //get video extension

if($tex=='mp4' || $tex=='avi' ||
$tex=='webm' || $tex=='flv' ||
$tex=='MP4' || $tex=='3gp')
{

$rand = substr(md5(microtime()),rand(0, 26) , 26);

@$filez = $rand.$_FILES['file1']['name'];


$videoname= mysqli_real_escape_string($con, $videoname);
$aboutvideo= mysqli_real_escape_string($con, $aboutvideo);
$timestart = mysqli_real_escape_string($con, $timestart);
$timestop = mysqli_real_escape_string($con, $timestop);


//compression script from here video would be compressed before path being being saved to database and moved to folder

if(move_uploaded_file($fileTmpLoc, "plays/$filez")){    
$insert="INSERT INTO `plays`(`streamers_id`, `file1`, `video_name`, `about_video`, `streamers_type`, `time_start`, `time_stop`, `date`, `streamers_name`) VALUES ('$streamersid','$filez','$videoname','$aboutvideo','$streamerstype','$timestart','$timestop','$date','$streamersname')";
$run=mysqli_query($con, $insert);
echo "Upload complete ";
} else {
     echo "Upload Failed";
}

} else {
echo "Invalid video";   
}   
}
?>

1 个答案:

答案 0 :(得分:3)

您希望在上传之前压缩,然后必须使用客户端上运行的代码完成。您的PHP在服务器上运行。因此,您必须编写某种用户可以下载的可以压缩和上传的应用程序。