diff --git a/configure.ac b/configure.ac
index ca80f6dbc576c91aaa833469beeeeafab6f5fbb4..dfe21a9716db32db2f5fd933ea998b1f2a954728 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3185,8 +3185,10 @@ AS_IF([test "${enable_xcb}" != "no"], [
   dnl avcodec (vaapi-x11)
   AS_IF([test "${enable_libva}" != "no"], [
     AS_IF([test "${have_avcodec}" != "no"], [
-      VLC_ADD_CFLAGS([avcodec], [${XCB_CFLAGS}])
-      VLC_ADD_LIBS([avcodec], [${XCB_LIBS}])
+      PKG_CHECK_MODULES(XLIB_XCB, [x11-xcb])
+      VLC_ADD_CFLAGS([avcodec], [${XLIB_XCB_CFLAGS} ${XCB_CFLAGS}])
+      VLC_ADD_LIBS([avcodec], [${XLIB_XCB_LIBS} ${XCB_LIBS}])
+      AC_DEFINE(HAVE_XCB, 1, [Define if avcodec has to be built with XCB support.])
     ])
   ])
 ])