2016-11-17 136 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