diff --git a/ffmpeg.c b/ffmpeg.c
index 7ac8228a745be5c3e2a193d10cf9ac1b3785ddbf..d755c9e173b3f70f8f9e1b4cf23aaf4eda724c85 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2371,6 +2371,9 @@ static void opt_output_file(const char *filename)
 
             audio_enc = &st->codec;
             audio_enc->codec_type = CODEC_TYPE_AUDIO;
+
+            if(!strcmp(file_oformat->name, "mp4") || !strcmp(file_oformat->name, "mov") || !strcmp(file_oformat->name, "3gp"))
+                audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
             if (audio_stream_copy) {
                 st->stream_copy = 1;
             } else {