AVStream和AVCodecParameters
说明:
AVStream 结构表示当前媒体流的上下文,着重于所有媒体流共有的属性(并且是在程序运行时才能确定其值)和关联其他结构的字段。 其中codecpar成员里存储了当前音视频媒体使用的编解码器信息; priv_data 成员关联解析各个具体媒体流解复用拆包用的 context;还有关键帧的索引表index_entries成员也存于此。
typedef struct AVStream
{ AVCodecContext *codec; //指向解码器 context,新版本已过时 AVCodecParameters *codecpar; //AVCodecContext解码结构体的结构体参数,解码之前都需要通过它来初始化AVCodecContext. void *priv_data; //指向解复用的流的 context,比如 mp4 的 MovStreamcontext AVRational time_base;
.
AVRational avg_frame_rate;
//音频频帧速率(1s多少帧,对于音频时,该值可能是个浮点数,比如44.1khz, 每一帧里有channel*frame_size个样本数据,
那么帧率为441000/frame_size) AVIndexEntry *index_entries; //用于 seek (滑动至指定位置播放)时使用,用于快速索引关键帧,
如 flv 的 keyframes 索引表和 mp4 的 I帧的索引表都存于此,很重要 int nb_index_entries; //index_entries 的元素的个数
int index_entries_allocated_size;
double frame_last_delay; } AVStream;

其中,AVCodecParameters结构体与AVCodecContext里的参数有很多相同的成员,如下所示:

typedef struct AVCodecParameters {

enum AVMediaType codec_type; //编解码器的类型(视频,音频...)

enum AVCodecID codec_id; //标示特定的编解码器,通过该id号可以来找到AVCodec
/**
* Additional information about the codec (corresponds to the AVI FOURCC).
*/
uint32_t codec_tag; //编码器的附加信息 /**
* Extra binary data needed for initializing the decoder, codec-dependent.
*
* Must be allocated with av_malloc() and will be freed by
* avcodec_parameters_free(). The allocated size of extradata must be at
* least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
* bytes zeroed.
*/
uint8_t *extradata;
/**
* Size of the extradata content in bytes.
*/
int extradata_size; /**
* - video: the pixel format, the value corresponds to enum AVPixelFormat.
* - audio: the sample format, the value corresponds to enum AVSampleFormat.
*/
int format; //帧的格式,如果未知或未设置为-1
//对于视频帧,参考AVPixelFormat枚举值,比如:AV_PIX_FMT_YUV420P
//对于音频帧,参考AVSampleFormat枚举值,比如:AV_SAMPLE_FMT_U8 /**
* The average bitrate of the encoded data (in bits per second).
*/
int64_t bit_rate; int bits_per_coded_sample; /**
* Codec-specific bitstream restrictions that the stream conforms to.
*/
int profile;
int level; /**
* Video only. The dimensions of the video frame in pixels.
*/
int width;
int height; //视频帧的尺寸(以像素为单位)
//这里的宽高不一定会有值(对于流媒体视频而言),不过用户可以在解码后通过if (frame->width > 0 && frame->height > 0)来判断是否为视频流 /**
* Video only. The aspect ratio (width / height) which a single pixel
* should have when displayed.
*
* When the aspect ratio is unknown / undefined, the numerator should be
* set to 0 (the denominator may have any value).
*/
AVRational sample_aspect_ratio; //像素的宽高比,通过av_q2d()来获取值,如果未知/未指定,为0/1。 /**
* Video only. The order of the fields in interlaced video.
*/
enum AVFieldOrder field_order; /**
* Video only. Additional colorspace characteristics.
*/
enum AVColorRange color_range; //图像的编码格式(MPEG/JPEG),解码时,由库设置,编码时,由用户来设置
enum AVColorPrimaries color_primaries; //图像源初选的色度坐标
enum AVColorTransferCharacteristic color_trc; //图像颜色传输特性
enum AVColorSpace color_space; //图像彩色空间类型,解码时,由库设置,编码时,由用户来设置,比如等于AVCOL_SPC_RGB时,那么color_trc等于AVCOL_TRC_IEC61966_2_1
enum AVChromaLocation chroma_location; //储存的颜色色度样品的位置 /**
* Video only. Number of delayed frames.
*/
int video_delay; //延迟帧数 /**
* Audio only. The channel layout bitmask. May be 0 if the channel layout is
* unknown or unspecified, otherwise the number of bits set must be equal to
* the channels field.
*/
uint64_t channel_layout; //声道布局,仅用于音频 int channels; //音频通道数量,仅用于音频
int sample_rate; //音频数据的采样率。
//用户可以通过 if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))来判断该frame是否为音频
/**
* Audio only. Audio frame size, if known. Required by some formats to be static.
*/
int frame_size; //音频帧的样本数据数量
... ...
} AVCodecParameters;
获取音视频流信息方法
第一种,使用遍历方法获取
videoindex = -;
audioindex = -;
for (uint i = ; i < pFormatCtx->nb_streams; i++)
{
if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) //找到视频流
{
videoindex = i;
}
else if(pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) //找到音频流
{
audioindex = i;
}
}

第二种,使用av_find_best_stream()获取方法获取

函数定义如下:
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream,
               AVCodec **decoder_ret, int flags);
