分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
=====================================================
FFmpeg的库函数源代码分析文章列表:
【架构图】
【通用】
FFmpeg 源代码简单分析:av_register_all()
FFmpeg 源代码简单分析:avcodec_register_all()
FFmpeg 源代码简单分析:内存的分配和释放(av_malloc()、av_free()等)
FFmpeg 源代码简单分析:常见结构体的初始化和销毁(AVFormatContext,AVFrame等)
FFmpeg 源代码简单分析:av_find_decoder()和av_find_encoder()
FFmpeg 源代码简单分析:avcodec_open2()
FFmpeg 源代码简单分析:avcodec_close()
【解码】
图解FFMPEG打开媒体的函数avformat_open_input
FFmpeg 源代码简单分析:avformat_open_input()
FFmpeg 源代码简单分析:avformat_find_stream_info()
FFmpeg 源代码简单分析:av_read_frame()
FFmpeg 源代码简单分析:avcodec_decode_video2()
FFmpeg 源代码简单分析:avformat_close_input()
【编码】
FFmpeg 源代码简单分析:avformat_alloc_output_context2()
FFmpeg 源代码简单分析:avformat_write_header()
FFmpeg 源代码简单分析:avcodec_encode_video()
FFmpeg 源代码简单分析:av_write_frame()
FFmpeg 源代码简单分析:av_write_trailer()
【其它】
FFmpeg源代码简单分析:日志输出系统(av_log()等)
FFmpeg源代码简单分析:结构体成员管理系统-AVClass
FFmpeg源代码简单分析:结构体成员管理系统-AVOption
FFmpeg源代码简单分析:libswscale的sws_getContext()
FFmpeg源代码简单分析:libswscale的sws_scale()
FFmpeg源代码简单分析:libavdevice的avdevice_register_all()
FFmpeg源代码简单分析:libavdevice的gdigrab
【脚本】
【H.264】
=====================================================
本文简单分析FFmpeg常见结构体的初始化和销毁函数的源代码。常见的结构体在文章:
《FFMPEG中最关键的结构体之间的关系》中已经有过叙述,包括:
AVFormatContext:统领全局的基本结构体。主要用于处理封装格式(FLV/MKV/RMVB等)。
AVIOContext:输入输出对应的结构体,用于输入输出(读写文件,RTMP协议等)。
AVStream,AVCodecContext:视音频流对应的结构体,用于视音频编解码。
AVFrame:存储非压缩的数据(视频对应RGB/YUV像素数据,音频对应PCM采样数据)
AVPacket:存储压缩数据(视频对应H.264等码流数据,音频对应AAC/MP3等码流数据)
他们之间的关系如下图所示(详细信息可以参考上文提到的文章)。
下文简单分析一下上述几个结构体的初始化和销毁函数。这些函数列表如下。
结构体 |
初始化 |
销毁 |
AVFormatContext |
avformat_alloc_context() |
avformat_free_context() |
AVIOContext |
avio_alloc_context() |
|
AVStream |
avformat_new_stream() |
|
AVCodecContext |
avcodec_alloc_context3() |
|
AVFrame |
av_frame_alloc(); av_image_fill_arrays() |
av_frame_free() |
AVPacket |
av_init_packet(); av_new_packet() |
av_free_packet() |
下面进入正文。
AVFormatContext
AVFormatContext的初始化函数是avformat_alloc_context(),销毁函数是avformat_free_context()。avformat_alloc_context()
avformat_alloc_context()的声明位于libavformat\avformat.h,如下所示。
/** * Allocate an AVFormatContext. * avformat_free_context() can be used to freethe context and everything * allocated by the framework within it. */AVFormatContext*