• FFMPEG笔记


    # FFMPEG结构体和函数笔记

    FFMPEG 是一套可以用来记录,转换数字音频,视频,并能将其转化为流的开源计算机程序

    入门前辈:雷神——雷霄骅

    雷霄骅个人简介:

             雷霄骅,,中国传媒大学通信与信息系统专业博士生,荣获2014、2015年度CSDN博客之星,2015年于美国微软总部荣膺微软大中华区MVP称号。

             2016年7月 16日晚9点多进实验室,凌晨3时倒在电梯口,时年26岁。

             各个网站论坛对雷神去世一事评论:

    1. https://www.zhihu.com/question/49211380 
    2. https://blog.csdn.net/machh/article/details/52109231?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160430564019725222416930%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160430564019725222416930&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v28-2-52109231.pc_first_rank_v2_rank_v28&utm_term=%E9%9B%B7%E9%9C%84%E9%AA%85&spm=1018.2118.3001.4449      
    3.  https://www.cnblogs.com/huxiaopeng/p/5735354.html     

    雷霄骅个人CSDN专栏: https://blog.csdn.net/leixiaohua1020       

    知乎: https://blog.csdn.net/machh/article/details/52109231?ops_request_misc=%257B%2522req   uest%255Fid%2522%253A%2522160430564019725222416930%2522%252C%2522scm%25        22%253A%252220140713.130102334..%2522%257D&request_id=16043056401972522241 ank_v28-2-52109231.pc_first_rank_v2_rank_v28&utm_term=%E9%9B%B7%E9%9C%84%E9      %AA%85&spm=1018.2118.3001.4449  

    OSCHINA::https://my.oschina.net/leixiaohua1020     

         

    FFMPEG源代码结构图

    链接:https://img-my.csdn.net/uploads/201503/12/1426134989_1189.jpg      

    FFMPEG官方文档:https://www.ffmpeg.org/doxygen/4.1/index.html      

    一.结构体

    链接:https://blog.csdn.net/leixiaohua1020/article/details/41181155

    详细链接:https://blog.csdn.net/leixiaohua1020/article/details/11693997

    AVFormatContext:统领全局的基本结构体。主要用于处理封装格式(FLV/MKV/RMVB等)。

    AVIOContext:输入输出对应的结构体,用于输入输出(读写文件,RTMP协议等)。

    AVCodec:

    AVStream,AVCodecContext:视音频流对应的结构体,用于视音频编解码。

    AVFrame:存储非压缩的数据(视频对应RGB/YUV像素数据,音频对应PCM采样数据)

    AVPacket:存储压缩数据(视频对应H.264等码流数据,音频对应AAC/MP3等码流数据)

    二.函数解析

    1. av_register_all()

    函数体:void av_register_all(void);

    函数功能:注册解码器,复用器等

    官方:av_register_all() to register all compiled muxers, demuxers and protocols.

    总结:必须第一个调用,但4.0版本已经弃用

    链接:https://blog.csdn.net/leixiaohua1020/article/details/12677129

    1. avdevice_register_all()

    函数体:void avdevice_register_all(void);

    函数功能:对设备进行注册

    官方:* To use libavdevice, simply call avdevice_register_all() to register all

            * compiled muxers and demuxers. They all use standard libavformat API.

     * @}

       总结:调用摄像头之类设备必须先对设备进行注册

       链接:https://blog.csdn.net/leixiaohua1020/article/details/41211121

    1. avformat_network_init()

    函数体:int avformat_network_init(void);

    函数功能:初始化网络库以及网络加密协议相关的库(openssl)

    官方:Undo the initialization done by avformat_network_init.

    总结:在使用rtsp等网络视频流时使用

    链接:https://blog.csdn.net/leixiaohua1020/article/details/12677265

    1. avformat_alloc_context()

    函数体:AVFormatContext *avformat_alloc_context(void);

    函数功能:负责申请一个AVFormatContext结构的内存,并进行简单初始化

    官方:To create an * AVFormatContext, use avformat_alloc_context

    总结:AVFormatContext的初始化函数,对应的销毁函数为avformat_free_context()

    链接:https://blog.csdn.net/leixiaohua1020/article/details/41181155

    1. avformat_open_input()

    函数体:int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);

    参数说明:

    ps:函数调用成功之后处理过的AVFormatContext结构体。
    file:打开的视音频流的URL。
    fmt:强制指定AVFormatContext中AVInputFormat的。这个参数一般情况下可以设置为NULL,这样FFmpeg可以自动检测AVInputFormat。

    dictionay:附加的一些选项,一般情况下可以设置为NULL。

    函数功能:打开输入视频文件

    官方:

    总结:函数执行成功,返回值>=0

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44064715 

    1. av_dump_format()

    函数体:void av_dump_format(AVFormatContext *ic,int index,const char *url,   int is_output)

    函数功能:打印关于输入和输出格式的详细信息,检查下初始化过程中设置的参数是否符合规范

    官方参数说明:

     * @param ic already initialized Format Context, must not be NULL.

     * @param index index of the stream to dump information about

     * @param url name of file or URL of stream to print information about

     * @param is_output Select whether specified context is of input(0) or output(1)

    总结: 输出详细信息

    链接:https://blog.csdn.net/yao_hou/article/details/104102235   

    1. avformat_find_stream_info()

    函数体:int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);

    函数功能:读取一部分视音频数据获取相关信息,位于libavformat\avformat.h

    官方:

                * @param ic    media file handle

                 * @param last  the last found program, the search will start after this

                *              program, or from the beginning if it is NULL

                * @param s     stream index

                * @return the next program which belongs to s, NULL if no program is found or

                * the last program is not among the programs of ic.

    总结: 读取信息,函数执行成功,返回值值大于等于0

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44084321

    1. avcodec_find_decoder()

    函数体:AVCodec *avcodec_find_decoder(enum AVCodecID id);

    函数功能:查找FFMPEG的解码器

    官方:

             * Find a registered decoder with a matching codec ID.

             * @param id AVCodecID of the requested decoder

          * @return A decoder if one was found, NULL otherwise.

    总结: 根据ID找到对应的解码器,也可使用avcodec_find_decoder_by_name()

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44084557 

    1. avcodec_open2()

    函数体:int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

    函数功能:初始化一个视音频解码器的AVCodecContext,位于libavcodec\avcodec.h

    参数:

    codec:输入的AVCodec
           options:一些选项。例如使用libx264编码的时候,“preset”,“tune”等都可以通过该参 数设置。

    总结: 初始化解码器格式

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44117891     

    1. av_frame_alloc()

    函数体:AVFrame *av_frame_alloc(void);

    函数功能:分配AVFrame内存空间

    官方:

             * Allocate an AVFrame and set its fields to default values.  The resulting

             * struct must be freed using av_frame_free().

          * @return An AVFrame filled with default values or NULL on failure.

    总结: 分配内存空间

    链接:https://blog.csdn.net/qq_25333681/article/details/89743660

    11.sws_getContext()

    函数体:初始化一个SwsContext

        struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,

                                      int dstW, int dstH, enum AVPixelFormat dstFormat,

                                      int flags, SwsFilter *srcFilter,

                                  SwsFilter *dstFilter, const double *param);

    函数功能:初始化一个SwsContext,为图像处理做准备

    官方:* @param srcW the width of the source image

             * @param srcH the height of the source image

             * @param srcFormat the source image format

             * @param dstW the width of the destination image

             * @param dstH the height of the destination image

             * @param dstFormat the destination image format

             * @param flags specify which algorithm and options to use for rescaling

          * @return a pointer to an allocated context, or NULL in case of error

    总结:后三个常见为NULL

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44305697 

    1. av_read_frame()

    函数体:

    函数功能:

    官方:

    总结:

    链接:

    1. avcodec_decode_video2()

    函数体:

    函数功能:

    官方:

    总结:

    链接:

    1. sws_scale()

    函数体: int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],

                           const int srcStride[], int srcSliceY, int srcSliceH,

                   uint8_t *const dst[], const int dstStride[]);

    函数功能:处理图像数据

    官方:

             * @param c         the scaling context previously created with

             *                  sws_getContext()

             * @param srcSlice  the array containing the pointers to the planes of

             *                  the source slice

             * @param srcStride the array containing the strides for each plane of

             *                  the source image

             * @param srcSliceY the position in the source image of the slice to

             *                  process, that is the number (counted starting from

             *                  zero) in the image of the first row of the slice

             * @param srcSliceH the height of the source slice, that is the number

             *                  of rows in the slice

             * @param dst       the array containing the pointers to the planes of

             *                  the destination image

             * @param dstStride the array containing the strides for each plane of

             *                  the destination image

             * @return          the height of the output slice

    总结: 图像处理执行函数

    链接:https://blog.csdn.net/leixiaohua1020/article/details/44346687 

    15.avpicture_fill()

    函数体:int avpicture_fill(AVPicture *picture, const uint8_t *ptr,

                     enum AVPixelFormat pix_fmt, int width, int height);

    函数功能:将ptr指向的数据填充到picture内,但并没有拷贝,只是将picture结构内的data指针指向了ptr的数据

    官方:

         @param dst_data         要填充的数据指针

         @param dst_linesize     dst_data中要被填充的线条大小(即linesize, 行宽)

         @param src              包含实际图像的缓冲区(可以为空).

         @param pix_fmt          图像的像素格式

         @param width         图像的像素宽度

         @param height            图像的像素高度

         @param align         在src中用于行宽对齐的值

         @return the size in bytes required for src, a negative error code in case of failure

                 该函数返回src所需的大小(以字节为单位), 失败时返回一个负数(错误代码).

    总结:在FFMPEG4.2.2被抛弃,被av_image_fill_arrays()替代

    链接:https://blog.csdn.net/macmacip/article/details/105463390?utm_medium=distribute.pc_relevant.none-task-blog-title-3&spm=1001.2101.3001.4242

    16.av_free_packt()

    函数体:void av_free_packet(AVPacket *pkt);

    函数功能:释放AVPacket对象

    官方:@param pkt packet to free

    总结:

    链接:

    17.XXXXXX

    函数体:

    函数功能:

    官方:

    总结:

    链接:

     

    Demo程序学习

    1.100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)

     https://blog.csdn.net/leixiaohua1020/article/details/8652605  

    2.

    图像视频编码和FFMPEG学习

    1. luotuo44  https://blog.csdn.net/luotuo44/category_2275719.html  
    2. 雷霄骅  https://blog.csdn.net/leixiaohua1020/article/details/15811977    
  • 相关阅读:
    微软面试题_中文字符串转换为数字
    微软面试题_3个字母的组合
    LeetCode Notes_#1031_两个非重叠子数组的最大和
    剑指Offer_#57-II_和为 s 的连续正数序列
    LeetCode Notes_#560 和为k的子数组
    LeetCode Notes_#84 柱状图中最大的矩形
    LeetCode Notes_#221 最大正方形
    LeetCode Notes_#146 LRU缓存机制
    码云团队开发项目拉取与推送
    vue父子组件的双向绑定
  • 原文地址:https://www.cnblogs.com/guapilsh/p/13915323.html
Copyright © 2020-2023  润新知