From c524d9bb8852b903339995531fb9678006fd37d6 Mon Sep 17 00:00:00 2001
From: Jindrich Makovicka <makovick@gmail.com>
Date: Thu, 27 Sep 2012 16:55:03 +0200
Subject: [PATCH] avoid infinite loop in try_decode_frame

exit the loop if the decoder does not consume any more bytes, and
does not produce frames, but there are still remaining bytes in the packet
---
 libavformat/utils.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9c6b143..73a3f17 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2139,12 +2139,18 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option
         default:
             break;
         }
-        if (ret >= 0) {
+        if (ret > 0) {
             if (got_picture)
                 st->info->nb_decoded_frames++;
             pkt.data += ret;
             pkt.size -= ret;
             ret       = got_picture;
+        } else if (ret == 0) {
+            ret       = got_picture;
+            if (got_picture)
+                st->info->nb_decoded_frames++;
+            else
+                break;
         }
     }
 
-- 
1.7.10.4

