diff --git a/doc/protocols.texi b/doc/protocols.texi
index d6e12f73e3103a2951090fd82df91c1cf9128eb7..172184e501103360b1219aab4f8a12ae0407eb66 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -164,7 +164,7 @@ content across a TCP/IP network.
 
 The required syntax is:
 @example
-rtmp://@var{server}[:@var{port}][/@var{app}][/@var{playpath}]
+rtmp://@var{server}[:@var{port}][/@var{app}][/@var{instance}][/@var{playpath}]
 @end example
 
 The accepted parameters are:
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 9af45842261233c6e8249152ba491901569d1d4f..807e899f3408cbfe9252b5113366ea9db6c6b8ae 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -1037,9 +1037,10 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
             fname = next;
             rt->app[0] = '\0';
         } else {
+            // make sure we do not mismatch a playpath for an application instance
             char *c = strchr(p + 1, ':');
             fname = strchr(p + 1, '/');
-            if (!fname || c < fname) {
+            if (!fname || (c && c < fname)) {
                 fname = p + 1;
                 av_strlcpy(rt->app, path + 1, p - path);
             } else {