aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-08-01 22:17:52 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-08-04 18:06:26 +0200
commit4e855c11b50b2f5b29cfd570d7cf7efeaff558d5 (patch)
tree55a6abba16bbdb39d0624299f76346a115501a77
parente8c003edd259feabacef0884ea8a47b22f7cac49 (diff)
downloadffmpeg-4e855c11b50b2f5b29cfd570d7cf7efeaff558d5.tar.gz
avformat/util: change av_find_default_stream_index() to use a score based system
Disfavor video streams with unknown resolution and no packets Fixes seeking in audio-only-speex.flv Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/utils.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4cfebf23f9..6ebbe6cbd9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1531,23 +1531,36 @@ static void flush_packet_queue(AVFormatContext *s)
int av_find_default_stream_index(AVFormatContext *s)
{
- int first_audio_index = -1;
int i;
AVStream *st;
+ int best_stream = 0;
+ int best_score = -1;
if (s->nb_streams <= 0)
return -1;
for (i = 0; i < s->nb_streams; i++) {
+ int score = 0;
st = s->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
- return i;
+ if (!st->codec->width && !st->codec->height && !st->codec_info_nb_frames)
+ score += 25;
+ else
+ score += 100;
+ }
+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (!st->codec->sample_rate && !st->codec_info_nb_frames)
+ score += 12;
+ else
+ score += 50;
+ }
+
+ if (score > best_score) {
+ best_score = score;
+ best_stream = i;
}
- if (first_audio_index < 0 &&
- st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
- first_audio_index = i;
}
- return first_audio_index >= 0 ? first_audio_index : 0;
+ return best_stream;
}
/** Flush the frame reader. */