diff mbox

[FFmpeg-devel,1/2] avformat/utils: return impaired streams in av_find_best_stream if only those exist

Message ID 20170602211014.4257-1-cus@passwd.hu
State Accepted
Commit 47c699f7be16f58004061408fc4d0676cef0a3b3
Headers show

Commit Message

Marton Balint June 2, 2017, 9:10 p.m. UTC
Fixes ticket #6397.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/utils.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer June 3, 2017, 5:07 p.m. UTC | #1
On Fri, Jun 02, 2017 at 11:10:13PM +0200, Marton Balint wrote:
> Fixes ticket #6397.
> 
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavformat/utils.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)

LGTM

can you add a fate test for this ?

thx

[...]
Marton Balint June 4, 2017, 1:10 p.m. UTC | #2
On Sat, 3 Jun 2017, Michael Niedermayer wrote:

> On Fri, Jun 02, 2017 at 11:10:13PM +0200, Marton Balint wrote:
>> Fixes ticket #6397.
>>
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  libavformat/utils.c | 17 +++++++++--------
>>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> LGTM

Thanks, pushed both patches.

>
> can you add a fate test for this ?

Will work on it as time permits.

Thanks,
Marton
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index fbd8b58ac2..b544b6f9c5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4097,7 +4097,9 @@  int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
                         AVCodec **decoder_ret, int flags)
 {
     int i, nb_streams = ic->nb_streams;
-    int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1, best_bitrate = -1, best_multiframe = -1, count, bitrate, multiframe;
+    int ret = AVERROR_STREAM_NOT_FOUND;
+    int best_count = -1, best_bitrate = -1, best_multiframe = -1, best_disposition = -1;
+    int count, bitrate, multiframe, disposition;
     unsigned *program = NULL;
     const AVCodec *decoder = NULL, *best_decoder = NULL;
 
@@ -4116,10 +4118,6 @@  int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
             continue;
         if (wanted_stream_nb >= 0 && 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 && !(par->channels && par->sample_rate))
             continue;
         if (decoder_ret) {
@@ -4130,13 +4128,16 @@  int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
                 continue;
             }
         }
+        disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED));
         count = st->codec_info_nb_frames;
         bitrate = par->bit_rate;
         multiframe = FFMIN(5, count);
-        if ((best_multiframe >  multiframe) ||
-            (best_multiframe == multiframe && best_bitrate >  bitrate) ||
-            (best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
+        if ((best_disposition >  disposition) ||
+            (best_disposition == disposition && best_multiframe >  multiframe) ||
+            (best_disposition == disposition && best_multiframe == multiframe && best_bitrate >  bitrate) ||
+            (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
             continue;
+        best_disposition = disposition;
         best_count   = count;
         best_bitrate = bitrate;
         best_multiframe = multiframe;