《FFMPEG架构简单分析》
另:gitee markdown暂不支持mermaid流程图显示,移步CSDN看完整版
作者 | 日期 |
---|---|
将狼才鲸 | 2021-08-14 |
CSDN阅读完整版:
b站其它视频:才鲸嵌入式
Gitee源码下载地址:才鲸/音视频编解码
ffmpeg源码架构
1. ffmpeg提供应用程序:
ffmpeg、ffplay、ffprobe
2. 提供库:
libavutil、libavcodec、libavformat、libavdevice、libavfilter、libswscale、libswresample、libpostproc
提供的服务
所有API讲解
开发Demo
wiki及编解码
一些书籍
An ffmpeg and SDL Tutorial
FFmpeg book 命令大全
2.1 模块依赖
3. 源码结构:
DIR compat 操作系统和数学库有关
DIR fftools ffmpeg ffplay ffprobe应用程序
DIR libavcodec 库 编解码
DIR libavdevice 库 设备
DIR libavfilter 库 滤镜
DIR libavformat 库 封装
DIR libavresample 库 音频重采样、样本格式转换和混合
DIR libavutil 库 字符串函数、随机数生成器、数据结构、附加数学函数、加密和多媒体相关
DIR libpostproc 库 用于在视频看起来很糟糕时进行视频后期处理
DIR libswresample 库 高度优化的音频重采样、样本格式转换和混合
DIR libswscale 库 高度优化的图像缩放、颜色和像素格式转换
其它的文件夹和主目录的下的文件与程序源码没有关系
4. 功能结构
AVOptions提供了通用的option设置和获取机制,可适用于任意struct(通常要求该结构体的第一个成员必须是AVClass指针,该AVClass.options必须指向一个AVOptions的静态数组,以NULL作为结束)
app | libavformat | libavcodec | libavfilter | libavutil |
---|---|---|---|---|
ffplay | Demuxing | Decoding | Buffer sink | Crypto and Hashing |
ffprobe | Muxing | Encoding | Buffer source | Mathematics |
ffmpeg | I/O Read/Write | Codecs | String Manipulation | |
Demuxers | Internal | Memory Management | ||
I/O Protocols | Core | Data Structures | ||
Internal | Utility | Video related | ||
Public Metadata API | Audio related | |||
Core functions | Error Codes | |||
Utility functions | Logging Facility |
5. 模块概述
1) libavformat
libavformat | Demuxing | Struct | |||||
---|---|---|---|---|---|---|---|
AVProbeData | AVIOContext | AVInputFormat | AVFormatContext | AVDictionary | AVProgram | AVMediaType | AVCodec |
libavformat | Demuxing | API |
---|---|---|
av_find_input_format | av_probe_input_format | av_probe_input_format2 |
av_probe_input_format3 | av_probe_input_buffer2 | av_probe_input_buffer |
avformat_open_input | av_demuxer_open | avformat_find_stream_info |
av_find_program_from_stream | av_program_add_stream_index | av_find_best_stream |
av_read_frame | av_seek_frame | avformat_seek_file |
avformat_flush | av_read_play | av_read_pause |
avformat_close_input |
libavformat | Muxing | Struct | |||||
---|---|---|---|---|---|---|---|
AVFormatContext | AVDictionary | AVPacket | AVFrame | AVOutputFormat | AVCodecID | AVMediaType |
libavformat | Muxing | API |
---|---|---|
avformat_write_header | avformat_init_output | av_write_frame |
av_interleaved_write_frame | av_write_uncoded_frame | av_interleaved_write_uncoded_frame |
av_write_uncoded_frame_query | av_write_trailer | av_guess_format |
av_guess_codec | av_get_output_timestamp |
2) libavcodec libavfilter libswscale libswresample libavdevice libavutil libpostproc
libavcodec API
Modules
Decoding
Encoding
Codecs
Internal
send/receive encoding and decoding API overview
Core functions/structures
Utility functions
libavfilter API
Modules
Buffer sink API
Buffer source API
libavutil
Modules
Crypto and Hashing
Mathematics
Mathematical utilities for working with timestamp and time base.
String Manipulation
Memory Management
Utilities for manipulating memory
Data Structures
Video related
Audio related
Error Codes
Logging Facility
Other
6. ffmpeg架构
7. ffplay架构
8. ffprobe架构
9. 驱动
- 通过ffmpeg libavdevice 打开音频设备编译时会链接错误,网上找了很多文章没有办法解决,于是干脆自己从底层直接读写音频和显示驱动。
9.1 Linux驱动
9.1.1 音频驱动
- Linux主流音频结构体ALSA,使用库libasound。
- 以前用的是OSS音频架构
- ALSA接口,proc接口,/proc/asound/
- 同时在应用层,ALSA为我们提供了alsa-lib
- /dev/snd/ 目录
- 从8.10开始,ubuntu默认声卡驱动是pulseaudio
- 编程时都使用libasound
9.1.2 显示驱动
- 早期的Linux使用ramebuffer显示框架,后面是DRM框架
- 桌面环境有gnome kde unity
- X Window System,简称X,或者X11
- OpenGl libGL
- libDRM
9.2 Windows驱动
9.3 播放和录制
- ffmpeg lib 播放与录制大全
- 播放:文件(MP4 MKV …) --解封装–> (h264 hevc mepg4…) 和 (aac mp3…) --解码–> (rgb yuv YCrCb) 和 (pcm)
- 录制:反过来
10. QEMU
- 只能在Linux环境中安装