首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码Ogg/Opus文件

解码Ogg/Opus文件
EN

Stack Overflow用户
提问于 2016-06-14 15:29:39
回答 1查看 2.6K关注 0票数 3

我有一个非常小的C++代码,它尝试打开一个ogg/opus编码文件,并使用opus来用函数opus_decode()对它进行解码。问题是,几乎一半的opus_decode()调用相同的声音返回负(错误)代码。-4和-2 (无效的包裹和缓冲区太短),我无法解决。输出就像

N解码: 960 N解码:-4 N解码: 1920 N解码: 960 N解码:-4 N解码

诸若此类。

代码语言:javascript
复制
#include <string.h>
#include <opus/opus.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
#include <fstream>

#define LEN 1024
#define FREQ 48000
#define CHANNELS 1
#define FRAMESIZE 1920

int main(int argc, char *argv[]) {

    int size = opus_decoder_get_size(CHANNELS);

    OpusDecoder *decoders = (OpusDecoder*)malloc(size);
    int error = opus_decoder_init(decoders, FREQ, CHANNELS);

    std::ifstream inputfile;
    inputfile.open("/home/vir/Descargas/detodos.opus"); //48000Hz, Mono

    char input[LEN];

    opus_int16 *data = (opus_int16*)calloc(CHANNELS*FRAMESIZE,sizeof(opus_int16));


    if(inputfile.is_open())
        while (!inputfile.eof()) {

            inputfile >> input;         

            std::cerr << "N decoded: " << opus_decode(decoders, (const unsigned char*)&input[0], LEN, data, FRAMESIZE, 0)  << "\n";

        }


    return error;
}
EN

回答 1

Stack Overflow用户

发布于 2016-08-30 02:22:10

看来您使用的是Opus工具而不是OpusFile。显然,您已经针对libopus.a库进行了链接,但您还需要下载和构建OpusFile 0.7,并根据构建OpusFile创建的libopusfile.a链接您的程序。将opusfile.h包含在OpusFile 0.7的程序中。最后,您需要下载并构建libogg库,从Xiph.org/下载下载libogg 1.3.2并链接到该库。

这个链接是解释如何打开和关闭opus流以进行解码的文档。

确保您有ogg opus文件并使用.

代码语言:javascript
复制
OggOpusFile *file = op_open_file(inputfile, error)(inputfile is char* inputfile and error is an int pointer)

使用op_free(file)关闭流。这是实际解码opus流的功能文档。在调用op_free之前,用.

代码语言:javascript
复制
op_read(file,buffer,bufferSize,null), buffer is opus_int16 pcm[120*48*2]

bufferSizesizeof(pcm)/sizeof(*pcm)op_read将解码更多的文件,因此将其放在for循环中,直到op_read返回0为止。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37816289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档