首页 > 其他分享 >AVStream(avformat.h)

AVStream(avformat.h)

时间:2024-03-09 17:45:08浏览次数:24  
标签:stream int frame avformat int64 duration pts AVStream

AVStream是存储每一个视频/音频信息的结构体。

/**
 * Stream structure.
 * New fields can be added to the end with minor version bumps.
 * Removal, reordering and changes to existing fields require a major
 * version bump.
 * sizeof(AVStream) must not be used outside libav*.
 */
typedef struct AVStream {
    int index;    /**< stream index in AVFormatContext */
    /**
     * Format-specific stream ID.
     * decoding: set by libavformat
     * encoding: set by the user
     */
    int id;
    AVCodecContext *codec; /**< codec context */
    /**
     * Real base framerate of the stream.
     * This is the lowest framerate with which all timestamps can be
     * represented accurately (it is the least common multiple of all
     * framerates in the stream). Note, this value is just a guess!
     * For example, if the time base is 1/90000 and all frames have either
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
     */
    AVRational r_frame_rate;
    void *priv_data;
 
    /**
     * encoding: pts generation when outputting stream
     */
    struct AVFrac pts;
 
    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
     * time base should be 1/framerate and timestamp increments should be 1.
     * decoding: set by libavformat
     * encoding: set by libavformat in av_write_header
     */
    AVRational time_base;
 
    /**
     * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
     * Only set this if you are absolutely 100% sure that the value you set
     * it to really is the pts of the first frame.
     * This may be undefined (AV_NOPTS_VALUE).
     * @note The ASF header does NOT contain a correct start_time the ASF
     * demuxer must NOT set this.
     */
    int64_t start_time;
 
    /**
     * Decoding: duration of the stream, in stream time base.
     * If a source file does not specify a duration, but does specify
     * a bitrate, this value will be estimated from bitrate and file size.
     */
    int64_t duration;
 
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
 
    int disposition; /**< AV_DISPOSITION_* bit field */
 
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
 
    /**
     * sample aspect ratio (0 if unknown)
     * - encoding: Set by user.
     * - decoding: Set by libavformat.
     */
    AVRational sample_aspect_ratio;
 
    AVDictionary *metadata;
 
    /**
     * Average framerate
     */
    AVRational avg_frame_rate;
 
    /**
     * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
     * will contain the attached picture.
     *
     * decoding: set by libavformat, must not be modified by the caller.
     * encoding: unused
     */
    AVPacket attached_pic;
 
    /*****************************************************************
     * All fields below this line are not part of the public API. They
     * may not be used outside of libavformat and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */
 
    /**
     * Stream information used internally by av_find_stream_info()
     */
#define MAX_STD_TIMEBASES (60*12+5)
    struct {
        int64_t last_dts;
        int64_t duration_gcd;
        int duration_count;
        double duration_error[2][2][MAX_STD_TIMEBASES];
        int64_t codec_info_duration;
        int nb_decoded_frames;
        int found_decoder;
    } *info;
 
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
 
    // Timestamp generation support:
    /**
     * Timestamp corresponding to the last dts sync point.
     *
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
     * a DTS is received from the underlying container. Otherwise set to
     * AV_NOPTS_VALUE by default.
     */
    int64_t reference_dts;
    int64_t first_dts;
    int64_t cur_dts;
    int64_t last_IP_pts;
    int last_IP_duration;
 
    /**
     * Number of packets to buffer for codec probing
     */
#define MAX_PROBE_PACKETS 2500
    int probe_packets;
 
    /**
     * Number of frames that have been demuxed during av_find_stream_info()
     */
    int codec_info_nb_frames;
 
    /**
     * Stream Identifier
     * This is the MPEG-TS stream identifier +1
     * 0 means unknown
     */
    int stream_identifier;
 
    int64_t interleaver_chunk_size;
    int64_t interleaver_chunk_duration;
 
    /* av_read_frame() support */
    enum AVStreamParseType need_parsing;
    struct AVCodecParserContext *parser;
 
    /**
     * last packet in packet_buffer for this stream when muxing.
     */
    struct AVPacketList *last_in_packet_buffer;
    AVProbeData probe_data;
#define MAX_REORDER_DELAY 16
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
 
    AVIndexEntry *index_entries; /**< Only used if the format does not
                                    support seeking natively. */
    int nb_index_entries;
    unsigned int index_entries_allocated_size;
 
    /**
     * flag to indicate that probing is requested
     * NOT PART OF PUBLIC API
     */
    int request_probe;
} AVStream;

AVStream重要的变量如下所示:

