使用 libshout 将 OGG Flac 流式传输到 Icecast

Streaming OGG Flac to Icecast with libshout

我有一个用 C++ 开发的简单流媒体,使用 LibFlac 和 LibShout 流式传输到 Icecast 服务器。 flac 编码器是通过以下方式创建的:

  m_encoder = FLAC__stream_encoder_new();
  FLAC__stream_encoder_set_channels(m_encoder, 2);
  FLAC__stream_encoder_set_ogg_serial_number(m_encoder, rand());
  FLAC__stream_encoder_set_bits_per_sample(m_encoder, 16);
  FLAC__stream_encoder_set_sample_rate(m_encoder, in_samplerate);
  FLAC__stream_encoder_init_ogg_stream(m_encoder, NULL, writeByteArray, NULL, NULL, NULL, this);

函数 writeByteArray 使用来自 libshout 的 shout_send_raw 函数将编码数据发送到 Icecast。 shout_send_raw returns 实际发送的字节数,所以我假设它正常工作,没有发生错误。 问题是 Icecast 服务器不流式传输我发送的数据。我在日志中看到以下内容: [2018-02-15 15:31:47] DBUG stats/modify_node_event update "/radio" total_bytes_read (20735897) [2018-02-15 15:31:47] DBUG stats/modify_node_event update "/radio" total_bytes_sent (0) 我看到 Icecast 接收到数据,但它没有将其发送到连接的客户端。挂载点是 radio,当我尝试使用任何媒体播放器连接到该挂载点时 - 它什么都不做,没有播放。 所以我的问题是 Icecast 接收数据但不将其发送给连接的客户端怎么可能? 也许需要一些额外的 libshout 配置,下面是我的配置方式: shout_set_format( m_ShoutData, SHOUT_FORMAT_OGG_AUDIO ); shout_set_mime( m_ShoutData, "application/ogg" ); 任何帮助将不胜感激。

根据评论总结解决方案:

FLAC 的比特率明显高于任何其他常用的音频编解码器。因此,默认设置将 NOT 起作用。队列大小 必须 显着增加,以便完整的数据帧适合它,否则,Icecast 将不会在流上同步并拒绝向客户端输出数据。

流媒体视频显然也是如此。必须针对适当的挂载点或全局调整队列大小。