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 <转>的更多相关文章

  1. 最新版ffmpeg源码分析

    最新版ffmpeg源码分析一:框架 (ffmpeg v0.9) 框架 最新版的ffmpeg中发现了一个新的东西:avconv,而且ffmpeg.c与avconv.c一个模样,一研究才发现是libav下 ...

  2. ffmpeg 源码分析

    http://blog.csdn.net/liuhongxiangm/article/details/8824761 https://code.google.com/p/ffmpegsource/is ...

  3. ffmpeg源码分析一:概述 (转1)

    原帖地址:http://blog.csdn.net/austinblog/article/details/24800381 首先先看ffmpeg.c文件,有类似于如下的一些变量: InputStrea ...

  4. ffmpeg源码分析五:ffmpeg调用x264编码器的过程分析 (转5)

    原帖地址:http://blog.csdn.net/austinblog/article/details/25127533 该文将以X264编码器为例,解释说明FFMPEG是怎么调用第三方编码器来进行 ...

  5. ffmpeg源码分析三:transcode_init函数 (转3)

    原帖地址:http://blog.csdn.net/austinblog/article/details/25061945 transcode_init()函数是在转换前做准备工作的.下面看看其源代码 ...

  6. ffmpeg源码分析二:main函数和transcode函数 (转2)

    原帖地址:http://blog.csdn.net/austinblog/article/details/24804455 首先从main函数看起,关键解释部分已加注释,该函数在ffmpeg.c文件中 ...

  7. ffmpeg源码分析之媒体打开过程

    int avformat_open_input(AVFormatContext **ps,           const char *filename,           AVInputForma ...

  8. ffmpeg源码分析四:transcode_step函数 (转4)

    原帖地址:http://blog.csdn.net/austinblog/article/details/25099979 该函数的主要功能是一步完整的转换工作,下面看看源代码: static int ...

  9. FFmpeg源码简单分析:libswscale的sws_scale()

    ===================================================== FFmpeg的库函数源码分析文章列表: [架构图] FFmpeg源码结构图 - 解码 FFm ...

随机推荐

  1. UVA-1614 Hell on the Markets(贪心+推理) (有待补充)

    题目大意:一个整数序列a,1≤a[i]≤i.问能否通过在一些元素前加上负号,使得整个序列和为0. 题目分析:贪心.贪心策略:每次都先选最大的元素加负号(或保留,不加负号). 贪心依据:对于1≤a[i] ...

  2. springboot问题集(一)------junit内Assert.assertEquals()的含义

    1. assertEquals([String message],Object target,Object result) target与result不相等,中断测试方法,输出message asse ...

  3. Outpost Security Suite Pro 8.1 – 免费4个月

    OSS( 简称 )一款来自俄罗斯Agnitum公司的互联网安全产品. Outpost以网络防火墙知名,AVG和avast!等知名安全企业都有使用Outpost的防火墙技术. Outpost Secur ...

  4. [转载]队列queue和双端Dequeue

    转载自:http://uule.iteye.com/blog/2095650?utm_source=tuicool 注意:这都只是接口而已 1.Queue API 在java5中新增加了java.ut ...

  5. 通过Ftp put命令上传导致文件损坏的解决办法

    通过Linux命令行向在一台Windows FTP服务器上传文件.然后在另一台Windows客户机登录FTP服务器下载,但是下载后的文件大小变了,exe文件错误了不能正确执行.刻意打包的文件(.rar ...

  6. 2017年7月ROS学习资料小结

    <孙子兵法·谋攻篇>:"上兵伐谋,其次伐交,其次伐兵,其下攻城:攻城之法为不得已." 任何发生在自己国土上的战争,即便胜利,也饱含屈辱. ----~~~~----Gaz ...

  7. SEO -- WP如何建立SiteMap

    站点地图对网站的seo优化有着相当重要的作用,而WordPress的优势就是插件特别的多,也特别符合蜘蛛的口味,在wp上建立站点地图是相当简单的事情,只需要一款插件和几步简单的配置 Google XM ...

  8. Oracle数据库导入导出(备份还原)

    一.数据库的导出 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中(全库导出) exp system/manager@TEST file=d:\ ...

  9. DBUnit使用介绍

    一.DbUnit设计理念熟悉单元测试的开发人员都知道,在对数据库进行单元测试时候,通常采用的方案有运用模拟对象(mock objects)和stubs两种.通过隔离关联的数据库访问类,比如JDBC的相 ...

  10. HDU 2199 Can you solve this equation?(二分精度)

    HDU 2199 Can you solve this equation?     Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == ...