ffmpeg源码分析--av_find_best_stream <转>
1. av_find_best_stream
a. 就是要获取音视频及字幕的stream_index
b.以前没有函数av_find_best_stream时,获取索引可以通过如下
for(i=; i<is->pFormatCtx->nb_streams; i++)
{
if(is->pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
is->videoindex= i;
}
if(is->pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
{
is->sndindex= i;
}
}
2.video及audio的调用如下:
ic type wanted_stream_nb related_stream decoder_ret flag
st_index[AVMEDIA_TYPE_VIDEO] =
av_find_best_stream(ic, AVMEDIA_TYPE_VIDEO, st_index[AVMEDIA_TYPE_VIDEO], -, NULL, );
st_index[AVMEDIA_TYPE_AUDIO] =
av_find_best_stream(ic, AVMEDIA_TYPE_AUDIO, st_index[AVMEDIA_TYPE_AUDIO],st_index[AVMEDIA_TYPE_VIDEO], NULL, );
3.说明
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream,
AVCodec **decoder_ret, int flags)
{
int i, nb_streams = ic->nb_streams;
int ret = AVERROR_STREAM_NOT_FOUND, best_count = -, best_bitrate = -, best_multiframe = -, count, bitrate, multiframe;
unsigned *program = NULL;
const AVCodec *decoder = NULL, *best_decoder = NULL; if (related_stream >= && wanted_stream_nb < ) { //没看到有什么作用,即参数related_stream在这儿没有用
AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
if (p) {
program = p->stream_index;
nb_streams = p->nb_stream_indexes;
}
}
for (i = ; i < nb_streams; i++) { //对于只有音频与视频流的媒体文件来说nb_streams=2
int real_stream_index = program ? program[i] : i; //program=NULL,所以real_stream_index=i;
AVStream *st = ic->streams[real_stream_index];
AVCodecContext *avctx = st->codec;
if (avctx->codec_type != type) //以下三个if是过滤条件
continue;
if (wanted_stream_nb >= && real_stream_index != wanted_stream_nb)
continue;
if (wanted_stream_nb != real_stream_index &&
st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED |
AV_DISPOSITION_VISUAL_IMPAIRED))
continue;
if (type == AVMEDIA_TYPE_AUDIO && !(avctx->channels && avctx->sample_rate))
continue;
if (decoder_ret) { //decoder_ret=NULL,所以下面这个find_decoder也没有调用
decoder = find_decoder(ic, st, st->codec->codec_id);
if (!decoder) {
if (ret < )
ret = AVERROR_DECODER_NOT_FOUND;
continue;
}
}
count = st->codec_info_nb_frames;
bitrate = avctx->bit_rate;
if (!bitrate)
bitrate = avctx->rc_max_rate;
multiframe = FFMIN(, count);
if ((best_multiframe > multiframe) ||
(best_multiframe == multiframe && best_bitrate > bitrate) ||
(best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
continue;
best_count = count;
best_bitrate = bitrate;
best_multiframe = multiframe;
ret = real_stream_index; //到这儿real_stream_index就是匹配了三个if的index了,不匹配的都continue了
best_decoder = decoder;
if (program && i == nb_streams - && ret < ) {
program = NULL;
nb_streams = ic->nb_streams;
/* no related stream found, try again with everything */
i = ;
}
}
if (decoder_ret)
*decoder_ret = (AVCodec*)best_decoder;
return ret; //返回就完事了
}
av_find_best_stream函数其实跟以前实现思路是一样的,只不过这儿的条件更多一点而己。
转载地址:http://blog.chinaunix.net/uid-26009923-id-5730055.html
ffmpeg源码分析--av_find_best_stream <转>的更多相关文章
- 最新版ffmpeg源码分析
最新版ffmpeg源码分析一:框架 (ffmpeg v0.9) 框架 最新版的ffmpeg中发现了一个新的东西:avconv,而且ffmpeg.c与avconv.c一个模样,一研究才发现是libav下 ...
- ffmpeg 源码分析
http://blog.csdn.net/liuhongxiangm/article/details/8824761 https://code.google.com/p/ffmpegsource/is ...
- ffmpeg源码分析一:概述 (转1)
原帖地址:http://blog.csdn.net/austinblog/article/details/24800381 首先先看ffmpeg.c文件,有类似于如下的一些变量: InputStrea ...
- ffmpeg源码分析五:ffmpeg调用x264编码器的过程分析 (转5)
原帖地址:http://blog.csdn.net/austinblog/article/details/25127533 该文将以X264编码器为例,解释说明FFMPEG是怎么调用第三方编码器来进行 ...
- ffmpeg源码分析三:transcode_init函数 (转3)
原帖地址:http://blog.csdn.net/austinblog/article/details/25061945 transcode_init()函数是在转换前做准备工作的.下面看看其源代码 ...
- ffmpeg源码分析二:main函数和transcode函数 (转2)
原帖地址:http://blog.csdn.net/austinblog/article/details/24804455 首先从main函数看起,关键解释部分已加注释,该函数在ffmpeg.c文件中 ...
- ffmpeg源码分析之媒体打开过程
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma ...
- ffmpeg源码分析四:transcode_step函数 (转4)
原帖地址:http://blog.csdn.net/austinblog/article/details/25099979 该函数的主要功能是一步完整的转换工作,下面看看源代码: static int ...
- FFmpeg源码简单分析:libswscale的sws_scale()
===================================================== FFmpeg的库函数源码分析文章列表: [架构图] FFmpeg源码结构图 - 解码 FFm ...
随机推荐
- UVA-11248 Frequency Hopping (最大流+最小割)
题目大意:给一张网络,问是否存在一条恰为C的流.若不存在,那是否存在一条弧,使得改动这条弧的容量后能恰有为C的流? 题目分析:先找出最大流,如果最大流不比C小,那么一定存在一条恰为C的流.否则,找出最 ...
- MyBatise代码自动生成时候Oralce的number类型BigDecimal问题
使用MyBatise的代码自动生成工具时候,即便在配置文件中定义了 <javaTypeResolver> <property name="forceBigDecimals& ...
- 素数对猜想之python3实现
题目 让我们定义dn为:dn=pn+1−pn,其中pi是第i个素数.显然有d1=1,且对于n>1有dn是偶数.“素数对猜想”认为“存在无穷多对相邻且差为 ...
- C#并行编程(1)
一.基于任务的程序设计 共享内存多核OS和分布式内存OS 共享内存多核OS-一个微处理器由多个内核组成,且每个内核共享一段私有内存: 分布式内存OS-- 由多个微处理器组成,每个微处理器可以有自己的私 ...
- 『转』G Data InternetSecurity 2014 – 免费3个月
G Data来自德国的顶级杀毒软件,采用BitDefender+CloseGap双引擎,屡获AV-TEST防護率100%.不多介绍,目前2014中文版没有上市.活动地址:点此进入官方网站:点此进入申请 ...
- Transaction ACID (转载)
Transaction 原文出处: 黄勇 Transaction 也就是所谓的事务了,通俗理解就是一件事情.从小,父母就教育我们,做事情要有始有终,不能半途而废.�0�2事务也是这样,不能做一般 ...
- 第10课 struct和union分析
struct的小秘密:空结构体占多大内存呢? 直观的答案有两种: 1.空结构体的大小为0 2.结构体本来就是为了将不同的变量集合在一起使用的,定义空结构体会导致编译错误 实例分析: #include ...
- 第3课 进化后的const分析
C语言中的const const修饰的变量是只读的,本质还是变量 const修饰的局部变量在栈上分配空间(改变这个空间的值,这个变量就会改变) const修饰的全局变量在只读存储区分配空间 const ...
- yaf 整理札记
由于yaf只是一个web框架,只负责处理web请求之类的基本功能,相当简洁,连db库都没有.于是试着把zend 2.2的db库,form库,validator库与yaf结合,写了一个demo.因为ze ...
- python中django框架的csrf验证
在form表单以post的方式提交时,django默认会带一个验证的机制csrf验证 <form action="/day02/login/" method="po ...