mlt

MLT framework (melt) add music only to specified time in video


Need to add music to video only to some parts For example from 100frame to 500frame (4s - 20s)

Overall task is to merge a lot of videos and add music only to some of them.


Solution

  • You can put the audio and video on different tracks and use the mix transition to combine the audio.

    # melt video.mp4 \
       -audio-track -blank 100 audio.mp3 \
       -transition mix in=100 out=500 a_track=0 b_track=1
    

    Further explanation here: https://www.mltframework.org/bin/view/MLT/MltMelt#Transitions

    Mix transition documentation here: https://www.mltframework.org/bin/view/MLT/TransitionMix

    EDIT1:

    To mute the audio from a video clip, you can apply the volume filter:

    # melt video.mp4 -attach-clip volume gain=0 ...
    

    To change the volume of a clip, you can also apply the volume filter:

    ... -audio-track -blank 100 audio.mp3 -attache-clip volume gain=3dB ...
    

    Volume filter documentation: https://www.mltframework.org/bin/view/MLT/FilterVolume

    To stop the music playing, you should set an "out" point. Also, you should put all the audio clips on one track and then specify the transitions:

    # melt video.mp4 -attach-clip volume gain=0 \
       -audio-track -blank 100 audio1.mp3 out=400 -blank 300 audio2.mp3 out=400 \
       -transition mix in=100 out=500 a_track=0 b_track=1
       -transition mix in=800 out=1200 a_track=0 b_track=1