tags:

views:

1034

answers:

1

I need to read the output from ffmpeg in order to even try the solution to my question from yesterday. This is a separate issue from my problem there, so I made a new question.

How the heck do I get the output from an ffmpeg -i command in PHP?

This is what I've been trying:

<?PHP
    error_reporting(E_ALL);
    $src = "/var/videos/video1.wmv";
    $command = "/usr/bin/ffmpeg -i " . $src;
    echo "<B>",$command,"</B><br/>";
    $command = escapeshellcmd($command);

    echo "backtick:<br/><pre>";
    `$command`;

    echo "</pre><br/>system:<br/><pre>";
    echo system($command);

    echo "</pre><br/>shell_exec:<br/><pre>";
    echo shell_exec($command);

    echo "</pre><br/>passthru:<br/><pre>";
    passthru($command);

    echo "</pre><br/>exec:<br/><pre>";
    $output = array();
    exec($command,$output,$status);
    foreach($output AS $o)
    {
            echo $o , "<br/>";
    }
    echo "</pre><br/>popen:<br/><pre>";
    $handle = popen($command,'r');
    echo fread($handle,1048576);
    pclose($handle);
    echo "</pre><br/>";
?>

This is my output:

<B>/usr/bin/ffmpeg -i /var/videos/video1.wmv</B><br/>
backtick:<br/>
    <pre></pre><br/>
system:<br/>
    <pre></pre><br/>
shell_exec:<br/>
    <pre></pre><br/>
passthru:<br/>
    <pre></pre><br/>
exec:<br/>
    <pre></pre><br/>
popen:<br/>
    <pre></pre><br/>

I don't get it. safe_mode is off. There's nothing in disable_functions. The directory is owned by www-data (the apache user on my Ubuntu system). I get a valid status back from exec() and system() and running the same command from the command line give me tons of output. I feel like I must be missing something obvious but I have no idea what it is.

Help. Please.

+5  A: 

The problem is you catch only stdout and not the stderr. Change this line:

$command = "/usr/bin/ffmpeg -i " . $src;

into

$command = "/usr/bin/ffmpeg -i " . $src . " 2>&1";

and give it another try :)

hegemon
Andrew
I can confirm that the following should work. I've used this exact line in a hobby project once.exec('ffmpeg -i ' . escapeshellarg($filepath) . ' 2>
Werner
Andrew