FFmpeg常用结构体分析(二):AVStream

文章首发于我的个人博客

我们在分析AVFormatContext结构的时候提到其中的一个成员streams。使用该成员我们就可以得到AVStream对象。

unsigned int nb_streams;

AVStream** streams;

nb_streams是当前轨道数,就是流数量,streams是轨道的指针数组。一般而言一个视频文件会有一个视频流和一个音频流,那就是两个AVStream结构。

对于AVStream,我们常用的成员有:

//(1)标识该视频/音频流
int index;

//(2)指向该音频/视频流的AVCodecContext(已被废弃,不推荐使用)
AVCodecContext* codec;

//(3)获得AVCodecParameters对象,用于替代AVCodecContext(推荐使用)
AVCodecParameters* codecpar;

//(4)该视频长度;
int64_t duration;	

//(5)视频平均帧率
AVRational avg_frame_rate;
//其中,AVRational表示有理数,他有两个参数
//avg_frame_rate.num : 分子
//avg_frame_rate.den : 母
//平均帧率 = avg_frame_rate.num / avg_frame_rate.den

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, replaced by libavformat if left unset
     */
    int id;
#if FF_API_LAVF_AVCTX
    /**
     * @deprecated use the codecpar struct instead
     */
    attribute_deprecated
    AVCodecContext *codec;
#endif
    void *priv_data;

    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented.
     *
     * decoding: set by libavformat
     * encoding: May be set by the caller before avformat_write_header() to
     *           provide a hint to the muxer about the desired timebase. In
     *           avformat_write_header(), the muxer will overwrite this field
     *           with the timebase that will actually be used for the timestamps
     *           written into the file (which may or may not be related to the
     *           user-provided one, depending on the format).
     */
    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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值