how to convert any type of video to mp4?
Asked Answered
D

3

5

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?

Doublestop answered 14/12, 2013 at 6:23 Comment(1)
I would like to have the code in the website when someone uploads a video it will automatically convert it to mp4.Doublestop
I
13

If you are trying this at your server/ not using any online tool. You can use FFmpeg for this. Sample code for conversion:

ffmpeg -i {input}.mov -vcodec h264 -acodec aac -strict -2 {output}.mp4

FFmpeg is most widely used tool for this purpose and you can download the same here.

Ifc answered 14/12, 2013 at 6:27 Comment(1)
in addition to run it in a php script just type something like shell_exec('code above');Haughay
U
0
//This code convert video to mp4 format.
//for that you have to install HandBrakeCLI on your linux server
system("HandBrakeCLI -i ".$currfileName." -o ".$new_convertedvideo.".mp4 -v -m -E aac,ac3 -e x264");
Urticaceous answered 14/12, 2013 at 6:27 Comment(0)
C
0

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!");
}
Crown answered 3/11, 2023 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.