【问题标题】:Compressing videos and uploading in php压缩视频并在php中上传
【发布时间】:2016-11-17 16:45:48
【问题描述】:

您好已经成功构建了一个允许用户上传视频的网络应用程序,但我正在尝试在上传视频之前压缩视频以节省带宽。请问我该如何处理这些?例如,在图片压缩中它是 GD 库,但在 Youtube 上的视频搜索帖子和堆栈溢出中,没有人回答我的问题,这是我的代码。注意:这些代码完美运行,但我试图在上传 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";   
}   
}
?>

【问题讨论】:

  • 不,这不是我的,我正在寻找一个简单的 sn-p @JeremyHarris
  • 在视频编码方面没有“简单的 sn-p”。如果你想用 PHP 做那种事情,你将不得不亲自动手学习 ffmpeg

标签: php video


【解决方案1】:

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

【讨论】:

  • 您可以将 ffmpeg 包装在一个电子应用程序中,该应用程序将压缩剪辑并上传它们。我已经成功实施了一个类似的项目。您只需要确保在每个发行版中都包含适当编译的二进制文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-04
  • 1970-01-01
  • 2015-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多