【问题标题】:opus_decode returning corrupted streamopus_decode 返回损坏的流
【发布时间】:2020-02-26 13:38:33
【问题描述】:

我正在解码从 icecast 服务器直播的 ogg opus 数据。我正在使用 libopus 进行解码。 数据有时会被解码,但大多数时候 op_decode() 返回 -4 表示流损坏。 这是使用 curl 库访问数据的回调函数。

#define SAMPLE_RATE 48000
#define CHANNELS 2
#define MAX_FRAME_SIZE 6*960
size_t play_stream(void *buffer, size_t size, size_t nmemb, void *userp)
{
    FILE *fp;
    opus_int16 out[MAX_FRAME_SIZE * CHANNELS];
    int error;
    int i;
    unsigned char pcm_bytes[MAX_FRAME_SIZE * CHANNELS * 2];
    int frame_size;

    frame_size = opus_decode(decoder, (unsigned char*)buffer, (opus_int32)size * nmemb, out, MAX_FRAME_SIZE, 0);

    if (frame_size < 0)
    {
        fprintf(stderr, "decoder failed: %s\n", opus_strerror(frame_size));

    }


    return size * nmemb;
}

有人可以帮帮我吗?

【问题讨论】:

  • 最明显的检查是:size*nmemb 的尺寸是否正确?
  • @user253751 size*nmemb 是 curl 回调给出的大小......它一直在变化。
  • 缓冲区包含什么?您应该为每个 opus_decode 调用传递一个原始 opus 数据包。您应该在解码之前从 ogg 推断它。

标签: c curl ogg decoder opus


【解决方案1】:

opus_decode() 函数解码 Opus 数据包,而不是 Ogg Opus 流。您可以使用 Ogg 库从流中获取数据包,然后使用 libopus 对数据包进行解码,但更简单的方法是使用 opusfile 库。 Opusfile 甚至可以直接从网络读取流。

【讨论】:

  • 谢谢,我可以直接使用 opusfile 解码 url。但是如何关闭来自网络的流式音频连接?
  • @SajuAlexander:完成后只需在 OggOpusFile 上调用 op_free()。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-01
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多