diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 6528c967795655259740859375ce930f59861c1f..4667a4fb52f9cc8ba77341f03f1897115fb92757 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -33,12 +33,14 @@
 #include "libavutil/internal.h"
 #include "libavutil/imgutils.h"
 
+#if FF_API_GETCHROMA
 void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     *h_shift = desc->log2_chroma_w;
     *v_shift = desc->log2_chroma_h;
 }
+#endif
 
 static int is_gray(const AVPixFmtDescriptor *desc)
 {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 303c11204659c4664775e68292e94ff0f0bc2ad1..75d99bc44177fe6a89c857736fffed272a9437ba 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -48,6 +48,9 @@
  * the public API and may change, break or disappear at any time.
  */
 
+#ifndef FF_API_GETCHROMA
+#define FF_API_GETCHROMA         (LIBAVCODEC_VERSION_MAJOR < 58)
+#endif
 #ifndef FF_API_MISSING_SAMPLE
 #define FF_API_MISSING_SAMPLE    (LIBAVCODEC_VERSION_MAJOR < 58)
 #endif