diff --git a/config/external/moz.build b/config/external/moz.build
index 2fc8df57992e..63d18e50a961 100644
--- a/config/external/moz.build
+++ b/config/external/moz.build
@@ -40,8 +40,9 @@ if not CONFIG["MOZ_SYSTEM_LIBVPX"]:
     external_dirs += ["media/libvpx"]
 
 if CONFIG["MOZ_AV1"]:
-    external_dirs += ["media/libaom"]
-    external_dirs += ["media/libdav1d"]
+    if not CONFIG["MOZ_SYSTEM_AV1"]:
+        external_dirs += ["media/libaom"]
+        external_dirs += ["media/libdav1d"]
 
 if not CONFIG["MOZ_SYSTEM_PNG"]:
     external_dirs += ["media/libpng"]
diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build
index 5c6e25b3980b..ce99ebfb6d3f 100644
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -81,6 +81,11 @@ if CONFIG["MOZ_AV1"]:
         "agnostic/AOMDecoder.cpp",
         "agnostic/DAV1DDecoder.cpp",
     ]
+    if CONFIG['MOZ_SYSTEM_AV1']:
+        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBAOM_CFLAGS']
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBAOM_LIBS']
+        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBDAV1D_CFLAGS']
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBDAV1D_LIBS']
 
 if CONFIG["MOZ_OMX"]:
     EXPORTS += [
diff --git a/media/ffvpx/libavcodec/moz.build b/media/ffvpx/libavcodec/moz.build
index 761fc8cf4cd9..793a5b8697a8 100644
--- a/media/ffvpx/libavcodec/moz.build
+++ b/media/ffvpx/libavcodec/moz.build
@@ -120,10 +120,16 @@ if not CONFIG['MOZ_FFVPX_AUDIOONLY']:
         'vp9recon.c',
         'vpx_rac.c',
     ]
-    USE_LIBS += [
-        'dav1d',
-        'media_libdav1d_asm',
-    ]
+    if CONFIG["MOZ_SYSTEM_AV1"]:
+        CFLAGS += CONFIG['MOZ_SYSTEM_LIBDAV1D_CFLAGS']
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBDAV1D_LIBS']
+        CFLAGS += CONFIG['MOZ_SYSTEM_LIBAOM_CFLAGS']
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBAOM_LIBS']
+    else:
+        USE_LIBS += [
+            'dav1d',
+            'media_libdav1d_asm',
+        ]
     if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
         LOCAL_INCLUDES += ['/media/mozva']
         SOURCES += [
diff --git a/toolkit/moz.configure b/toolkit/moz.configure
index f93a5d64fec8..814357f4e979 100644
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -744,7 +744,23 @@ def av1(value):
         return True
 
 
-@depends(target, when=av1 & compile_environment)
+option("--with-system-av1",
+       help="Use system av1 (located with pkgconfig)")
+
+system_libaom_info = pkg_check_modules("MOZ_SYSTEM_LIBAOM", "aom >= 1.0.0",
+                                       when="--with-system-av1")
+
+system_libdav1d_info = pkg_check_modules("MOZ_SYSTEM_LIBDAV1D", "dav1d >= 0.1.1",
+                                         when="--with-system-av1")
+
+@depends(system_libaom_info, system_libdav1d_info)
+def system_av1(system_libaom_info, system_libdav1d_info):
+    has_av1_libs = False
+    if system_libaom_info and system_libdav1d_info:
+        has_av1_libs = True
+    return has_av1_libs
+
+@depends(target, when=av1 & depends(system_av1)(lambda v: not v) & compile_environment)
 def dav1d_asm(target):
     if target.cpu in ("aarch64", "x86", "x86_64"):
         return True
@@ -760,6 +776,7 @@ set_config("MOZ_DAV1D_ASM", dav1d_asm)
 set_define("MOZ_DAV1D_ASM", dav1d_asm)
 set_config("MOZ_AV1", av1)
 set_define("MOZ_AV1", av1)
+set_config("MOZ_SYSTEM_AV1", depends_if(system_av1)(lambda _: True))
 
 # JXL Image Codec Support
 # ==============================================================


