FFmpeg Decklink播放音频PCM

时间:2019-12-27 23:45:03

标签: audio ffmpeg pcm libav decklink

我正在为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个音频数据包,不确定如何处理第二个音频数据包,我已经尝试将第一个和第二个音频数据包组合在一起,但效果不佳音频方面。

感谢您的帮助。

0 个答案:

没有答案