How to parse ffmpeg info in PHP?

前端 未结 4 1727
梦谈多话
梦谈多话 2020-12-28 23:48

How does one go about getting specific pieces of information, like the \'duration\' from the output of ffmpeg -i /var/thismovie.avi ?

I need frame heigh

4条回答
  •  有刺的猬
    2020-12-29 00:37

    $output = `ffmpeg -i /var/thismovie.avi`; //note that back quote is like exec
    preg_match('/Duration: (.*?),.*?Video:.*?0x.*?([0-9]+)x([[0-9]+).*?([0-9]+) fps/i'
        ,$output , $result);
    

    output of $result array should be like this:

    Array
    (
        [0] => Duration: 00:00:10.76, start: 0.000000, bitrate: 5180 kb/s Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps
        [1] => 00:00:10.76
        [2] => 1280
        [3] => 720
        [4] => 25
    )
    

    UPDATE

    The actual output is multi line, so please update the pattern into

    /Duration: (.*?),.*?([0-9]+)x([0-9]+) \[.*?([0-9]+) fps/is

提交回复
热议问题