AVFormatContext,是FFmpeg的基本结构之一,对应于封装格式(或容器格式)。

AVFormatContext与之前介绍的avstream、avcodeccontext、avcodec之间的大概关系:

FFmpeg之AVFormatContext_java

本文调试看一看AVFormatContext结构中的变量值。

同样,使用之前的示例代码,在avformat_open_input函数后下断点:

FFmpeg之AVFormatContext_java_02

可以查看avformatcontext结构中的变量值:

FFmpeg之AVFormatContext_java_03

avformatcontext中的metadata记录了多媒体文件的一些信息(比如作者、专辑之类),可以这样取得里面的信息:

            if (formatCtx->metadata) {

                AVDictionaryEntry *item = NULL;

                while((item = av_dict_get(formatCtx->metadata, "", item, AV_DICT_IGNORE_SUFFIX))){

                    printf("key:%s value:%s \n", item->key, item->value);

                }

               

// 或者这样:

                AVDictionaryEntry *tag = NULL;

                tag = av_dict_get(formatCtx->metadata, "artist", NULL, 0);

                if (tag) {

std::string artist = (char*)tag->value;

                }


avformatcontext的一些变量说明:

iformat/oformat,输入/输出格式,在解复用(解封装)或复用(封装)时使用。

pb,输入或输出场景,提供数据操作接口(比如读写、seek等)。

nb_streams,流的个数(以流的方式来复用)。

streams,流的数组。

filename,文件名。

start_time,流的起始时间,以AV_TIME_BASE为单位(除以AV_TIME_BASE转为秒)。

duration,流的时长,以AV_TIME_BASE为单位。

bit_rate,比特率。

probesize,在检测容器格式时,最大的探测大小,在avformat_open_input之前设置(或不设置使用默认值)。

max_analyze_duration,最大的分析数据的时长,在检测编码格式时使用,在avformat_find_stream_info前设置(或不设置),越大越耗时。

metadata,元信息。

https://mp.weixin.qq.com/s/8FqwlFNVCWu0k3zCmuU0jw