2

When I run proc_open with a file.txt path for the stderr output, that file is constantly updated every couple seconds with output of the proc_open program I am running which is ffmpeg. I just want to redirect that output to a phpfile where it can be read and parsed but while the process is running (so send info every couple seconds) so I can update a database. IS this possible? I have been googling for hours so if there are any experts out there who actually know how to use this function of have experience in this I would greatly appreciate any help.

this puts output in a text doc. If I change to 2 => array("pipe","w") and the echo the output only comes on my screen at the end of the process

$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("file","/home/g/Desktop/test.txt","a")
) ;

$cwd = './' ;
// open process /bin/sh
$process = proc_open("/usr/local/bin/ffmpeg -i /home/g/Desktop/vid.wmv /home/g/Desktop/vid.flv", $descriptorspec, $pipes, $cwd) ;

1 Answer 1

1
  1. you could run ffmpeg like this:

    ffmpeg ..optinons... 2>&1 | php script.php
    

But you could have in input STDERR and STDOUT of ffmpeg

  1. And second normal decision:

    <?
    $cmd = 'ffmpeg -i /home/azat/Desktop/src.avi -y /home/azat/Desktop/dst.avi';
    $pipes = array();
    $descriptors = array(2 => array('file', '/tmp/atest.log', 'a'));
    
    $p = proc_open($cmd, $descriptors, $pipes);
    
    while (true) {
            sleep(1);
    
            $status = proc_get_status($p);
            if (!$status['running']) break;
    
            echo "STEEL RUN\n";
            // some manupulations with "/tmp/atest.log"
    }
    

Also you can see this class - it is a wrapper for exec processes

Sign up to request clarification or add additional context in comments.

6 Comments

ffmpeg ..optinons... 2>&1 | php script.php if I do that, the php script will only execute once at the end. I want to keep sending info so I can create a progress bar. Your second suggestion will write to a log right? I want to be able to parse and send that information to a database on regular intervals. Can this be done? Also what does that class do?
Interval - is sleep(1);. Change it for your value. Class is do the same things, and even more (for example see loop method)
And about "ffmpeg ..optinons... 2>&1 | php script.php" you wrong! It will send output of ffmpeg to script while it comes from ffmpeg
Well I tried doing it and putting an insert statement in the script.php and only one database entry was there. I was expecting several. What variable do you use to refer to the ffmpeg data coming to script.php?
$h = fopen('php://stdin', 'r'); $str = fgets($h); fclose($h); $str - your string
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.