[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
- 序言
- 編解碼
- H264
- HEVC碼流解析
- H264編碼原理
- 多媒體封裝
- MP4
- 學好 MP4,讓直播更給力
- AAC
- FLV
- 流媒體協議
- RTSP
- RTCP
- RTP
- H265 RTP封包筆記
- SDP
- RTMP
- RTMP URL
- rtmp url基礎
- webrtc
- 編譯
- 最簡單的編譯webrtc方案
- Webrtc音視頻會議之Webrtc“不求甚解”
- Webrtc音視頻會議之Mesh/MCU/SFU三種架構
- 音頻傳輸之Jitter Buffer設計與實現
- Janus
- Webrtc音視頻會議之Janus編譯
- Webrtc音視頻會議之Janus源碼架構設計
- webrtc服務器-janus房間管理
- 源碼分析
- WebRTC視頻JitterBuffer詳解
- 走讀Webrtc 中的視頻JitterBuffer(一)
- 走讀webrtc 中的視頻JitterBuffer(二)
- webrtc視頻幀率控制算法機制
- 目標碼率丟幀-1
- 目標幀率丟幀-2
- 29 如何使用Medooze 實現多方視頻會議
- FFmpeg
- FFmpeg編譯
- Window10下編譯最新版FFmpeg的方法步驟
- FFMPEG靜態庫編譯
- ffmpeg實現畫中畫
- FFmpeg推流器
- ffmpeg-aac
- OpenCV
- OpenCV學習筆記——視頻的邊緣檢測
- 圖像特征點匹配(視頻質量診斷、畫面抖動檢測)
- 圖像質量診斷