2016-11-17 658 views
0

您好已经成功构建了一个Web应用程序,允许用户上传视频,但我试图在上传视频之前压缩视频以节省带宽。请如何处理这些问题?例如,在图片压缩它是GD库,但在Youtube和堆栈溢出视频搜索后,没有回答我的问题,这些是我的代码。注意:这些代码完美工作,但我试图压缩视频上传前在PHP中。在此先感谢..在php中压缩视频并上传

我看了这个帖子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"; 
} 
} 
?> 
+2

可能重复的[服务器端视频转换和压缩](http://stackoverflow.com/questions/26591690/server-side-video-convertion-and-compression) –

+0

不,它不是我的是一个简单的片段我正在寻找@JeremyHarris – chiefo

+1

当谈到视频编码时,没有“简单的片段”。如果你想用PHP做这样的事情,你将不得不弄脏你的手,并学习ffmpeg –

回答

1

您正在寻找压缩的文件再上传,那么它必须做使用在客户端上运行的代码。你的PHP在服务器上运行。因此,你必须编写一些用户可以下载的应用程序,以便压缩和上传。

+0

你可以将ffmpeg包装在一个电子应用程序中,该应用程序将压缩剪辑并上传它们。我已经成功实施了一个类似的项目。您只需确保在每个发行版中包含适当编译的二进制文件。 – UltrasoundJelly