Is there a way to add a "fade to black" effect to a video, from the command line?

I have a script to encode videos (using mencoder), but is there a way to add a simple "fade out/in to black" from the command line, preferably free (as in open source).

It could be either on Windows or Ubuntu Linux.


The only thing I could find – based on the command line – is mmsuper8, a Linux tool.

Specifically, it features the mmsuper8fade tool, which seems like it could be useful for you.

Best would be if you edit this question and supply an example that worked for you!


A recent ffmpeg with the 'fade' video filter can do this. Unfortunately, the ffmpeg in the Ubuntu repos doesn't have filters enabled for some inane reason, so you'll have to get it from somewhere else (see here).

To fade in from black, starting at frame 0, over 50 frames (2 seconds @ 25fps):

ffmpeg -i input.mp4 -filter:v 'fade=in:0:50' \
-c:v libx264 -crf 22 -preset veryfast -c:a copy output.mp4

To fade out starting at frame 21000 (14 minutes @ 25fps), over 50 frames:

ffmpeg -i input.mp4 -filter:v 'fade=out:21000:50' \
-c:v libx264 -crf 22 -preset veryfast -c:a copy output.mp4

You can combine the two into a filterchain:

ffmpeg -i input.mp4 -filter:v 'fade=in:0:50,fade=out:21000:50' \
-c:v libx264 -crf 22 -preset veryfast -c:a copy output.mp4

As you can see from these examples, you have to transcode video when using a video filter. Since ffmpeg and mencoder share many libraries, it should be fairly easy to re-write your scripts to use ffmpeg instead of mencoder & avoid an unnecessary extra encode. I'm pretty sure that you can achieve the same thing in mencoder, but I don't know mencoder syntax.