如何从ogg/opus文件中一一读取OPUS数据包 [英] How can I read OPUS packets one by one from ogg/opus file

查看:244
本文介绍了如何从ogg/opus文件中一一读取OPUS数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从ogg/opus文件中逐一读取OPUS数据包,然后以OPUS格式进一步发送它们,因此无需解码.我正在查看 opusfile lib,但API和示例相当复杂并且更着重于解码文件并获得结果PCM.有没有一种方法可以用此库实现我想要的功能,以及如何实现?如果没有,我还有什么其他选择?

I need to read OPUS packets one by one from ogg/opus file and send them further in OPUS format so without decoding. I'm looking at opusfile lib but API and examples are rather complicated and more focused on decoding the file and getting resulted PCM. Is there a way to achieve what I want with this lib and how? If not what other options do I have?

推荐答案

我想我来晚了.我有非常相似的用例,我想从ogg opus文件中提取opus数据包.我找到了这个答案

I guess I am slightly late. I had very similar use case, I wanted to extract opus packets from ogg opus file. I found this answer

https://stackoverflow.com/a/26285277/10110652

以下代码将帮助您在while循环内的"nextPacket" byteArray中获取Opus数据包(未解码为pcm)

Following code will help you to get opus packets (without been decoded to pcm) in 'nextPacket' byteArray inside while loop

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文件.

Same program can be used to extract vorbis encoded packets in ogg container, means ogg vorbis file.

编码愉快!

这篇关于如何从ogg/opus文件中一一读取OPUS数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