diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7a1f6ddb280128aed3089294bec7390e940c218a..914010c6a1779ac59fdf17959659cc0614a3f232 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -515,9 +515,9 @@ static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
     put_be16(pb, 1); /* Frame count (= 1) */
     
     memset(compressor_name,0,32);
-    if (track->enc->codec->name)
+    if (track->enc->codec && track->enc->codec->name)
         strncpy(compressor_name,track->enc->codec->name,31);
-    put_byte(pb, FFMAX(strlen(compressor_name),32) );
+    put_byte(pb, strlen(compressor_name));
     put_buffer(pb, compressor_name, 31);
     
     put_be16(pb, 0x18); /* Reserved */