`

FFMPEG结构体分析:AVStream

 
阅读更多

 

注:写了一系列的结构体的分析的文章,在这里列一个列表:

FFMPEG结构体分析:AVFrame
FFMPEG结构体分析:AVFormatContext
FFMPEG结构体分析:AVCodecContext
FFMPEG结构体分析:AVIOContext
FFMPEG结构体分析:AVCodec
FFMPEG结构体分析:AVStream
FFMPEG结构体分析:AVPacket

 

FFMPEG有几个最重要的结构体,包含了解协议,解封装,解码操作,此前已经进行过分析:

FFMPEG中最关键的结构体之间的关系

在此不再详述,其中AVStream是存储每一个视频/音频流信息的结构体。本文将会分析一下该结构体里重要变量的含义和作用。

首先看一下结构体的定义(位于avformat.h文件中):

 

/* 雷霄骅
 * 中国传媒大学/数字电视技术
 * leixiaohua1020@126.com
 *
 */
/**
 * 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:标识该视频/音频流

AVCodecContext *codec:指向该视频/音频流的AVCodecContext(它们是一一对应的关系)

AVRational time_base:时基。通过该值可以把PTS,DTS转化为真正的时间。FFMPEG其他结构体中也有这个字段,但是根据我的经验,只有AVStream中的time_base是可用的。PTS*time_base=真正的时间

int64_t duration:该视频/音频流长度

AVDictionary *metadata:元数据信息

AVRational avg_frame_rate:帧率(注:对视频来说,这个挺重要的)

AVPacket attached_pic:附带的图片。比如说一些MP3,AAC音频文件附带的专辑封面。

该结构体其他字段的作用目前还有待于探索。

 



 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    FFmpeg基础库编程开发

    4.9 AVStream结构体 64 4.10 MOVStreamContext 结构体 65 4.11 AVPacket 结构体 66 4.12 AVPacketList 结构体 67 4.13 AVFrame结构体 67 第五章 重要模块 76 5.1 libavutil公共模块 76 1 文件列表 76 2 common.h ...

    ffmpeg截图代码

    - 示例代码可能包括创建AVFormatContext,解析输入流,获取AVStream,解码视频帧,然后使用AVFrame和AVPicture结构体来保存图片数据。 6. 面临的挑战: - 并发处理:如果需要对大量视频进行截图,需要考虑多线程...

    FFMpeg SDK 开发手册

    9. AVStream:AVStream代表了媒体中的一个单独的流(音视频流),它包括了编解码器的上下文、时间戳基准和解复用信息等。 在进行FFmpeg开发时,一些重要的初始化函数包括: - av_register_all():这个函数用于注册...

    ffmpeg基础库编程开发_add_notes.pdf

    - **AVStream结构体**: 描述单个流的信息。 - **MOVStreamContext结构体**: MOV流上下文。 - **AVPacket结构体**: 包含单个编码数据包。 - **AVPacketList结构体**: AVPacket的链表结构。 - **AVFrame结构体**: 包含...

    ffmpeg基础开发资料自总结

    4.9 AVStream 结构体 65 4.10 MOVStreamContext 结 构体 66 4.11 AVPacket 结 构体 67 4.12 AVPacketList 结 构体 67 4.13 AVFrame 结构体 53 第五章 重要模块 68 5.1 libavutil 公共模块 68 1 文件列表 68 2 common...

    FFmpeg:YUV转H264,(内存中)H264保存flv

    你需要创建一个`AVFormatContext`,`AVStream`,`AVPacket`等结构体,然后按照FFmpeg的流程进行处理。 在处理车牌识别一体机的数据时,可能需要对接其提供的SDK。这通常涉及到注册设备、接收实时视频流、调用SDK...

    Understanding FFmpeg with source code FFMPEG Fundementals.7z

    数据结构:介绍了FFmpeg中的关键数据结构,如AVFormatContext、AVStream、AVCodecContext、AVPacket、AVIOContext等,这些结构体用于描述多媒体文件、媒体流、编解码器上下文、数据包和I/O操作。 时间信息:讨论了...

    FFMPEG中文基础教程

    2. **FFmpeg关键结构体分析** - **解协议**:`AVIOControl`、`URLProtocol`和`URLContext`用于处理各种输入输出协议,如HTTP、RTSP、RTMP和MMS。`URLProtocol`定义了特定协议的处理函数,而`URLContext`则存储了与...

    雷神的代码FFMpeg 实现音视频剪切(无编解码)

    FFmpeg 提供了 `AVStream` 结构体,其中的 `pts` 和 `duration` 字段可以用于计算。 4. **创建输出文件** 使用 `avformat_alloc_output_context2()` 创建一个新的输出上下文,指定输出的容器格式。之后,添加输入...

    QT使用FFmpeg库实现视频流播放

    此函数需要指定文件路径或URL,以及一个AVFormatContext结构体指针。 ```cpp AVFormatContext* formatContext = nullptr; if (avformat_open_input(&formatContext, "path_to_video", nullptr, nullptr) != 0) { /...

    FFMpeg SDK 开发手册(中文)

    8. AVStream:代表媒体流中的单个数据流(音频、视频或字幕),它包含了流的编解码器参数、持续时间等信息。 在使用FFMpeg进行开发前,需要进行一系列初始化步骤。主要包括: 1. av_register_all():注册所有的编...

    FFmpeg cpp 实例代码

    在C++环境中使用FFmpeg,可以方便地进行音视频处理和分析。本实例代码提供了FFmpeg与C++结合的具体应用,帮助开发者更好地理解和运用FFmpeg库。 在FFmpeg_CPP-master这个压缩包中,你将找到一系列C++源代码,这些...

    库函数ffmpeg

    - **AvStream**:流结构体,代表一个具体的音视频流。 - **sample_rate**:采样率,对于音频流来说是每秒采样的次数。 - **time_base**:时间基准,用于计算实际的时间戳。 - **channels**:通道数,对于立体声来说...

    ffmpeg视频解码示例代码

    通过对源代码的分析,我们可以学习到 FFmpeg 如何与操作系统交互,如何处理多媒体数据,以及如何利用硬件加速等功能。这不仅对理解 FFmpeg 工作原理有帮助,也为开发自定义的多媒体应用提供了基础。

    ffmpeg开发学习笔记

    - `.streams`: 流数组,每个元素都是一个`AVStream`结构体。 - `.timestamp`: 时间戳。 - `.start_time`: 开始时间。 - `.duration`: 媒体文件的总持续时间。 - `.file_size`: 文件大小。 - `.bit_rate`: ...

    FFmpeg_C#_Demo_vs2017.zip

    1. **初始化FFmpeg**:创建必要的FFmpeg上下文,如AVFormatContext、AVStream等,以解析和处理RTSP流。 2. **连接RTSP服务器**:通过libavformat库中的函数建立到RTSP服务器的连接,获取媒体流信息。 3. **数据...

    C++基于FFmpeg的音频解码和播放

    音频流可以通过检查`AVStream`结构体的`codecpar-&gt;codec_type`字段为`AVMEDIA_TYPE_AUDIO`来识别。 4. **初始化解码器**:使用`avcodec_find_decoder`找到与音频流对应的解码器,然后用`avcodec_alloc_context3`...

    ffmpeg基础库编程开发

    数据结构部分深入介绍了FFmpeg框架中使用的关键数据结构,例如AVCodec结构体用于存储编解码器相关的信息,AVFormatContext结构体存储关于媒体文件格式的信息,AVIOContext结构体是I/O操作的上下文,AVStream结构体...

    ffmpeg初级教程

    4. **音视频同步**: 依赖 `AVPacket` 和 `AVFrame` 结构体进行数据处理,注意使用 `AVStream` 的 `pts` 和 `dts` 来确保音视频同步。 三、FFmpeg SDK 基本使用 1. **获取 SDK**: 通常可以从 FFmpeg 官方网站下载...

Global site tag (gtag.js) - Google Analytics