Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,835
    Thanks
    21
    Thanked 157 Times in 148 Posts
    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.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #4
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

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

    Thanks

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,835
    Thanks
    21
    Thanked 157 Times in 148 Posts
    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.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #6
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,432
    Thanks
    62
    Thanked 536 Times in 523 Posts
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •