diff --git a/cmdutils.c b/cmdutils.c
index d27759ea934a904ec333ed922d5e59f9cdd2756d..00c5d7114453531b91ff44a3b2a3cac8b2360a1e 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -423,6 +423,12 @@ int opt_loglevel(const char *opt, const char *arg)
     return 0;
 }
 
+int opt_codec_debug(const char *opt, const char *arg)
+{
+    av_log_set_level(AV_LOG_DEBUG);
+    return opt_default(opt, arg);
+}
+
 int opt_timelimit(const char *opt, const char *arg)
 {
 #if HAVE_SETRLIMIT
diff --git a/cmdutils.h b/cmdutils.h
index d1e84e0d90f27439ac8ca7179a72bf8c2b5d46f5..7a8c69b50d60de9af3b3f953f5a783b9b5942796 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -76,6 +76,8 @@ int opt_default(const char *opt, const char *arg);
  */
 int opt_loglevel(const char *opt, const char *arg);
 
+int opt_codec_debug(const char *opt, const char *arg);
+
 /**
  * Limit the execution time.
  */
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index 70b0d83fc5f49d49f554616794901fdcc1ea38ef..cced0bb89504d8ded54713ff47ab589f31c9f401 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -13,3 +13,4 @@
     { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show available audio sample formats" },
     { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
     { "v", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
+    { "debug", HAS_ARG, {(void*)opt_codec_debug}, "set debug flags", "flags" },