有没有办法从视频(m3u8)文件中提取元数据,如果存在,请帮我链接或源代码。 感谢
答案 0 :(得分:1)
m3u8是m3u的utf8版本,而不是c1252 charset。
m3u是一个文本文件,作为播放列表文件,内容如下:
#EXTM3U starts header and must be the first line
#EXTINF for each playable file.
在此链接中,您可以查看样本:
答案 1 :(得分:0)
下面的懒人的代码如下,详细的答案是here
private HashMap<String, Integer> parseHLSMetadata(InputStream i ){
try {
BufferedReader r = new BufferedReader(new InputStreamReader(i, "UTF-8"));
String line;
HashMap<String, Integer> segmentsMap = null;
String digitRegex = "\\d+";
Pattern p = Pattern.compile(digitRegex);
while((line = r.readLine())!=null){
if(line.equals("#EXTM3U")){ //start of m3u8
segmentsMap = new HashMap<String, Integer>();
}else if(line.contains("#EXTINF")){ //once found EXTINFO use runner to get the next line which contains the media file, parse duration of the segment
Matcher matcher = p.matcher(line);
matcher.find(); //find the first matching digit, which represents the duration of the segment, dont call .find() again that will throw digit which may be contained in the description.
segmentsMap.put(r.readLine(), Integer.parseInt(matcher.group(0)));
}
}
r.close();
return segmentsMap;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
干杯。