From 524daf8d0469c703f1357af0dd6b171e6aa8bc06 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Tue, 7 Nov 2017 13:05:55 -0500
Subject: [PATCH] media: use av_find_best_stream

Change-Id: I6ab8a0078f7b67b2342859e216ab4ff02d721736
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
---
 src/media/media_decoder.cpp | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp
index 0fd2e7de20..a125f3cf13 100644
--- a/src/media/media_decoder.cpp
+++ b/src/media/media_decoder.cpp
@@ -174,19 +174,14 @@ MediaDecoder::setupStream(AVMediaType mediaType)
         }
     }
 
-    for (size_t i = 0; streamIndex_ == -1 && i < inputCtx_->nb_streams; ++i) {
-        if (inputCtx_->streams[i]->codecpar->codec_type == mediaType) {
-            streamIndex_ = i;
-        }
-    }
-
+    // find the first video stream from the input
+    streamIndex_ = av_find_best_stream(inputCtx_, mediaType, -1, -1, &inputDecoder_, 0);
     if (streamIndex_ < 0) {
         RING_ERR() << "No " << streamType << " stream found";
         return -1;
     }
 
     avStream_ = inputCtx_->streams[streamIndex_];
-
     inputDecoder_ = findDecoder(avStream_->codecpar->codec_id);
     if (!inputDecoder_) {
         RING_ERR() << "Unsupported codec";
-- 
GitLab