Skip to content

音视频处理基础

音视频封装

🎬 视频/音频处理 Pipeline

[输入文件]

(Container)                         // avformat_open_input

(Stream)                            // avformat_find_stream_info

(Stream selection)                  // 选择 audio / video stream(av_find_best_stream)

────────────────────────────────────────
Demux                               // 拆容器,av_read_frame (libavformat)

(Packet)                            // AVPacket(含 stream_index)

Decode                              // 解码,avcodec_send_packet / receive_frame (libavcodec)

(Frame)                             // 原始数据,AVFrame

(可选处理:缩放 / 重采样)              // swscale / swresample

Encode                              // 编码,avcodec_send_frame / receive_packet

(Packet)                            // 编码后数据

Mux                                 // 封容器,av_interleaved_write_frame (libavformat)
────────────────────────────────────────

Flush                               // avcodec_send_packet(NULL) + flush encoder

[输出文件]

🎥 视频关键属性

width / height      // 分辨率
pix_fmt             // 像素格式(YUV420P等)
bit_rate            // 码率
fps                 // 帧率
time_base           // 时间单位
gop_size            // 关键帧间隔

🎧 音频关键属性

sample_rate         // 采样率(44100 / 48000)
channels            // 声道数
channel_layout      // 声道布局
sample_fmt          // 采样格式(s16 / fltp)
bit_rate            // 码率

📦 容器属性

duration            // 时长
start_time          // 起始时间
nb_streams          // 流数量
format_name         // 容器类型

⏱️ 时间系统(重点难点)

pts(显示时间)
dts(解码时间)
time_base(时间单位)

-------------------

seconds = pts * time_base