0

我正在为 Decklink 开发 ffmpeg 播放应用程序,但我遇到了一些音频问题。我已经看到有关此主题的其他问题,但目前都没有帮助。

我已经尝试使用 swr_convert 将 Reubens 代码(https://stackoverflow.com/a/15372417/12610231)用于将 ffmpeg/libav 帧播放到 Decklink 板(这需要 16 位 PCM 交错),但音频听起来不对. 听起来它缺少样本/只获得了所需样本的一半)。

当我在原始音频文件中录制样本并使用 Audacity 播放时,时间线是实际录制长度的一半,并以双倍速度播放样本。

我还尝试了“手动”转换(https://stackoverflow.com/a/15372417/12610231),但不幸的是,这不是我希望的结果。

这是我的一些代码片段

swr_ctx = swr_alloc();
av_opt_set_int(swr_ctx, "in_channel_count", pAudioCodecCtx->channels, 0);
av_opt_set_int(swr_ctx, "in_sample_rate", pAudioCodecCtx->sample_rate, 0);
av_opt_set_int(swr_ctx, "in_channel_layout", pAudioCodecCtx->channel_layout, 0);
av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", pAudioCodecCtx->sample_fmt, 0);
av_opt_set_int(swr_ctx, "out_channel_count", 2, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", 48000, 0);
av_opt_set_int(swr_ctx, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);

if (swr_init(swr_ctx))
{
    printf("Error SWR");
}

///

ret = avcodec_decode_audio4(pAudioCodecCtx, pFrame, &frameFinished, &packet);

if (ret < 0) {
    printf("Error in decoding audio frame.\n");
}

swr_convert(swr_ctx, (uint8_t**)&m_audioBuffer, pFrame->nb_samples, (const uint8_t *)pFrame->extended_data, pFrame->nb_samples);

看起来 FFmpeg 数据包包含 1 个视频数据包和 2 个音频数据包,不确定如何处理第二个音频数据包,我已经尝试将第一个和第二个音频数据包合并,但在音频方面没有任何好的结果。

任何帮助表示赞赏。

4

0 回答 0