p{margin:0;padding:0;}

Greeting from S. Korea ! 

I am parsing the output of ffmpeg with perl. Particular, I want to print only 
these lines among the output and capturing the resolution, i.e. 1280x720. 
....

Stream #0:0: Video: h264 (High), yuv420p, 1280x720, SAR 1:1 DAR 16:9, 23.98 
fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(jpn): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
Stream #0:2(eng): Subtitle: ass (default) 
.....


My code is following: 
# INFO is pipe to ffmpeg 
# Here, the <print "$1 $2 $3 $4\n"> is for debugging .  
while ( <INFO> ) { 
        if ( <regular expression>  ) { 
            print "$1 $2 $3 $4\n"; 
        }
}
Desirable outputs: 
-> Video 1280 720 
     Audio 
     Subtitle 

Regarding the <regular expession>: 
1. /Stream #\d:\d.*(Video|Audio|Subtitle).*(\d+)x(\d+)/ (greedy)
-> Video 0 720 
Q: why does $2 give  0? I remember .* match backward starting from the end of 
the string. Then it should be  "Video 1280 720" as output.

2. /Stream #\d:\d.*(Video|Audio|Subtitle).*?(\d+)x(\d+)/ (non greedy) 
-> Video 1280 720 
Q: I can understand this, but again I think (1) should work too. 

3. /Stream #\d:\d.*(Video|Audio|Subtitle).*?(?:(\d+)x(\d+))?/ ( non-capturing 
optional group ) 
-> Video 
    Audio 
    Subtitle 
Q: It seems that the resolution part is ignored because it is optional. 
Otherwise, the output will contains "Video" only as (1) and (2). How can I 
circumvent this ? 

4. /Stream #\d:\d.*(Video|Audio|Subtitle).+?(?:(\d+)x(\d+))?.*?$/ 
-> Video 
     Audio 
     Subtitle 
Q: I tried to match things after the resolution, hoping that it will be 
captured. 

5. /Stream #\d:\d.*(Video|Audio|Subtitle).+?(?:(\d+)x(\d+))?(.*?)$/ ( let's 
capture the last part) 
-> Video    h264 (High), yuv420p, 1280x720, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 
tbr, 1k tbn, 47.95 tbc (default)
    Audio    ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
    Subtitle    ass (default)
Q: Now $2 and $3 is undef, and the rest of the string went to $4. Again, I am 
quite puzzled by the output. 

Please pardon my long email. I hope someone can point out the flaws in my 
logic. Here, I can match and print Video/Audio/Subtitle separately. 
But I wish for one expression to match them all, one expression to print them. 


Best regards, 

Viet-Duc



Reply via email to