codec - 如何从ogg/opus文件中一一读取OPUS数据包

标签 codec ogg opus

我需要从 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/

相关文章:

Qt 或 OpenCV : print out the codec of a video file

iphone - iPhone sdk 中的 OGG Vorbis

java - 读取OGG作为LWJGL 3 OpenAL的样本流

c# - 使用 NAudio 将 WAV 流转换为 Opus

android - 是否存在任何返回媒体文件比特率、帧率等的 android api?

android - FFmpeg - 转换视频以在 Android 设备上播放的命令

c++ - Qt、声子和多媒体编解码器 : how to bundle them?

shell - 从 OGG 文件中提取封面图像

audio - 有没有一种方法可以比 DTX 更好地优化 Opus 中的静音期?

ios - AudioUnit + Opus 编解码器 = 裂纹问题