diff --git a/libavformat/avio.h b/libavformat/avio.h
index a99880878883a5ba88fe291151d0add8999564b9..a3bf5c01d4e48cba926a50e7cc999ce89c8a1b7d 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -514,9 +514,11 @@ int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__
 int url_fprintf(AVIOContext *s, const char *fmt, ...);
 #endif
 
+#if FF_API_OLD_AVIO
 /** @note unlike fgets, the EOL character is not returned and a whole
     line is parsed. return NULL if first char read was EOF */
-char *url_fgets(AVIOContext *s, char *buf, int buf_size);
+attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
+#endif
 
 void put_flush_packet(AVIOContext *s);
 
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index e273aa536a6668acb5742c13ed66189abd0a0b30..290572435e870977b1fda157c4c7bdcd96bb717f 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -915,6 +915,7 @@ int url_fprintf(AVIOContext *s, const char *fmt, ...)
 }
 #endif //CONFIG_MUXERS
 
+#if FF_API_OLD_AVIO
 char *url_fgets(AVIOContext *s, char *buf, int buf_size)
 {
     int c;
@@ -935,6 +936,7 @@ char *url_fgets(AVIOContext *s, char *buf, int buf_size)
         *q = '\0';
     return buf;
 }
+#endif
 
 int url_fget_max_packet_size(AVIOContext *s)
 {