int index:标识该视频/音频流在AVFormatContext中的索引。
int id:表示流的格式特定ID。在解码时由libavformat设置,在编码时由用户设置 
codec (ACCodecContext指针):指向编解码器上下文的指针。
r_frame_rate(AVRational):流的实际基础帧率。这是能够准确表示所有时间戳的最低帧率。
priv_data(void指针):私有数据指针。
pts(AVFrac结构体):用于输出流时的PTS生成。
time_base(AVRational):表示时间戳的基本单位(以秒为单位)。解码时由libavformat设置,在av_write_header中由libavformat设置。
start_time(int64_t):流的第一帧在呈现顺序中的PTS(演示时间基准)
duration(int64_t):流的持续时间,以流时间基准表示。
nb_frames(int64_t):如果已知,表示流中的帧数。
disposition(int):AV_DISPOSITION_*位字段,表示流的性质。
discard(AVDiscard枚举):选择可以随意丢弃的数据包。
sample_aspect_ratio(AVRational):样本宽高比。
metadata(AVDictionary指针):元数据。
avg_frame_rate(AVRational):平均帧率
attached_pic(AVPacket):用于具有AV_DISPOSITION_ATTACHED_PIC性质的流中的附加图片。
info(内部使用结构体):内部结构,用于av__find_stream_info()。
pts_wrap_bits(int):PTS位数。
reference_dts,first_dts,cur——dts,last——IP_pts,last_IP_duration(int64_t类型)时间戳生成支持相关。
probe_packets(int):用于编解码器探测的数据包流量。
codec_info_nb_frames:在av_find_stream_info()期间解混的帧数。
stream_identifier:流标识符
interleaver_chunk_size,interleaver_chunk_duration:交错块大小和持续时间。
need_parsing(AVStreamParseType枚举):av_read_frame()支持相关。
parser(AVCodecParserContext指针):解析器。
last_in_packet_buffer(AVPacketList指针):用于复用时流的最后一个包。
probe_data:探测数据。
pts_buffer:PTS缓冲区。
index_entries:仅在格式不支持本地寻址时使用。
nb_index_entries:索引条目数。
index_entries_allocated_size(unsigned int):分配给索引条目的内存大小。
request_probe(int):指示是否请求探测的标志。

以上的字段用于描述音视频流的各种属性和元数据,以便在处理和解码音视频文件时进行有效的管理和操作。

标签:stream,int,frame,avformat,int64,duration,pts,AVStream
From: https://www.cnblogs.com/doubleconquer/p/18063036

相关文章

  • AVIOContext(FFmpeg/ libavformat/ avio.h)
    AVIOContext/***BytestreamIOContext.*Newfieldscanbeaddedtotheendwithminorversionbumps.*Removal,reorderingandchangestoexistingfieldsrequireamajor*versionbump.*sizeof(AVIOContext)mustnotbeusedoutsidelibav*.**......
  • AVFormatContext介绍(avformat.h)
    typedefstructAVFormatContext结构体介绍表示解复用(解码)或复用(编码)多媒体流的格式上下文。在使用FFMPEG进行开发的时候,AVFormatContext是一个贯穿时钟的数据结构,很多函数都要用它作为参数。它是FFMPEG解封装(flv,mp4,rmvb,avi)功能的结构体。typedefstructAVFormatContext......
  • ffmpeg之avformat_alloc_output_context2
    函数原型:intavformat_alloc_output_context2(AVFormatContext**ctx,constAVOutputFormat*oformat,constchar*format_name,constchar*filename);功能:查找根据format_name或者filename或者oformat输出类型,并且初始化ctx结......
  • ffmpeg-读取媒体文件信息-avformat_open_input
    实例代码Codeintvideo_audio_info(intargc,char*argv[]){ if(argc<2){ printf("Usage:%smediaFile\n",argv[0]); return-1; } AVFormatContext*ic=NULL; charpath[20]={0}; strcpy(path,argv[1]); //1.打开媒体文件 intret=avfo......
  • FFmpeg之AVFormat
    (目录)一、概述  avformat中实现了目前多媒体领域中的几乎所有封装格式,可以封装,可以解封装(也叫解复用),根据需求不同,所支持的也有所不同,ffmpeg能否支持一种封装格式的视频的封装与解封装,完全取决于这个库,例如mp4、flv、mkv等容器的封装与解封装;又或者RTMP、RTSP、TCP、UDP等协议......
  • Python报错:pkg-config could not find libraries ['avformat', 'avcodec', 'av
    参考:https://github.com/PyAV-Org/PyAV/issues/238https://pyav.org/docs/6.1.2/installation.html#mac-os-x  =====================  报错信息:C:\Users\liuxue>pipinstallavCollectingavUsingcachedav-0.3.3.tar.gzInstallingcollectedpackages:avRunning......
  • Python报错:pkg-config could not find libraries ['avformat', 'avcodec', 'avdev
    参考:https://github.com/PyAV-Org/PyAV/issues/238https://pyav.org/docs/6.1.2/installation.html#mac-os-x  =====================  报错信息:C:\Users\liuxue>pipinstallavCollectingavUsingcachedav-0.3.3.tar.gzInstallingcollectedpackages:av......
  • avformat_network_init()解析备忘
    基于ffmpeg-6.0.avformat_network_init()函数定义如下:intavformat_network_init(void){#ifCONFIG_NETWORKintret;if((ret=ff_network_init())<0)returnret;if((ret=ff_tls_init())<0)returnret;#endifreturn0;}可以......
  • 关于FFmpeg释放 AVFormatContext*解码上下文的一些问题
    关于FFmpeg释放AVFormatContext*解码上下文的一些问题FFmpeg的一些常用函数用途结构体释放解码上下文FFmpeg的一些常用函数用途av_register_all()注册所有组件。avformat_open_input()打开输入视频文件。avformat_find_stream_info()获取视频文件信息。avcodec_find_d......
  • ffmpeg使用avformat_close_input()函数释放结构体时崩溃的问题
    先看一下我调试时,发现程序崩溃的代码位置  //这是我的程序释放流上下文时的操作 if(m_pAvFormatContext) { //释放视频解码器上下文 if(m_iVideoStreamIndex>=0) avcodec_free_context(&m_pVideoDecodeContext);//此处是发生崩溃......