我需要从 ogg/opus 文件中一一读取 OPUS 数据包,并以 OPUS 格式进一步发送它们,这样就无需解码。我正在看opusfile lib,但 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文件。
编码愉快!!!
关于codec - 如何从ogg/opus文件中一一读取OPUS数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64479365/