MLT / melt: concatenate clips, fade-in/fade-out audio and video

2.3k views Asked by At

I am attempting to automate a mundane video-editing task that I perform on a weekly basis. I would like to use melt to do this.

Assume that I have videos a, b, and c. I would like to do the following:

  1. Snip a1, b1, and c1 from within a, b, and c.
  2. Concatenate a1, b1, and c1 into a single video.
  3. Fade to/from black for one second when transitioning between a1, b1, and c1.
  4. Apply a soundtrack to the concatenated output of a1, b1, and c1, while also preserving the original audio.
  5. Fade out the soundtrack as c1 fades to black (concluding the video).

Whereby:

  1. a, b, and c are of an arbitrary length.
  2. a, b, and c are all 1080p videos filmed at 60 frames per second.
  3. a, b, c, a1, b1, and c1 are all .mp4 files.
  4. The soundtrack is an .mp3 file.

This is as close as I have gotten:

#!/bin/sh
melt \
  colour:black out=59 $VIDEO1 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  colour:black out=59 $VIDEO2 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  colour:black out=59 $VIDEO3 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  -audio-track $AUDIO -transition mix

(I'm using arbitrary placeholders for the relevant files and fade-in/out times in the example above.)

This succeeds in snipping and concatenating a1, b1, and c1 with animated transitions. However:

  1. If $AUDIO is longer than the concatenation of a1, b1, and c1, the audio continues to play (with a white screen) after the video has ended.

  2. The soundtrack does not fade out when c1 fades out (ie, when the video is over).

From what I've gathered, fading out the soundtrack may be accomplished by "animating the volume audio filter", but I have had no success in attempting that.

What should I try?

Thanks for your help.

1

There are 1 answers

3
Brian On BEST ANSWER

For #1, you need to set an out point for the audio. You have three 601 frame clips (the zeroth frame counts as one) for a total of 1803 frames. So set out=1802.

For #2, you can apply the volume filter to the end of the audio track to make it fade out.

See the documentation for the volume filter to understand the gain and end parameters: https://www.mltframework.org/plugins/FilterVolume/

#!/bin/sh
melt \
  colour:black out=59 $VIDEO1 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  colour:black out=59 $VIDEO2 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  colour:black out=59 $VIDEO3 in=0 out=600 -mix 60 -mixer luma \
  colour:black out=59 -mix 60 -mixer luma \
  -audio-track $AUDIO out=1802 -attach-track volume:0db end=-70db in=1703 out=1802 \
  -transition mix in=0 out=1802