hno Posted June 25, 2011 Share Posted June 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/ Share on other sites More sharing options...
MadTechie Posted June 25, 2011 Share Posted June 25, 2011 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, Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/#findComment-1234655 Share on other sites More sharing options...
hno Posted June 25, 2011 Author Share Posted June 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/#findComment-1234663 Share on other sites More sharing options...
MadTechie Posted June 25, 2011 Share Posted June 25, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/#findComment-1234728 Share on other sites More sharing options...
hno Posted June 25, 2011 Author Share Posted June 25, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/#findComment-1234762 Share on other sites More sharing options...
MadTechie Posted June 25, 2011 Share Posted June 25, 2011 it was just an example... it should work fine, however what i was trying to show was how you redirect the output, see the "> /dev/null 2>/dev/null &" thats the only part you need to maintain! Quote Link to comment https://forums.phpfreaks.com/topic/240364-how-to-send-background-request/#findComment-1234766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.