首页 > 其他分享 >AVFormatContext介绍(avformat.h)

AVFormatContext介绍(avformat.h)

时间:2024-03-09 09:55:05浏览次数:16  
标签:AVFMT struct AVFormatContext int 介绍 avformat FLAG value define

typedef struct AVFormatContext结构体介绍

表示解复用(解码)或复用(编码)多媒体流的格式上下文。在使用FFMPEG进行开发的时候,AVFormatContext是一个贯穿时钟的数据结构,很多函数都要用它作为参数。它是FFMPEG解封装(flv,mp4,rmvb,avi)功能的结构体。

typedef struct AVFormatContext {
    const AVClass *av_class;//指向AVOptions和日志记录的AVClass结构的指针,用于AVOptions和日志记录
    struct AVInputFormat *iformat;//指向输入格式的指针。
    struct AVOutputFormat *oformat;//指向输出格式的指针。
    void *priv_data;//格式私有数据,一个AVOptions的结构。
    AVIOContext *pb;//格式的I/O上下文
    unsigned int nb_streams;//文件中流的信息
    AVStream **streams;//文件中的信息
    char filename[1024];//输入或输出文件名 
    int64_t start_time;//有关流的时间信息
    int64_t duration;//有关流的时间信息
    int bit_rate;//总流比特率
    unsigned int packet_size;//数据包大小
    int max_delay;//最大延迟
    int flags;//标志位,指示各种格式相关的属性,如是否生成pts、是否忽略索引等。
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
#define AVFMT_FLAG_NOPARSE      0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
#define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
#define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
#define AVFMT_FLAG_MP4A_LATM    0x8000 ///< Enable RTP MP4A-LATM payload
#define AVFMT_FLAG_SORT_DTS    0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
#define AVFMT_FLAG_PRIV_OPT    0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
#define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it separate
    unsigned int probesize;//数据探测大小
    int max_analyze_duration;//最大分析时长
    const uint8_t *key;//密钥
    int keylen;//密钥长度
    unsigned int nb_programs;//文件中程序的数量
    AVProgram **programs;//指向AVProgram指针数组的指针,表示文件中的所有程序。
    enum CodecID video_codec_id;//视频编码器ID
    enum CodecID audio_codec_id;//音频编码器ID
    enum CodecID subtitle_codec_id;//字幕编解码器ID
    unsigned int max_index_size;//最大索引大小
    unsigned int max_picture_buffer;//最大图像缓冲区大小
    unsigned int nb_chapters;//文件中章节的数量
    AVChapter **chapters;//指向AVChapter指针数组的指针,表示文件中的所有章节
    AVDictionary *metadata;//元数据
    int64_t start_time_realtime;//实际开始时间
    int fps_probe_size;//fps探测大小
    int error_recognition;//错误识别
    AVIOInterruptCB interrupt_callback;//I/O中断回调函数
    int debug;//调试标志
#define FF_FDEBUG_TS        0x0001
    int ts_id;//传输流ID
    int audio_preload;//音频预加载
    int max_chunk_duration;//最大块时长
    int max_chunk_size;//最大块大小
    struct AVPacketList *packet_buffer;//数据包缓冲区
    struct AVPacketList *packet_buffer_end;//数据包缓冲区末尾
    int64_t data_offset; //数据偏移量
    struct AVPacketList *raw_packet_buffer;//原始数据包缓冲区剩余大小
    struct AVPacketList *raw_packet_buffer_end;
    struct AVPacketList *parse_queue;
    struct AVPacketList *parse_queue_end;
#define RAW_PACKET_BUFFER_SIZE 2500000
    int raw_packet_buffer_remaining_size;
} AVFormatContext;

其中最重要的结构是

AVIOContext *pb //输入数据的缓冲
unsigned int nb_streams//视音频的个数
AVStream **streams//视音频流
char filename[1024]://文件名
int_64 duration:时长(单位:微秒us,转换为秒需要除以100000)
int bit_rate:比特率(单位bps,转换为kbps需要除以1000)
AVDictionary *metadata//元素据

视频的时长可以转换HH::MM::SS的形式,示例代码如下:

AVFormatContext *pFormatCtx;
CString timelong;
int tns,thh,tmm,tss;
tns = (pFormatCtx->duration)/1000000;
thh = tns / 3600
tmm = (tns % 3600)/60;
tss = (tns % 60);
timelong.Format("%02d:%02d:%02d",thh,tmm,tss);

视频的原数据(metadata)信息可以通过AVDictionary获取。元数据存储在AVDictionaryEntry结构体中,如下所示

typedef struct AVDictionaryEntry{
      char *key;
      char *value;
}AVDictionaryEntry;

每一条元数据分为key和value两个属性
在ffmpeg中通过av_dict_get()函数获得视频的原数据。
.下列代码显示获取元数据并存入meta字符串变量的过程,注意每一条key和value之间有一个"\t",value之后有一个"\r\n"

