Is there any way to extract metadata from video(m3u开发者_运维百科8) files, If exist please help me with links or source code. Thanks
m3u8 is the utf8 version of m3u instead c1252 charset.
m3u is a text file as a play list file with a content like:
#EXTM3U starts header and must be the first line
#EXTINF for each playable file.
In this link you can view samples:
http://schworak.com/programming/music/playlist_m3u.asp
And an overview for generalistic HTTP Streaming Architecture.
Code for the lazy dudes out there is below and detailed answered is 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;
}
Cheers.
精彩评论