Jump to content

Recommended Posts

HI,

I'm writing a php script which the users can upload their's videos and then in the next step I use ffmpeg for converting the video to FLV but It takes some times to do so and the user has to wait for the ffmpeg to complete converting.

I need to know if there is any way that after the users have uploaded their video ,a request send to a page which do the converting itself and the user do not have to wait for completion of  converting and all of that processes done in background.

 

If there is anyway which we can do so ,Please share that here.

 

Thank you very much

Link to comment
https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/
Share on other sites

Page 1, Submittion (simple form) page posts to page 2

Page 2, this page will

    A. check if a file was posted and save it to the correct path, and create a session with file details

    B. if no file was posted it check it has a session,

        Now this page can just continue to refresh until the task is complete, (your need to check the ffmpeg log on page load)

To convert without waiting you're need to do something like this

shell_exec('ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4 > /dev/null 2>/dev/null &');

or use pcntl_exec

    C. if no file was posted and session exists redirect to home,

Thanks ;

I changed the code to this for converting the video to FLV

exec("ffmpeg.exe -i uploads/$video_name1 input -acodec aac -ab 128kb -vcodec flv -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X uploads/$video_name.flv > /dev/null 2>/dev/null &");

 

Something I do is this:

First the user upload it's video and it's done by javascript and then the name of the file is inserted into database then I send the name of the uploaded video to the next page which in that page the converting operation is going to be done then I have put a header order under the converting page which send the user to the next page.

 

after I changed my converting line in the second page to that It does not take time to do converting and I immediately header to the next page but There was no converted video in that folder.Is there any problem with the code I have changed ?

 

Thanks

 

 

Remember the code php code will now tell the server to start a process to do the convertion and them continue with the script..

now you need to determine when the process has finished,

 

What i would do is, create a page called processing.. this page has a some php code at the top that check the process, or the log or if the converted file exists, and if it has finished then redirects to finished page, otherwise just have a html or JS reloader (every 10 seconds or so) or have a ajax routine to check the process..

Thanks

Does this code that I have write is true for converting to FLV:

exec("ffmpeg.exe -i uploads/$video_name1 input -acodec aac -ab 128kb -vcodec flv -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -

subcmp 2 -s 320x180 -title X uploads/$video_name.flv > /dev/null 2>/dev/null &");

 

I check it out again but the file has not been converted.Is there anything wrong with the code?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.