上传到支持ffmpeg的服务器时,如何使用php压缩视频文件的大小?

时间:2019-01-05 14:28:19

标签: php ffmpeg compression

<?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>

我正在尝试将视频文件上传到支持ffmpeg的服务器,对于4到5 mb的小尺寸视频,它可以正常工作,但是当我尝试将视频上传到15 mb以上时,上传时间太长在使用php上传到服务器时,如何压缩视频文件的大小而又不损失质量?

1 个答案:

答案 0 :(得分:1)

您不能。 Php是在服务器上而不是在客户端上。在发送之前,必须先对其进行压缩,否则它将占用完全相同的带宽。