//根据type参数从ic-> streams[]里获取用户要找的流,找到成功后则返回streams[]中对应的序列号,否则返回
//ic: AVFormatContext结构体句柄
//type:要找的流参数,比如: AVMEDIA_TYPE_VIDEO,AVMEDIA_TYPE_AUDIO,AVMEDIA_TYPE_SUBTITLE等
//wanted_stream_nb: 用户希望请求的流号,设为-1用于自动选择
//related_stream: 试着找到一个相关的流(比如多路视频时),一般设为-1,表示不需要
//decoder_ret:如果非空,则返回所选流的解码器(相当于调用avcodec_find_decoder()函数)
//flags:未定义

获取如下:

videoindex = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -, -, NULL, );
audioindex = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -, -, NULL, );

5.AVStream和AVCodecParameters的更多相关文章

  1. FFmpeg(5)-AVStream和AVCodecParameters部分参数分析

    一.AVStream AVCodecContext *codec // 已过时,使用另一个 codecpar 结构体代替. AVRational time_base // 时间基数. int64_t ...

  2. 11.QT-ffmpeg+QAudioOutput实现音频播放器

    1.前言      由于QAudioOutput支持的输入数据必须是原始数据,所以播放mp3,WAV,AAC等格式文件,需要解封装后才能支持播放.      而在QT中,提供了QMediaPlayer ...

  3. FFmpeg: AVCodecParameters 结构体分析

    /** * This struct describes the properties of an encoded stream. * * sizeof(AVCodecParameters) is no ...

  4. FFmpeg——AVCodec,AVCodecContext,AVCodecParameters 辨析

    先贴上雷神的一张FFmpeg关键结构体之间的关系图: 再看雷神的分析: 每个AVStream存储一个视频/音频流的相关数据: 每个AVStream对应一个AVCodecContext,存储该视频/音频 ...

  5. FFMPEG-数据结构解释(AVCodecContext,AVStream,AVFormatContext)

    http://blog.csdn.net/yuan892173701/article/details/8702333 AVCodecContext  这是一个描述编解码器上下文的数据结构,包含了众多编 ...

  6. AVStream ddk 翻译

    1.       AVStream概览 AVStream是一款微软提供的多媒体类驱动程序,它既支持单独的视频流媒体,也支持音频视频集成的流媒体.微软把AVStream作为操作系统的一部分,在驱动程序k ...

  7. FFMPEG结构体分析:AVStream

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

  8. FFmpeg 结构体学习(二): AVStream 分析

    在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容.本文,我们将讲述一下AVStream. AVStream是存储每一 ...

  9. (转)FFMPEG-数据结构解释(AVCodecContext,AVStream,AVFormatContext)

    AVCodecContext  这是一个描述编解码器上下文的数据结构,包含了众多编解码器需要的参数信息 如果是单纯使用libavcodec,这部分信息需要调用者进行初始化:如果是使用整个FFMPEG库 ...

随机推荐

  1. C#LeetCode刷题之#720-词典中最长的单词(Longest Word in Dictionary)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4120 访问. 给出一个字符串数组words组成的一本英语词典.从 ...

  2. 封装react antd的表格table组件

    封装组件是为了能在开发过程中高度复用功能和样式相似的组件,以便我们只关注于业务逻辑层的处理,提高开发效率,提高逼格,降低代码重复率,降低劳动时间,减少加班的可能. 本次组件的封装采用了函数式组件即无状 ...

  3. Eclipse的Servers中无法添加Tomcat6/7

    2017年03月06日 17:14:46 阅读数:1007 Eclipse中在添加tomcat时发现6和7点击后发现ServerName是灰色的不能使用,也点不了NEXT,在各种查百度后发现需要删除w ...

  4. asp.net core 应用docke部署到centos7

    前言 前期准备 win10 (不要安装hyper-V) VMware-Workstation-Pro/15.0 Xshell6 (非必需) VS2019 以上环境请自行安装 都是默认安装没什么可说的 ...

  5. 读取topic数据存储到文件内

    基于python3.6 from pykafka import KafkaClient import logging logging.basicConfig(level=logging.INFO) d ...

  6. unity探索者之获取设备当前电量

    很多入坑了的小伙伴应该都知道,很多时候做移动端项目都会有显示当前电池电量的需求 对于这个功能,在unity中要做的事并不多,核心方法就一个,自己做一个定时器或者直接使用协程间隔调用该方法就好了 pub ...

  7. PythonCrashCourse 第七章习题

    编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如"Let me see if I can find you a Subaru" car =input("Wha ...

  8. html+css知识点以及常见的坑

    float 与 绝对定位 共同点:都脱离文档流,不占用原来的位置,后面的内容占有位置 不同点: float后者居上,补齐,且只能在父级盒子内活动,且不能浮动在照片上. 绝对定位脱离文档流后,直接漂浮到 ...

  9. 网站seo整站优化有什么优势

    http://www.wocaoseo.com/thread-314-1-1.html       现在很多企业找网络公司做网站优化,已经不再像以前那样做目标关键词,而是通过整站优化来达到企业营销目的 ...

  10. Promise对象入门

    简介 promise对象可以获取异步操作的消息,提供统一的API,各个异步操作都可以用同样的方法进行处理. promise对象不受外界影响,其有三种状态:pending(进行中).fulfilled( ...