我试图解析ffmpeg -i
命令的一些输出。一些输出可能如下所示:
libavutil 50. 8. 0 / 50. 8. 0
libavcodec 52.52. 0 / 52.52. 0
libavformat 52.50. 0 / 52.50. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.10. 0 / 0.10. 0
libpostproc 51. 2. 0 / 51. 2. 0
Input #0, avi, from '/my/folder/clip.mpeg':
Duration: 00:05:25.00, start: 0.000000, bitrate: 554 kb/s
Stream #0.0: Video: msvideo1, rgb555le, 160x100, 10 tbr, 10 tbn, 10 tbc
如何解析最后一行的比特率值?我不能创建一个静态解析器,它只是在String中的位置x处选取值,因为输出不时有所不同,所以我必须以某种方式使其动态化。
但是怎么样?
答案 0 :(得分:2)
您可以使用正则表达式。 尝试这样的事情:
String text = "Duration: 00:05:25.00, start: 0.000000, bitrate: 554 kb/s";
final Pattern p = Pattern.compile(".?bitrate:\\s([0-9]*)\\skb/s");
final Matcher m = p.matcher(text);
if(m.find())
{
System.out.println(m.group(1));
}
有关Java和正则表达式的更多信息:http://docs.oracle.com/javase/tutorial/essential/regex/
答案 1 :(得分:0)
只需搜索字符串“bitrate:”并从那里开始。