how can i let users upload video to mp4 using php code? I've been trying to find a code that converts video to mp4 automatically no mater what type of video format it is this possible?
how to convert any type of video to mp4?
40k views Asked by user3076412 At
3
There are 3 answers
0
On
This should help you run it directly in php file.
$folder = '/path/to/uploads/folder/';
$filename = 'your_video_file.avi';
$newFilename = pathinfo($filename, PATHINFO_FILENAME).'.mp4';
exec('/usr/bin/ffmpeg -y -i '.$folder.$filename.' -c:v libx264 -c:a aac -pix_fmt yuv420p -movflags faststart -hide_banner '.$folder.$newFilename.' 2>&1', $out, $res);
if($res != 0) {
error_log(var_export($out, true));
error_log(var_export($res, true));
throw new \Exception("Error!");
}
If you are trying this at your server/ not using any online tool. You can use FFmpeg for this. Sample code for conversion:
FFmpeg is most widely used tool for this purpose and you can download the same here.