Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 306717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:29:34+00:00 2026-05-12T07:29:34+00:00

I am wanting to use ffmpeg to convert video to .flv in php. Currently

  • 0

I am wanting to use ffmpeg to convert video to .flv in php. Currently I have this working, but it hangs the browser until the file is uploaded and is finished. I have been looking at the php docs on how to run an exec() process in the background, while updating the process using the returned PID. Here is what I found:

//Run linux command in background and return the PID created by the OS
function run_in_background($Command, $Priority = 0)
{
    if($Priority)
        $PID = shell_exec("nohup nice -n $Priority $Command > /dev/null & echo $!");
    else
        $PID = shell_exec("nohup $Command > /dev/null & echo $!");
    return($PID);
}

There is also a trick which I use to track if the background task is running using the returned PID :

//Verifies if a process is running in linux
function is_process_running($PID)
{
    exec("ps $PID", $ProcessState);
    return(count($ProcessState) >= 2);
}

Am I suppose to create a separate .php file which then runs from the php cli to execute one of these functions? I just need a little nudge in getting this working and then I can take it from there.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:29:34+00:00Added an answer on May 12, 2026 at 7:29 am

    Am I suppose to create a separate .php
    file which then runs from the php cli
    to execute one of these functions?

    This is probably the way I would do it :

    • the PHP webpage adds a record in database to indicate “this file has to be processed”
      • and displays a message to the user ; something like “your file will be processed soon”
    • In CLI, have a batch process the new inserted files
      • first, mark a record as “processing”
      • do the ffmpeg thing
      • mark the file as “processed”
    • And, on the webpage, you can show to the user in which state his file is :
      • if it has not been processed yet
      • if it’s being processed
      • or if it’s been processed — you can then give him the link to the new video file.

    Here’s a couple of other thoughts :

    • The day your application becomes bigger, you can have :
      • one “web server”
      • many “processing servers” ; in your application, it’s the ffmpeg thing that will require lots of CPU, not serving web pages ; so, being able to scale that part is nice (that’s another to “lock” files, indicating them as “processing” in DB : that way, you will not have several processing servers trying to process the same file)
    • You only use PHP from the web server to generate web pages, which is je job of a web server
      • Heavy / long processing is not the job of a web server !
      • The day you’ll want to switch to something else than PHP for the “processing” part, it’ll be easier.

    Your “processing script” would have to be launch every couple of minutes ; you can use cron for that, if you are on a Linux-like machine.


    Edit : a bit more informations, after seeing the comment

    As the processing part is done from CLI, and not from Apache, you don’t need anykind of “background” manipulations : you can just use shell_exec, which will return the whole ouput of the command to your PHP script when it’s finished doing it’s job.

    For the user watching the web page saying “processing”, it will seem like background processing ; and, in a way, it’ll be, as the processing will be done by another processus (maybe even on another machine).

    But, for you, it’ll be much simpler :

    • one webpage (nothing “background”)
    • one CLI script, with no background stuff either.

    Your processing script could look like something like this, I suppose :

    // Fetch informations from DB about one file to process
    // and mark it as "processing"
    
    // Those would be fetched / determined from the data you just fetched from DB
    $in_file = 'in-file.avi';
    $out_file = 'out-file.avi';
    
    // Launch the ffmpeg processing command (will probably require more options ^^ )
    // The PHP script will wait until it's finished : 
    //   No background work
    //   No need for any kind of polling
    $output = shell_exec('ffmpeg ' . escapeshellarg($in_file) . ' ' . escapeshellarg($out_file));
    
    // File has been processed
    // Store the "output name" to DB
    // Mark the record in DB as "processed"
    

    Really easier than what you first thought, isn’t it ? 😉

    Just don’t worry about the background stuff anymore : only thing important is that the processing script is launched regularly, from crontab.

    Hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.