1
<?php
error_reporting(1);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
$conn = new mysqli($servername, $username, $password, $dbname);
$target_dir = "test_upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if(isset($_POST["upd"]))
    {
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
        if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg")
        {
            echo "File Format Not Suppoted";
        } 
        else
        {
            $video_path=$_FILES['fileToUpload']['name'];
            move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
            $sql = "INSERT INTO video (video_name) VALUES ('$video_path')";
            $result = $conn->query($sql);
            echo "uploaded ";
        }
    }
if(isset($_POST["disp"]))
{
    $sql = "select * from video";
    $result = $conn->query($sql);
    while($row=mysqli_fetch_array($result,MYSQLI_NUM))
    { ?>
        <video width="300" height="200" controls>
        <source src="test_upload/<?php echo $row[1]; ?>" type="video/mp4">
        </video> 
        <?php 
    } 
} ?>


<html>
<body>
    <form method="post" enctype="multipart/form-data">
        <table border="1">
            <tr>
                <td>
                    Upload  Video
                </td>
            </tr>
            <tr>
                <td>
                    <input type="file" name="fileToUpload"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Uplaod Video" name="upd"/>
                    <input type="submit" value="Display Video" name="disp"/>
                </td>
            </tr>
        </table>
    </form> 
</body>

I am trying to upload the video file to server which supports ffmpeg , for small size videos like 4 to 5 mb it works fine , but when i am trying to upload the video more than 15mb, it takes too much time for upload.How to compress the size of the video file with out losing the quality while uploading to server using php?

Umashankar B
  • 415
  • 8
  • 21
  • Have you searched up on how to compress the file using FFMPeg? As far as I know, I know FFMPeg allows you to do that too. Link 1: https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg, Link 2: https://gist.github.com/lukehedger/277d136f68b028e22bed Link 3: https://stackoverflow.com/questions/4490154/reducing-video-size-with-same-format-and-reducing-frame-size – JeanPaul98 Jan 05 '19 at 14:33

1 Answers1

1

you can’t. Php is excicuited on the server, not the client. It would need to be compressed before it is sent, otherwise it would take the exact same bandwidth.

szatmary
  • 29,969
  • 8
  • 44
  • 57