av_interleaved_write_frame错误 Invalid data found when processing input

问题描述:
调用av_interleaved_write_frame接口发送AAC格式的音频数据时,报错:Invalid data found when processing input
解决方案:

if (pOutFormatCtx->oformat->flags & AVFMT_GLOBALHEADER){
    pOutAudioCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

我之前添加过上面的代码,但是没有执行到,导致av_interleaved_write_frame接口失败,强制设置了一下,可以了。

    pOutAudioCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;

AV_CODEC_FLAG_GLOBAL_HEADER在源码中的定义如下:

/**
 * Place global headers in extradata instead of every keyframe.
 * 将全局头部信息放在extradata指针中,而不是每一个关键帧中
 */
#define AV_CODEC_FLAG_GLOBAL_HEADER   (1 << 22)

注意:有些格式需要设置该参数。

其具体使用可参考:
https://blog.csdn.net/a812073479/article/details/79856262
https://blog.csdn.net/passionkk/article/details/75528653

发布了59 篇原创文章 · 获赞 22 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Martin_chen2/article/details/100153426