0

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.

Shubham AgaRwal
  • 4,355
  • 8
  • 41
  • 62
user2455079
  • 420
  • 4
  • 16
  • 1
    The post title says Melt but the ffmpeg tag is used. Will ffmpeg answers work? If yes, is the audio the correct length already or do you need it trimmed? – Gyan Aug 04 '16 at 20:02
  • @Mulvya, mlt is preferred, audio must be trimmed... – user2455079 Aug 05 '16 at 19:03

1 Answers1

3

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
Brian
  • 1,200
  • 6
  • 8
  • That works, but how can i overwrite (mute) original soundtrack? And another question: Can i change volume of added track or changing it during video clip? – user2455079 Aug 08 '16 at 09:25
  • Just tested, partially works, sound keeps playing after out=500 and extends all video file with white screen after it ends... Need to mute original clips sound with adding soundtrack and on some of them keep original sound without adding soundtrack. – user2455079 Aug 08 '16 at 10:24
  • Command i'm using: http://files.dangerd.org/pub/tmp/mlt.txt -blank 300 between tracks doesn't work, music keeps playing, what i've missed? – user2455079 Aug 08 '16 at 10:38
  • I edited the answer with some additional information. – Brian Aug 08 '16 at 17:04