Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-28-2011, 01:33 PM   PM User | #1
iDeep
New to the CF scene

 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iDeep is an unknown quantity at this point
Arrow How to do realtime video conversion using PHP and ffmpeg ?

Hi,

I am using a PHP script which uses ffmpeg to convert flv videos to mp3, now the whole process takes a lot of time and I was thinking if this can be done in such a way that ffmpeg spits out converted mp3 output in real-time to users so they can start downloading files without waiting while the process completed in background.

Any pointers to other possible solutions would greatly help.

Thanks
iDeep is offline   Reply With Quote
Old 04-28-2011, 08:44 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Here's how I would do it.

1. User uploads flv file to your website.
2. A row is inserted into a table called "pending_conversions", or whatever, with a status of "UPLOADED". The filename and user ID is stored in this table as well.
3. As soon as the file is uploaded, throw a message back to your user "your video has been uploaded and is being converted. You will receive an email when it is finished."
3. A separate PHP script which actually performs the conversion gets fired off by CRON, every x minutes.
4. The first thing this script does is check "pending_conversions" for any rows with a status of "UPLOADED". If any are found, they are converted.
5. Prior to doing the lengthy conversion, update the row in the table to change the status to "CONVERTING".
6. When the conversion is done, change the status to "COMPLETE".
7. Send an email to the user notifying them the conversion is done and provide a link to the converted file.

You may also want to write a little widget that uses AJAX to go out every x seconds to check for completed conversions for the logged in user. So if your user is still visiting your website when the conversion completes, he/she can be notified.
__________________
Fumigator is offline   Reply With Quote
Old 04-28-2011, 11:24 PM   PM User | #3
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Originally Posted by iDeep View Post
Hi,

I am using a PHP script which uses ffmpeg to convert flv videos to mp3, now the whole process takes a lot of time and I was thinking if this can be done in such a way that ffmpeg spits out converted mp3 output in real-time to users so they can start downloading files without waiting while the process completed in background.

Any pointers to other possible solutions would greatly help.

Thanks
So, to clarify, you want users to be able to start downloading a MP3 file before the FLV-to-MP3 conversion process completes?

If that is the case, my first question is: Have you tried this? Have you tried to push the MP3 download to the user immediately (or moments) after starting the FLV-to-MP3 conversion process (and after verifying that the new MP3 file exists)?

I really have no idea if this would work, but it would be cool if it did. It wouldn't be that hard to test, but I don't have time to do it now.

And if you aren't able to push the download right away, perhaps you could use some AJAX on a timer to periodically test to see if the new MP3 file is in a state in which it can be downloaded.

Again, exactly what "state" you are testing for and exactly what PHP functions you would use to do this, I'm not really sure.

You should Google for something like this.

This link looks promising.

Sorry I can't be of more help at the moment.
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 06-17-2011, 01:11 PM   PM User | #4
iDeep
New to the CF scene

 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iDeep is an unknown quantity at this point
Hi,

Sorry for abandoning the thread, I am willing to pay for achieving this functionality.

Thanks
iDeep is offline   Reply With Quote
Old 06-17-2011, 03:55 PM   PM User | #5
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
You might want to check out this post: http://www.codingforums.com/showpost...4&postcount=35 in a related thread. The zlib compression thing seems promising -- if it is enabled on YouTube's server.
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 03-26-2012, 08:38 AM   PM User | #6
johnnyS
New to the CF scene

 
Join Date: Mar 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
johnnyS is an unknown quantity at this point
Just to add some info, you cannot achieve this in real time procession or converting it after upload. It is best to run it via cron because the conversion takes time, especially on files that are large. You don't want to reach the maximum execution time of a script and fail the conversion.
johnnyS is offline   Reply With Quote
Old 03-26-2012, 10:32 AM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,495
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Yes it can be done in real time but only if the conversion code allows for it (IE it's not encrypted by zend/ioncube) and at least uses a loop in there somewhere.

Lets say it converts 10Kb at a time in a loop. In that loop you can then print out the 10Kb thats been converted to the browser. If there is a pause all that will happen is the download will not output any data but the client will just wait for it (eg a browser or download manager).

When testing downloads, Flashget is a superior download manager that allows you to see whats going on within the headers.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 PM.


Advertisement
Log in to turn off these ads.