Search code examples
phpffmpegproc-open

php proc_open how to detect that the command is completed / proc_open() expects at least 3 parameters


Here is my code

$descriptorspec = array( 0 => array("pipe", "r") );
$call_mp4 = "ffmpeg command ...... ";
$openMp4 = proc_open($call_mp4, $descriptorspec , $pipe);
$isMp4stillcompressing  = proc_get_status( $openMp4 );
while ( $isMp4stillcompressing['running'] ) {
    echo '• ';
}

The "bug" I have is that it goes without end ;(

Why is that ?

My main goal is to output a dot or other info while being converted

Thanks


Solution

  • In this order, the variable $isMp4stillcompressing will be set once outside the while loop, and remain true forever inside the loop. It needs to be checked each time the loop runs:

    $isMp4stillcompressing  = proc_get_status( $openMp4 );
    
    while ( $isMp4stillcompressing['running'] ) {
        echo '• ';
        $isMp4stillcompressing  = proc_get_status( $openMp4 );
    }