opus_decode返回损坏的流

问题描述 投票:0回答:1

我正在解码从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;
}

有人可以帮我吗?

c curl ogg decoder opus
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.