diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 32a1f92cb83ad78a4dd6b766b019aad2897f3be3..738459e83034e7b2183c9c39e0fd8e7701caf961 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -665,7 +665,9 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen)
         c = avio_r8(s);
         if (c && i < maxlen-1)
             buf[i++] = c;
-    } while (c != '\n' && c);
+    } while (c != '\n' && c != '\r' && c);
+    if (c == '\r' && avio_r8(s) != '\n')
+        avio_skip(s, -1);
 
     buf[i] = 0;
     return i;