我有一个需求,我需要从Android的HLS Stream中提取元数据。我找到了两个库FFMPEG和VITAMIO。考虑到android上对HLS streaming的零散支持,在阅读了大量更令人困惑的文章后,我最终完成了上述两个库的进一步研究,没有发现一个应用程序在Android上完成了元数据(计时元数据)的提取。
我很困惑这是否可以在Android上实现。如果是这样,我应该使用哪种方法..。帮帮我伙计们..。
发布于 2013-10-22 02:11:56
定时文本元数据并不像Nikola的回答所建议的那样存储在m3u8文件中,而是存储在mpeg2 ts段中。这里提供了它是如何嵌入到ts中的概述:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/HTTP_Live_Streaming_Metadata_Spec/HTTP_Live_Streaming_Metadata_Spec.pdf
您可以尝试使用ffmpeg提取元数据,命令应该是这样的:
ffmpeg -i in.ts -f ffmetadata metadata.txt
您需要使用jni和libavformat执行相同的操作。这并不是非常简单,您仍然需要想出一种机制来向您的应用程序发送读取的元数据。
如果可以,我建议您通过单独的机制发送定时元数据信号。你能把它解压出来,放到你的播放器单独下载的文本文件中吗?然后你和视频播放器报告的时间线排成一排?这将更容易实现,但我不知道您的要求。
发布于 2013-10-21 10:21:57
解析m3u8相对容易。您需要创建String
和Integer
的HashMap
来存储解析后的数据。m3u8文件由3个条目标签组成,它们代表M3U8的条目、媒体序列和所有媒体文件的片段时长,但最后一个媒体文件与其他媒体文件不同。
在每个#EXTINF
整数持续时间被粘贴到它之后,所以我们需要通过使用基本的正则表达式解析字符串来获得它。
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;
}
干杯。
https://stackoverflow.com/questions/19404669
复制相似问题