1

Add Shorter audio to video with loop with volume control of both audio and video and with only for a specific duration ((i want to add audio and keep both audio and the videos sound in both cases))

I have two part of a problem

1) audio is 27 seconds long 2) Video is 2 mins 24 seconds long

a) I want to loop the audio and add it to the video for example (add audio only) from 50 seconds to 1 min 30 seconds (not the whole video but still get the whole video as output )within the video , with the looped audio

b) create a clip of video from 50 seconds to 1 min 30 seconds (not whole video as output)within the video , with the looped audio

I have used follwing command from ffmpeg to add audio to video , which adds it the whole video, how can we i) specify only a part of video to have the looped audio ii) create a new clip for the selected duration with the looped audio

so far I Have been able to loop, and change volume of both audio and video and mix them with following command for whole video

"-y","-i",videofile, "-filter_complex",
                        "amovie=audiofile:loop=1000,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.5[a1];" +
                        "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a2];" +
                        " [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
                        "-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", outputfile

I am stuck in managing time in both the cases

1

Use

amovie=audiofile:loop=1000,asetpts=N/SR/TB,atrim=0:40,adelay=50000|50000,apad,aformat=...

The trim keeps first 40 seconds of the looped audio, the adelay shifts its start time to 50000 milliseconds i.e. 50 seconds.

  • your solution worked, but created an issue it created a video file which is 90 sec long, right from the start of the video ie 0 sec, and audio starting from 50 sec to 90 sec,what I want is two thing 1) create a file which would start from say 50 sec and ends at 90 sec (in all just 40 sec long)with audio of (40 sec) that we have and 2) create a file which is of the original length(say 300sec) of the original video but have the audio from 50sec to 90sec part of the video, thanks for your help – 1234567 Oct 4 '17 at 11:43
  • For 1), add -ss 50 after the filters. For 2), remove -shortest. – Gyan Oct 4 '17 at 11:49
  • second part of my problem is solved, thanks, as regards to the first thing, I added -ss 50, but it created a new file which is 90 sec (50+40) , so i added -t 40 just to get a 40 sec long video, but then no audio was added can you help with that , again thanks – 1234567 Oct 4 '17 at 12:11
  • thanks Mulvya , your guidance was very helpful , i solved both issues I am sharing the code for others help aswell, again thanks – 1234567 Oct 4 '17 at 12:27
  • one more thing, @Mulvya, if a audio is a longer say 1 min and we want add just a part of the audio say from 18 sec to 35 sec with loop to the audio how can that be done – 1234567 Oct 4 '17 at 13:00
0

this is a code for adding a audio to video with 1) looping audio 2) change volume of both audio and video 3) create a new file of set duration only 4) create a file with original video duration and audio at a certain part of video

A) for new file of set duration only

"-y","-i",j,
                        "-filter_complex",
                        "amovie="+audio+":loop=999,asetpts=N/SR/TB," +
                                "atrim=0:40,adelay=50000|50000,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.5[a1];" +
                                "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=2.0[a2];" +
                                " [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
                        "-ss","50", "-t","40","-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-preset", "ultrafast", out

the thing we do is add "-ss","50", "-t","40"

b) for a file with original video duration and audio at a certain part of video

"-y","-i",j,
                            "-filter_complex",
                            "amovie="+audio+":loop=999,asetpts=N/SR/TB," +
                                    "atrim=0:40,adelay=50000|50000,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.5[a1];" +
                                    "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=2.0[a2];" +
                                    " [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
                            "-ss","50", "-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-preset", "ultrafast", out

the thing we do is add "-ss","50" but dont add "-t","40"`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.