diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4148285971..f72231790f 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -53,6 +53,7 @@
 #include "libavutil/cpu.h"
 #include "libavutil/ffversion.h"
 #include "libavutil/version.h"
+#include "libavcodec/bsf.h"
 #include "cmdutils.h"
 #if HAVE_SYS_RESOURCE_H
 #include <sys/time.h>
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e9d30fbd67..b424f914e9 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -31,6 +31,7 @@
 #include "libavformat/avio.h"
 
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bsf.h"
 
 #include "libavfilter/avfilter.h"
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index a63bed54cf..6dbe638433 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -27,6 +27,7 @@
 #include "libavformat/avformat.h"
 
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bsf.h"
 
 #include "libavfilter/avfilter.h"
 
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index d369b30bbc..3b3a3ef05a 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -32,6 +32,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/thread.h"
 #include "avcodec.h"
+#include "bsf.h"
 #include "decode.h"
 #include "encode.h"
 #include "frame_thread_encoder.h"
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index dabd60386e..f6d2cde441 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -41,7 +41,6 @@
 #include "libavutil/pixfmt.h"
 #include "libavutil/rational.h"
 
-#include "bsf.h"
 #include "codec.h"
 #include "codec_desc.h"
 #include "codec_par.h"
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index e03326515b..d565286397 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -16,12 +16,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
+#include <stdint.h>
+#include <string.h>
 
-#include "libavutil/common.h"
 #include "libavutil/log.h"
 
-#include "avcodec.h"
+#include "bsf.h"
 #include "bsf_internal.h"
 
 extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
diff --git a/libavcodec/cbs_bsf.c b/libavcodec/cbs_bsf.c
index 0977d431f7..86ec3f2a4d 100644
--- a/libavcodec/cbs_bsf.c
+++ b/libavcodec/cbs_bsf.c
@@ -16,6 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bsf.h"
 #include "bsf_internal.h"
 #include "cbs_bsf.h"
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..6def4047e5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -40,6 +40,7 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
+#include "bsf.h"
 #include "decode.h"
 #include "hwconfig.h"
 #include "internal.h"
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 975ec0ba30..d8fb054832 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -32,6 +32,7 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/pixfmt.h"
 #include "avcodec.h"
+#include "bsf.h"
 #include "config.h"
 
 /**
diff --git a/libavcodec/opus_metadata_bsf.c b/libavcodec/opus_metadata_bsf.c
index 723e31c243..e73852d618 100644
--- a/libavcodec/opus_metadata_bsf.c
+++ b/libavcodec/opus_metadata_bsf.c
@@ -16,6 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "bsf.h"
 #include "bsf_internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
index 47f44b6467..32a90cd2f7 100644
--- a/libavcodec/pcm_rechunk_bsf.c
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -19,6 +19,7 @@
  */
 
 #include "avcodec.h"
+#include "bsf.h"
 #include "bsf_internal.h"
 #include "libavutil/avassert.h"
 #include "libavutil/opt.h"
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 8ca804c2a3..be6808f5c4 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -25,6 +25,7 @@
 #include "libavutil/fifo.h"
 #include "libavutil/opt.h"
 #include "libavcodec/av1_parse.h"
+#include "libavcodec/bsf.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 6d77398f48..20912e797e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -25,6 +25,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timestamp.h"
+#include "libavcodec/bsf.h"
 #include "avformat.h"
 #include "internal.h"
 #include "url.h"
diff --git a/libavformat/internal.h b/libavformat/internal.h
index c6adf7b872..2919080801 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -26,6 +26,7 @@
 #include "libavutil/bprint.h"
 
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bsf.h"
 
 #include "avformat.h"
 #include "os_support.h"
diff --git a/libavformat/mux.c b/libavformat/mux.c
index d719e16283..6fa1c5495b 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -21,6 +21,7 @@
 
 #include "avformat.h"
 #include "internal.h"
+#include "libavcodec/bsf.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/packet_internal.h"
 #include "libavutil/opt.h"
diff --git a/libavformat/tee.c b/libavformat/tee.c
index f33cbea98c..759535bdea 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -23,6 +23,7 @@
 #include "libavutil/avutil.h"
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
+#include "libavcodec/bsf.h"
 #include "internal.h"
 #include "avformat.h"
 #include "avio_internal.h"
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 0df14682a4..6b117e5223 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -35,6 +35,7 @@
 #include "libavutil/time.h"
 #include "libavutil/timestamp.h"
 
+#include "libavcodec/bsf.h"
 #include "libavcodec/bytestream.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/packet_internal.h"
