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 ...
随机推荐
- c++ 中的 set
set (集合) 中的元素是排序好的,而且是不重复的. 例题:hdu 4989 题目大意:求一组数列中任意两个不重复元素和,再求不重复和的和. #include <bits/stdc++.h&g ...
- ablout unbuntu default mysql
http://www.ghostchina.com/how-to-reset-mysqls-root-password/ http://blog.csdn.net/u010603691/article ...
- Linux终端界面屏保
Linux终端界面屏保 在很多Linux使用者的认知里,都认为终端下的Linux操作界面是没有屏保的,只有像windows那样的图形界面下才有屏保.但是其实Linux下也是有屏保的,只不过是ASC ...
- poj 3744 概率dp 快速幂 注意排序 难度:2
/* Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5304 Accepted: 1455 De ...
- 重磅教程!帮你全面彻底搞定Material design的学习笔记
http://www.uisdc.com/comprehensive-material-design-note
- CMD中goto语句会中断for循环特性详解
在这个程序里面由于用到了上篇文章中所说的字符串切割,而用到了Goto强制跳转语句 但是在程序中使用的时候却发现一个错误,当把这个字符切割的代码段如果直接作为非嵌套语句执行正常 但是一旦放到for循环的 ...
- Xadmin的配置及使用
xadmin是Django的第三方扩展,可是使Django的admin站点使用更方便. 1. 安装 通过如下命令安装xadmin的最新版 pip install https://github.com/ ...
- Java中的HashMap的工作原理是什么?
问答题23 /120 Java中的HashMap的工作原理是什么? 参考答案 Java中的HashMap是以键值对(key-value)的形式存储元素的.HashMap需要一个hash函数,它使用ha ...
- .properties文件常量定义
application.properties文件,位于resources目录下.一般定义一些不会改变的数据如数据库相关配置,文件路径,项目地址. 如何在项目代码中获取该文件中的配置信息: 1,在app ...
- Git 之 git原理简介
这里只是很简单.超简单的介绍下git,为的是方便记忆: 本地仓库分为三个部分:工作区.暂存区.仓库区,其中暂存区和仓库区属于版本区. 对于文件的操作,需要从工作区----> 暂存区 ----&g ...