//MetaData------------------------------------------------------------
//从AVDictionary获得
//需要用到AVDictionaryEntry对象
//CString author,copyright,description;
CString meta=NULL,key,value;
AVDictionaryEntry *m = NULL;
//不用一个一个找出来
/*	m=av_dict_get(pFormatCtx->metadata,"author",m,0);
author.Format("作者:%s",m->value);
m=av_dict_get(pFormatCtx->metadata,"copyright",m,0);
copyright.Format("版权:%s",m->value);
m=av_dict_get(pFormatCtx->metadata,"description",m,0);
description.Format("描述:%s",m->value);
*/
//使用循环读出
//(需要读取的数据,字段名称,前一条字段(循环时使用),参数)
while(m=av_dict_get(pFormatCtx->metadata,"",m,AV_DICT_IGNORE_SUFFIX)){
	key.Format(m->key);
	value.Format(m->value);
	meta+=key+"\t:"+value+"\r\n" ;
}

标签:AVFMT,struct,AVFormatContext,int,介绍,avformat,FLAG,value,define
From: https://www.cnblogs.com/doubleconquer/p/18061950

相关文章

  • java17新特性简单介绍
    前言本项目使用的IDE为IDEA2023.3.3(社区版)。文本块java17之前的写法,双引号需要转义,换行需要\n,需要加号拼接publicclassTestString{publicstaticvoidmain(String[]args){Stringjson="{\n"+"\"id\":\"1\",\n&qu......
  • netcat 命令介绍及使用示例
    netcat命令介绍及使用示例nc(netcat)是一个强大的网络工具,它可以用于读取和写入数据流,支持TCP和UDP协议。它常被用于网络调试和网络服务的创建。一、安装方法centos中,执行yuminstallncprocps-ng-y二、功能介绍1.IP端口监控使用nc进行端口扫描可以检查指定主机的......
  • (笔记)Vivado操作之时序约束介绍
     一、前言      任何一个FPGA工程都需要设置相关的时序约束,下面将介绍Vivado中如何进行时序约束操作以及各种约束的使用方法。 二、时序约束界面        在一个工程运行到IMPLEMENTATION后,进入到左侧的FlowNavigator窗口,点击IMPLEMENTION下的EditConstraint......
  • 57WebAssembly逆向介绍
     当涉及到使用爬虫技术时,选择pywasm还是wasmer-python主要取决于你的具体需求、目标网站的复杂性和性能要求。以下是对这两个库在爬虫场景下的方便性对比:pywasm方便性:PythonicAPI:pywasm提供了符合Python风格的API,对于Python开发者来说可能更加直观和易于使用。集成性......
  • Hbase介绍
    什么是HbaseHbase是一个高可靠、高性能、面向列、可伸缩的分布式存储系统,利用Hbase技术可在廉价的PCServer上搭建大规模结构化存储集群。利用HadoopHDFS作为其文件存储系统,利用HadoopMapReduce来处理Hbase中的海量数据,利用Zookeeper作为其分布式协同服务主要......
  • sqlite.dll介绍,sqlite.dll文件缺失的解决方法,3分钟快速修复sqlite.dll
    第一次见到这个dll,一般是找到这个dll,重新引用下。网上找到了关于这个dll的详细解释,其他dll应该也可以用这些方法修复,在此记录下。原文链接:https://zhuanlan.zhihu.com/p/668219472一.什么是SQLite.dllSQLite.dll是SQLite数据库引擎的一个关键组成部分。(SQLite是一个开源的嵌......
  • POSTGRESQL (PG) 6种索引类型介绍以及使用实例
    Postgresql中主要支持6种类型的索引:BTREE、HASH、GiST、SP-GiSP、GIN、BRIN。可以根据实际的应用场景选择合适的索引,BTREE、HASH是比较常用的索引。1.BTREE索引:CREATEINDEX默认使用BTREE索引,适合按照顺序存储的数据进行比较查询和范围查询,查询优化器会优先考虑使用BTREE索引,如......
  • Dash 2.16版本新特性介绍
    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/dash-master大家好我是费老师,几天前Dash发布了其2.16.0版本,随后在修复了一些潜在问题后,于今天发布了可稳定使用的2.16.1版本,执行下面的命令进行最新版本Dash的安装:pipinstalldash-U2.16版本中为......
  • Subversion svn 开源的版本控制系统入门介绍 VCS
    拓展阅读Subversion开源的版本控制系统入门介绍VCSGit开源的版本控制系统-01-入门使用介绍Git开源的版本控制系统-02-baseusage基本用法Git开源的版本控制系统-03-时间数据回溯Git开源的版本控制系统-04-branchmanage分支管理Git开源的版本控制系统-05-tags标签......
  • TIDB使用介绍
    TiDB概述TiDB数据库官方网址:https://pingcap.com/zh/​TiDB是PingCAP公司自主设计、研发的开源分布式关系型数据库,是一款同时支持在线事务处理与在线分析处理(HybridTransactionalandAnalyticalProcessing,HTAP)的融合型分布式数据库产品,具备水平扩容或者缩容、金融......