diff --git a/output_example.c b/output_example.c
index 6cd1b34080bd3b22eec1c70b4cd081d328969391..82df06b8bff0edbdcc781d018dbe81603ba9a099 100644
--- a/output_example.c
+++ b/output_example.c
@@ -224,7 +224,7 @@ static AVStream *add_video_stream(AVFormatContext *oc, int codec_id)
         c->mb_decision=2;
     }
     // some formats want stream headers to be separate
-    if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name, "mov") || !strcmp(oc->oformat->name, "3gp"))
+    if(oc->oformat->flags & AVFMT_GLOBALHEADER)
         c->flags |= CODEC_FLAG_GLOBAL_HEADER;
 
     return st;