Capture FFMPEG output

后端 未结 4 1852
鱼传尺愫
鱼传尺愫 2020-12-29 11:24

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 quest

相关标签:
4条回答
  • 2020-12-29 12:08

    To get output status and output:

    exec("ffmpeg -i input.avi output.mp4 2>&1", $output, $returnStatus);
    
    print_r($output);
    
    if($returnStatus === 0){
       // success
    }
    else {
       //fail
    }
    
    0 讨论(0)
  • 2020-12-29 12:17

    You can use exec and print_r the output...

    exec("ffmpeg -i input.avi -vcodec h264 -acodec aac -strict -2 output.mp4 2>&1",$output);
    
    echo "<pre>";
    print_r($output);
    echo "</pre>";
    
    0 讨论(0)
  • 2020-12-29 12:26

    The problem is you catch only stdout and not stderr (see Standard Streams). Change this line:

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

    into

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

    and give it another try :)

    0 讨论(0)
  • Use ffprobe instead, it's much quicker and supports JSON output.

    $output = shell_exec('ffprobe -v quiet -print_format json -show_format -show_streams "path/to/yourfile.ext"');
    $parsed = json_decode($output, true);
    

    And you have all your video info in a php array! This is much faster than ffmpeg -i for some reason.

    0 讨论(0)
提交回复
热议问题