diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6b1b2b493df6f390701f2fe7fbc136d8d2b65505..37ec8a9bee9b24c6fdc2a5ab0f9fec6c0de436e5 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -899,7 +899,9 @@ AVInputFormat  *av_iformat_next(AVInputFormat  *f);
  */
 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
 
-enum CodecID av_guess_image2_codec(const char *filename);
+#if FF_API_GUESS_IMG2_CODEC
+attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
+#endif
 
 /* XXX: Use automatic init with either ELF sections or C file parser */
 /* modules. */
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 59d9150cdffdf13a70dfdeac73cc227507dd6267..2b5d63b0bdf84d4168adadbad92d163a54886237 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -24,6 +24,7 @@
 #include "libavutil/avstring.h"
 #include "avformat.h"
 #include "avio_internal.h"
+#include "internal.h"
 #include <strings.h>
 
 typedef struct {
@@ -183,9 +184,16 @@ static int read_probe(AVProbeData *p)
     return 0;
 }
 
+enum CodecID ff_guess_image2_codec(const char *filename)
+{
+    return av_str2id(img_tags, filename);
+}
+
+#if FF_API_GUESS_IMG2_CODEC
 enum CodecID av_guess_image2_codec(const char *filename){
     return av_str2id(img_tags, filename);
 }
+#endif
 
 static int read_header(AVFormatContext *s1, AVFormatParameters *ap)
 {
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 7528dae4eb9bccca7c392ddfcd9699ff449b17ec..9bc23402a4756d0c515ee0a6b6dc74b504100420 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -250,4 +250,6 @@ void ff_reduce_index(AVFormatContext *s, int stream_index);
 void ff_make_absolute_url(char *buf, int size, const char *base,
                           const char *rel);
 
+enum CodecID ff_guess_image2_codec(const char *filename);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ca582b34df1d32e6345811b3bbcedd1153569496..1d58682a662b40a9417e0687920568068dbaf0e6 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -218,7 +218,7 @@ AVOutputFormat *av_guess_format(const char *short_name, const char *filename,
 #if CONFIG_IMAGE2_MUXER
     if (!short_name && filename &&
         av_filename_number_test(filename) &&
-        av_guess_image2_codec(filename) != CODEC_ID_NONE) {
+        ff_guess_image2_codec(filename) != CODEC_ID_NONE) {
         return av_guess_format("image2", NULL, NULL);
     }
 #endif
@@ -271,7 +271,7 @@ enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
 
 #if CONFIG_IMAGE2_MUXER
         if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){
-            codec_id= av_guess_image2_codec(filename);
+            codec_id= ff_guess_image2_codec(filename);
         }
 #endif
         if(codec_id == CODEC_ID_NONE)
diff --git a/libavformat/version.h b/libavformat/version.h
index 512195e82f800d3c70ff07373e86dbbcce448601..cfe1f823936b912f83ffbe4eae058a848efd1f44 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -104,5 +104,8 @@
 #ifndef FF_API_PKT_DUMP
 #define FF_API_PKT_DUMP                (LIBAVFORMAT_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_GUESS_IMG2_CODEC
+#define FF_API_GUESS_IMG2_CODEC        (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
 
 #endif //AVFORMAT_VERSION_H