lavf: fix av_find_best_stream when providing a wanted stream.
In the main loop, stream_number is incremented after checking the stream type, so the search usually will not find the wanted stream. This patch eliminates the useless stream_number variable and introduces a new one, called real_stream_index to store the real stream index of the current stream, no matter if we are looping through all the streams or only the streams of a program. Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Anton Khirnov <anton@khirnov.net>
This commit is contained in:
parent
6b35a795f8
commit
2c71581698
1 changed files with 5 additions and 4 deletions
|
@ -2462,7 +2462,7 @@ int av_find_best_stream(AVFormatContext *ic,
|
||||||
AVCodec **decoder_ret,
|
AVCodec **decoder_ret,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
int i, nb_streams = ic->nb_streams, stream_number = 0;
|
int i, nb_streams = ic->nb_streams;
|
||||||
int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;
|
int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;
|
||||||
unsigned *program = NULL;
|
unsigned *program = NULL;
|
||||||
AVCodec *decoder = NULL, *best_decoder = NULL;
|
AVCodec *decoder = NULL, *best_decoder = NULL;
|
||||||
|
@ -2475,11 +2475,12 @@ int av_find_best_stream(AVFormatContext *ic,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < nb_streams; i++) {
|
for (i = 0; i < nb_streams; i++) {
|
||||||
AVStream *st = ic->streams[program ? program[i] : i];
|
int real_stream_index = program ? program[i] : i;
|
||||||
|
AVStream *st = ic->streams[real_stream_index];
|
||||||
AVCodecContext *avctx = st->codec;
|
AVCodecContext *avctx = st->codec;
|
||||||
if (avctx->codec_type != type)
|
if (avctx->codec_type != type)
|
||||||
continue;
|
continue;
|
||||||
if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb)
|
if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
|
||||||
continue;
|
continue;
|
||||||
if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))
|
if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))
|
||||||
continue;
|
continue;
|
||||||
|
@ -2494,7 +2495,7 @@ int av_find_best_stream(AVFormatContext *ic,
|
||||||
if (best_count >= st->codec_info_nb_frames)
|
if (best_count >= st->codec_info_nb_frames)
|
||||||
continue;
|
continue;
|
||||||
best_count = st->codec_info_nb_frames;
|
best_count = st->codec_info_nb_frames;
|
||||||
ret = program ? program[i] : i;
|
ret = real_stream_index;
|
||||||
best_decoder = decoder;
|
best_decoder = decoder;
|
||||||
if (program && i == nb_streams - 1 && ret < 0) {
|
if (program && i == nb_streams - 1 && ret < 0) {
|
||||||
program = NULL;
|
program = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue