Trimming and fading out video/audio with ffmpeg

I recently wanted to trim and fade out an MP4 file. I wasn’t inclined at the effort of putting it in a non-linear editor and was looking for a quick way to achieve this.

I found that ffmpeg had the necessary functionality to do this. The command I used in the end was:

ffmpeg -i in.mp4 -ss 00:00:00 -t 00:05:00 -vf "fade=t=out:st=297:d=3" -af "afade=t=out:st=297:d=3" out.mp4

The commands are:

  • -i in.mp4 is the input file
  • -ss 00:00:00 is where the video should start from (set this to other than zero to trim the start)
  • -t 00:05:00 is the duration of the video, trimming any video after that
  • -vf "fade=t=out:st=297:d=3" is a video filter which fades out at 297 seconds (4:57) over a 3 second duration
  • -af "afade=t=out:st=297:d=3" is the corresponding audio filter which fades out at 297 seconds (4:57) over a 3 second duration
  • out.mp4 is the output file

The video and audio filters have several more properties you can play with, such as if you want to fade to white using a log curve for the audio fade.

You can also combine filter commands by separating them with a comma, if you want both a fade in and fade out, for example:

-vf "fade=t=in:st=0:d=3,fade=t=out:st=297:d=3" -af "afade=t=out:st=0:d=3,afade=t=out:st=297:d=3"


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *