Welcome folks today in this post we will be talking about how to compress video bitrate and resolution in php using ffmpeg library. All the source code is given below. A step by step youtube video is given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<link rel="stylesheet" type="text/css" href="bootstrap-darkly.min.css"> <div class="container" style="margin-top: 200px;"> <div class="row"> <div class="col-md-4 offset-md-4"> <h1>Change bitrate</h1> <form method="POST" enctype="multipart/form-data" action="change-bitrate.php"> <div class="form-group"> <label>Select video</label> <input type="file" name="video" class="form-control" required="" accept="video/*"> </div> <div class="form-group"> <label>Select bitrate</label> <select name="bitrate" class="form-control"> <option value="350k">240p</option> <option value="700k">360p</option> <option value="1200k">480p</option> <option value="2500k">720p</option> <option value="5000k">1080p</option> </select> </div> <input type="submit" name="change_bitrate" class="btn btn-info" value="Change bitrate"> </form> </div> </div> </div> |
1 2 3 4 5 6 7 8 9 |
<?php $video = $_FILES["video"]["tmp_name"]; $bitrate = $_POST["bitrate"]; $command = "/usr/local/bin/ffmpeg -i $video -b:v $bitrate -bufsize $bitrate output.mp4"; system($command); echo "File has been converted"; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<div class="container" style="margin-top: 50px; margin-bottom: 100px;"> <div class="row"> <div class="col-md-4 offset-md-4"> <h1>Change resolution</h1> <form method="POST" enctype="multipart/form-data" action="change-resolution.php"> <div class="form-group"> <label>Select video</label> <input type="file" name="video" class="form-control" required=""> </div> <div class="form-group"> <label>Select resolution</label> <input type="text" name="resolution" class="form-control" placeholder="640x480"> </div> <input type="submit" name="change_resolution" class="btn btn-info" value="Change resolution"> </form> </div> </div> </div> |
1 2 3 4 5 6 7 8 9 |
<?php $video = $_FILES["video"]["tmp_name"]; $resolution = $_POST["resolution"]; $command = "/usr/local/bin/ffmpeg -i $video -s $resolution output2.mp4"; system($command); echo "File has been converted"; |