Domanda

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?

È stato utile?

Soluzione

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");

?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top