Hello have successfully built a web application that allows users upload videos, but i am trying to compress videos before uploading them so as to save bandwidth. Please how do I go about these? e.g, In pictures compression it is GD library but in video searched post on Youtube and stack overflow, none answers my question these is my code. NOTE:these code works perfectly but I am trying to compress the video before upload in php. Thanks in advance..
I looked at this post Server-side video conversion and compression not really what i am looking for because i have never really worked with 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";
}
}
?>