Php 用于从字符串导出某些信息的regext
我有这样一个输出字符串Php 用于从字符串导出某些信息的regext,php,regex,Php,Regex,我有这样一个输出字符串 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 remo
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
及
尝试(未经测试):
我对“datasize”所做的同样的事情应该适用于您想要获得的每一个信息,尽管这些信息有不同的格式(比如持续时间和包含音频比特率的流信息)
输出
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
)
尝试以下方法
preg_match_all('/(?:\b(?:duration|videosize|audiosize)\b\s*:[0-9:. ]+|stream #.*)/i', $data, $matches);
print_r($matches);
看
输出
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
)
)
将在持续时间(因为该行上有多个冒号)和流信息(相同的原因)上失败。是的,在您发表评论之前,刚刚注意到,{2,4}cheers中的滑动这与我的需要非常接近,但正如我所说,我无法调整字符串的开始和结束,因此此时元素编号[12]在输出数组中是持续时间,但如果数字发生变化,该持续时间是多少!?我怎样才能只获得输出中的持续时间?!你想要哪一部分?用你想要的输出编辑你的问题。我的意思是,突出显示或在你想要在你的数据中提取的项目旁边添加注释。这些表达式有什么用?什么都没有?
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
)
preg_match_all('/(?:\b(?:duration|videosize|audiosize)\b\s*:[0-9:. ]+|stream #.*)/i', $data, $matches);
print_r($matches);
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
)
)