diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index bbfc42b2b79665261df896fb8d28a417b648d220..ed7aaa0f86f410f516718adcff73cad6c4db9ddf 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -343,10 +343,12 @@ int av_opt_show(void *obj, void *av_log_obj){
  *
  * @param s AVCodecContext or AVFormatContext for which the defaults will be set
  */
-void av_opt_set_defaults(void *s)
+void av_opt_set_defaults2(void *s, int mask, int flags)
 {
     const AVOption *opt = NULL;
     while ((opt = av_next_option(s, opt)) != NULL) {
+        if((opt->flags & mask) != flags)
+            continue;
         switch(opt->type) {
             case FF_OPT_TYPE_CONST:
                 /* Nothing to be done here */
@@ -379,3 +381,7 @@ void av_opt_set_defaults(void *s)
     }
 }
 
+void av_opt_set_defaults(void *s){
+    av_opt_set_defaults2(s, 0, 0);
+}
+
diff --git a/libavcodec/opt.h b/libavcodec/opt.h
index 1d750ff2964cc1a8b5307a5053cf859177f6e06b..151dbb788eb01fe16fc52031e7f239536abbaaa1 100644
--- a/libavcodec/opt.h
+++ b/libavcodec/opt.h
@@ -80,5 +80,6 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c
 const AVOption *av_next_option(void *obj, const AVOption *last);
 int av_opt_show(void *obj, void *av_log_obj);
 void av_opt_set_defaults(void *s);
+void av_opt_set_defaults2(void *s, int mask, int flags);
 
 #endif