0

我有一个这样的输出字符串

ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Oct 22 2013 12:31:55 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[flv @ 0x23307a0] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 25.00 (25/1)
Input #0, flv, from '307263_191.flv':
  Metadata:
    metadatacreator : Yet Another Metadata Injector for FLV - Version 1.4
    hasKeyframes    : true
    hasVideo        : true
    hasAudio        : true
    hasMetadata     : true
    canSeekToEnd    : true
    datasize        : 42773717
    videosize       : 40350092
    audiosize       : 2403669
    lasttimestamp   : 107
    lastkeyframetimestamp: 107
    lastkeyframelocation: 42758866
  Duration: 00:01:47.18, start: 0.000000, bitrate: 3186 kb/s
    Stream #0.0: Video: flv, yuv420p, 1024x576, 3009 kb/s, 25 tbr, 1k tbn, 1k tbc
    Stream #0.1: Audio: adpcm_swf, 22050 Hz, 2 channels, s16, 176 kb/s
At least one output file must be specified

我必须从字符串中获取一些信息,例如持续时间、视频比特率、音频比特率以及视频和音频的大小。一种方法是用explode来做,但是字符串的重要部分之前和之后的文本不在我的控制范围内,并且可能会在每个输入上发生变化

有什么方法可以匹配字符串中的任何键和值:

更新:我需要这些

videosize       : 40350092
audiosize       : 2403669
Duration: 00:01:47.18

    Stream #0.0: Video: flv, yuv420p, 1024x576, 3009 kb/s, 25 tbr, 1k tbn, 1k tbc
    Stream #0.1: Audio: adpcm_swf, 22050 Hz, 2 channels, s16, 176 kb/s
4

3 回答 3

1

试试下面的。

preg_match_all('/(?:\b(?:duration|videosize|audiosize)\b\s*:[0-9:. ]+|stream #.*)/i', $data, $matches);
print_r($matches);

working demo

输出

Array
(
    [0] => Array
        (
            [0] => videosize       : 40350092
            [1] => audiosize       : 2403669
            [2] => Duration: 00:01:47.18
            [3] => Stream #0.0: Video: flv, yuv420p, 1024x576, 3009 kb/s, 25 tbr, 1k tbn, 1k tbc
            [4] => Stream #0.1: Audio: adpcm_swf, 22050 Hz, 2 channels, s16, 176 kb/s
        )
)
于 2013-11-07T16:39:56.483 回答
0

尝试(未经测试):

$duration     = preg_replace("#duration\s*:\s*(\d{2}:\d{2}:\d{2}.\d+)#i", "$1", $input)
$datasize     = preg_replace("#datasize\s*:\s*(\d+)#i"                  , "$1", $input)
$audiobitrate = preg_replace("#audio\s*:.*,\s*(\d+)\s*kb/s#i"           , "$1", $input)

我对“datasize”所做的同样的事情应该适用于你想要获得的每一个信息,尽管它们具有不同的格式(比如持续时间和内部带有音频比特率的流信息)

于 2013-11-07T05:23:48.610 回答
0
preg_match_all('/ {2,4}(.+?)\s?: (.+)/',$ffmegoutputstring,$matches,PREG_SET_ORDER);
print_r($matches);

输出...

Array
(
    [0] => Array
        (
            [0] =>     metadatacreator : Yet Another Metadata Injector for FLV - Version 1.4
            [1] => metadatacreator
            [2] => Yet Another Metadata Injector for FLV - Version 1.4
        )

    [1] => Array
        (
            [0] =>     hasKeyframes    : true
            [1] => hasKeyframes
            [2] => true
        )
于 2013-11-07T05:26:36.223 回答