ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[https://blog.csdn.net/sweibd/article/details/79175541](https://blog.csdn.net/sweibd/article/details/79175541) ## 1、需要在编码中使能CODEC\_FLAG\_GLOBAL\_HEADER AVCodecContext的flags |= CODEC\_FLAG\_GLOBAL\_HEADER 设置这个标志位后,才能在AVCodecContext中的extradata和extradata\_size得到对应的音视频头信息。 视频: AVCDecoderConfigurationRecord+ sps + pps 音频: ASC FLAG ## 2、设置rtmp发送中的头信息 ``` AVCodecContext\* dest \= pStream\->codec; if (\_pSendCtx\->oformat\->flags & AVFMT\_GLOBALHEADER) { dest\->flags |= CODEC\_FLAG\_GLOBAL\_HEADER; HostLogInfo("video oformat->flags=0x%08x, extradata\_size=%d", \_pSendCtx\->oformat\->flags, \_pVCodeCtx\->extradata\_size); // for flv, we should avoid invoking ff\_avc\_parse\_nal\_units\_buf() in flvenc.c if (\_pVCodeCtx\->extradata\_size \> 0) { int extra\_size \= (uint64\_t)\_pVCodeCtx\->extradata\_size + FF\_INPUT\_BUFFER\_PADDING\_SIZE; dest\->extradata \= (uint8\_t\*)av\_mallocz(extra\_size); memcpy(dest\->extradata, \_pVCodeCtx\->extradata, \_pVCodeCtx\->extradata\_size); dest\->extradata\_size \= \_pVCodeCtx\->extradata\_size; } } ``` 关键点: 1. 设置dest中的flag信息 2. 设置dest中的extradata, extradata\_size信息 这样在avformat\_write\_header函数中才会头几帧写入sps/pps asc