Regex: Getting FPS from FFMPEG log
I try and try again with Regex, I just don't get it. I'm trying to traverse a log file for FFMPEG and get the FPS.
Basically, on a variable line (seems to be around 16/17) of the log file this line appears:-
Stream #0.1[0x1e0]: Video: mpeg1video, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn开发者_JAVA技巧, 25 tbc
I'd like to traverse line by line, which I think I can do exploding by /n and then for loop through, but I'd prefer to just get the line that line, and then get the FPS value.
Any pointers gratefully received.
You could try this:
if (preg_match('/^Stream #0.*?(\b\d+(?:\.\d+)?\s*fps\b).*/m', $subject, $regs)) {
$full_line = $regs[0];
$result = $regs[1];
} else {
// no match...
}
Explanation:
^ # start of line (/m modifier makes sure that this works)
Stream #0 # match Stream #0 literally
.*? # match any number of characters, as few as possible
( # then capture the following
\b # starting at a "word" boundary
\d+ # one or more digits
(?: # try to match the following:
\. # a dot
\d+ # followed by one or more digits
)? # but make that optional
\s* # optional whitespace
fps # literal fps
\b # end at a word boundary
) # end of capturing group
.* # match the rest of the line
精彩评论