diff --git a/libavformat/Makefile b/libavformat/Makefile
index 17e2214d79868b8266b2671dd4c72772b07c3080..cfff6aab46c748144e0155b747f04e4408bff2db 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -549,7 +549,6 @@ TESTPROGS = seek                                                        \
             url                                                         \
 
 TESTPROGS-$(CONFIG_NETWORK)              += noproxy
-TESTPROGS-yes                            += api-h264
 TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh
 
 TOOLS     = aviocat                                                     \
diff --git a/tests/api/Makefile b/tests/api/Makefile
index 9f82be2c29180d5f58720259e18ea6af7f2a6a31..704987e1adef422c5660f35c7d68d8404fd95090 100644
--- a/tests/api/Makefile
+++ b/tests/api/Makefile
@@ -1,4 +1,5 @@
 APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac
+APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264
 APITESTPROGS += $(APITESTPROGS-yes)
 
 APITESTOBJS  := $(APITESTOBJS:%=$(APITESTSDIR)%) $(APITESTPROGS:%=$(APITESTSDIR)/%-test.o)
diff --git a/libavformat/api-h264-test.c b/tests/api/api-h264-test.c
similarity index 100%
rename from libavformat/api-h264-test.c
rename to tests/api/api-h264-test.c
diff --git a/tests/fate/api.mak b/tests/fate/api.mak
index 2127b9b94d4782a91664a2fe9bfd02b8192c0d2f..da5003646b53fa552a341b3be23ea2448c88e637 100644
--- a/tests/fate/api.mak
+++ b/tests/fate/api.mak
@@ -4,5 +4,12 @@ fate-api-flac: CMD = run $(APITESTSDIR)/api-flac-test
 fate-api-flac: CMP = null
 fate-api-flac: REF = /dev/null
 
+FATE_API_SAMPLES-LIBAVFORMAT-$(call DEMDEC, H264, H264) += fate-api-h264
+fate-api-h264: $(APITESTSDIR)/api-h264-test$(EXESUF)
+fate-api-h264: CMD = run $(APITESTSDIR)/api-h264-test $(TARGET_SAMPLES)/h264-conformance/SVA_NL2_E.264
+
 FATE-$(CONFIG_AVCODEC) += $(FATE_API_LIBAVCODEC-yes)
-fate-api: $(FATE_API_LIBAVCODEC-yes)
+FATE_API_SAMPLES-$(CONFIG_AVFORMAT) += $(FATE_API_SAMPLES-LIBAVFORMAT-yes)
+FATE_SAMPLES_AVCONV += $(FATE_API_SAMPLES-yes)
+
+fate-api: $(FATE_API_LIBAVCODEC-yes) $(FATE_API_SAMPLES-yes)
diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak
index 0e1ff62ba1a4dcc8b7280c5ce78143a1b1c0558b..a9c02bcbaf9ecc52377d64cf6639f48a3f4a578a 100644
--- a/tests/fate/libavformat.mak
+++ b/tests/fate/libavformat.mak
@@ -14,9 +14,5 @@ FATE_LIBAVFORMAT-yes += fate-url
 fate-url: libavformat/url-test$(EXESUF)
 fate-url: CMD = run libavformat/url-test
 
-FATE_SAMPLES_AVCONV-$(call DEMDEC, H264, H264) += fate-api-h264
-fate-api-h264: libavformat/api-h264-test$(EXESUF)
-fate-api-h264: CMD = run libavformat/api-h264-test $(TARGET_SAMPLES)/h264-conformance/SVA_NL2_E.264
-
 FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT-yes)
 fate-libavformat: $(FATE_LIBAVFORMAT)