Server-Side FFMPEG Conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Server-Side FFMPEG Conversion

Post by JustinMs66 »

I have a website i am working on that allows you to upload videos to it.
I use FFMPEG to convert the video to an flv, after upload, so the flash player can play it easily.

However i have a problem. i run a system command for ffmpeg using exec();. and it does work, but the page is loading for however long the conversion takes, as well as if the user closes the page, it will not fully convert.

What i want:
- once the video is uploaded, it sends a request to the server to do the conversion
- the conversion is done server-side and has nothing to do with the client-side (the user can close the browser window)
- code needs to be executed once the conversion is completed

now i have had a very hard time trying to figure this out, especially with the part where code is executed after the conversion is finished.

can anyone give me some ideas please?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What i want:
- once the video is uploaded, it sends a request to the server to do the conversion
I would probably create a cron job that monitors a database for new entries that needs to be converted.
- the conversion is done server-side and has nothing to do with the client-side (the user can close the browser window)
See above
- code needs to be executed once the conversion is completed
Something I'm not understanding here?

Code: Select all

exec(' ... ffmpeg .. ');

echo 'I wont be run until the exec is finished';
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Use ignore_user_abort() and put the process in background.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Send a header('Location:... and redirect away without exiting, the process will continue to run. You will need to check you have max_execution_time ini set appropriately and ignore_user_abort() is, as mentioned, worthy of consideration.
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Post by JustinMs66 »

VladSun wrote:Use ignore_user_abort() and put the process in background.
ok thank you, i implimented it, but it does nothing yet, but how would i go about putting the process in the background? (linux server)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Almost the same posting several days ago:
viewtopic.php?t=76522

There is a link in it ponting to nearly the same question ;)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply