gpt4 book ai didi

Android - 什么数据结构来存储视频字幕以在 O(1) 时间内获取它们

转载 作者:太空狗 更新时间:2023-10-29 13:25:05 25 4
gpt4 key购买 nike

我正在我的应用程序中播放视频,我必须在其上显示字幕。字幕位于单独的 smi 文件中,该文件是提供字幕信息的某种 XML 标记。字幕文件看起来像这样:

.
.
.
<sync start=104600>
<P Class=GBR><i></i><span ID=style1_0><i>Born of cold and winter air</i> </span><br><i></i><span ID=style1_0><i>and mountain rain combining.</i> </span></P>
</sync>
<sync start=107080>
<P Class=MYS>&nbsp;<br></P>
</sync>
<sync start=107200>
<P Class=MYS><i></i><span ID=style2_0><i>...serta hujan di pergunungan.</i> </span></P>
</sync>
<sync start=110840>
<P Class=MYS>&nbsp;<br></P>
<P Class=GBR>&nbsp;<br></P>
</sync>
<sync start=111160>
<P Class=SIM>&nbsp;<br></P>
</sync>
<sync start=111480>
<P Class=GBR><i></i><span ID=style1_0><i>This icy force</i> </span><br><i></i><span ID=style1_0><i>both foul and fair...</i> </span></P>
</sync>
.
.
.
.

start 是在视频顶部显示字幕的时间(以毫秒为单位)。现在我正在解析使用正则表达式并创建 SubtitleChunkArrayList,其中包含 startTime 和与之关联的内容。

class SubtitleChunk {
long startTime;
String content;
}

现在在显示视频时我已经启动了一个单独的线程,我正在使用它从数组中获取字幕并显示它。以下是逻辑

public void run() {
while (!isFinished_) {
if (subtitleContent != null && subtitleContent.content_ != null) {
for (int i = 0; i < length; i++) {
SubtitleChunk subChunk1 = null;
SubtitleChunk subChunk2 = null;
try {
subChunk1 = subtitleContent.content_.get(i);
subChunk2 = subtitleContent.content_.get(i + 1);

long cTime = moviePlayer_.getCurrentTimeMillis();
if (cTime > subChunk1.startTime && (subChunk2 == null || cTime < subChunk2.startTime)) {
currentSub = subChunk1.content;
currentChunk = subChunk1;
break;
}
} catch (Exception e) {
DebugUtil.printLogException(VIEW_LOG_TAG, e);
currentSub = "";
}
}
} else {
currentSub = "";
}

} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (moviePlayer_.isPlaying()) {
subtitleTextView.setText(Html.fromHtml(currentSub));
} else {

}
}
});
}
}

如您所见,我在 ArrayList 上运行一个循环,并将字幕的时间与我认为太昂贵的 moviePlayer_.getCurrentTimeMillis() 进行比较。字幕滞后,与视频不同步。

以上就是对问题的解释。现在的问题是..我该如何改进它?在 O(1) 时间内获取特定时间的字幕。

已编辑

我选择了 Interval Trees,这就是我需要放入字幕的内容:我从这里得到它:https://github.com/phishman3579/java-algorithms-implementation

最佳答案

更新:只是为了被接受 :-) 从我的评论中删除。

startTime 相对于视频的开头。因此,人们知道视频中相对于开始的位置。如果当前相对时间在一定范围内,那么我可以得到字幕。我不确定 Java 库中的任何数据结构是否有帮助。看看Segment Tree/Interval Tree .它会给你更多的洞察力。我希望这可能会有所帮助。这个想法是预处理您的 SMI 文件

关于Android - 什么数据结构来存储视频字幕以在 O(1) 时间内获取它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com