Reputation: 35
I want to upload a file (Indeed, I already did it using PHP and JQuery) but I want to encode it to MP4 and/or WebM in the process of the upload, such as Youtube does when you upload a video there. Is there a option to be able to do it in the server during the process?
Do I have to encode them first and then upload?
Upvotes: 3
Views: 21762
Reputation: 4421
You can do it at the end of file upload, which is after you moved the file to a specific location (below code)
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
You can use a free and well-known library called FFMPEG which supports a wide range of formats. Please take a look at these two links for example and better explanation:
https://www.phpro.org/tutorials/Video-Conversion-With-FFMPEG.html
https://trac.ffmpeg.org/wiki/Using%20FFmpeg%20from%20PHP%20scripts
Basically, you can call the FFMPEG function from PHP like this
<?php
/*** convert video to flash ***/
exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv");
?>
Upvotes: 3