解封装(Demuxing):
avformat_open_input → 打开文件
av_read_frame → 读 packet
avcodec_send_packet + avcodec_receive_frame → 解码
封装(Muxing):
avformat_alloc_output_context2 → 确定容器格式
avcodec_send_frame + avcodec_receive_packet → 编码
av_interleaved_write_frame → 写出/推流
色彩转换:
BGRA → YUV420P:sws_getContext + sws_scale 一步完成
比手写 RGB→YUV 再下采样快 3-5 倍
直播配置关键:
gop_size = 30(每 30 帧一个关键帧)
max_b_frames = 0(不要 B 帧减少延迟)
AV_CODEC_FLAG_LOW_DELAY(编码器低延迟模式)