codec - 如何从 ogg/opus 文件中一一读取 OPUS 数据包
问题描述
我需要从 ogg/opus 文件中一一读取 OPUS 数据包,并以 OPUS 格式进一步发送它们,因此无需解码。我正在查看opusfile库,但 API 和示例相当复杂,并且更专注于解码文件并获得结果 PCM。有没有办法用这个库实现我想要的,以及如何实现?如果不是,我还有什么其他选择?
解决方案
我想我有点晚了。我有非常相似的用例,我想从 ogg opus 文件中提取 opus 数据包。我找到了这个答案
https://stackoverflow.com/a/26285277/10110652
以下代码将帮助您在 while 循环内的 'nextPacket' byteArray 中获取 opus 数据包(未解码为 pcm)
File audioFile = null;
try {
audioFile = new File("xyz.ogg"); //input ogg opus file
oggFile = new FileStream(new RandomAccessFile(audioFile, "r"));
for (LogicalOggStream stream : (Collection<LogicalOggStream>) oggFile.getLogicalStreams()) {
byte[] nextPacket = stream.getNextOggPacket();
while (nextPacket != null) {
//nextPacket here contains opus packet
//do what ever you want to do with this packet
nextPacket = stream.getNextOggPacket();
}
}
} catch (EndOfOggStreamException e) {
System.out.println("End of File");
//file usually get over by raising this exception while execution getNextOggPacket()
}
相同的程序可用于提取 ogg 容器中的 vorbis 编码数据包,即 ogg vorbis 文件。
快乐编码!!!
推荐阅读
- java - java - 如何允许任何不是字母表中的字母的字符保留在java中
- java - Oracle Advance Queue 和 Java:能够通过代码发送消息但无法在队列表中看到
- git - 从远程仓库获取最后提交日期而不进行克隆
- string - 如何将字符串值插入到创建的空 py-spark 数据框中?
- flutter - 未处理的异常:无效的参数(值):不能为空 Flutter 2
- html - 添加以图像源为文本的动态超链接
- vue.js - Vue Js 输入字段电话号码
- java - Java RabbitMQ:无法将消息映射到相应的类
- python - 如何在每个新行上写日期?
- javascript - 当用户单击垂直滚动条并将其向上或向下移动时,我如何收听事件