0

I am trying to use FFmpeg to insert an audio clip at every 60 seconds into an audio file. I also want to delay the original audio stream until the end of the inserted audio clip , so that the inserted audio doesn't overlap with the original audio.

I would prefer a solution that doesn't involve splitting the original file into 60 seconds videos and then combine then together , as it makes the following steps, that I have to do, many times more complex.

Possible Solution:

I think the -ss flag could be used to set the timestamp of the inserted audio clip to 60 seconds after the end of the last segment. Then, I could use a delay filter to delay the original audio track until the end of the inserted audio clip.

However I am not sure how to create command. Mainly the part , where we apply this filter at every 60 seconds intervals.

Thanks for any help in advance!!

1 Answer 1

0

concat demuxer

#!/bin/bash

f="../input.mp3"
a="in.mp3"

# get duration of input
d=$(ffprobe -v 0 -show_entries format=duration -of default=nw=1:nk=1 "$f")

# get seconds
d=${d%.*}
echo $d

# variables
i=0
o=60

# create list of inputs
l="list.txt"
echo "ffconcat version 1.0" > $l
echo "file '$f'" >> $l
echo "outpoint $o" >> $l
# increase variables by 60 sec
i=$o
((o+=60))
while (( $i < $d )); do
    # insert audio clip
    echo "file '$a'" >> $l
    # add audio next 60 sec
    echo "file '$f'" >> $l
    echo "inpoint $i" >> $l
    echo "outpoint $o" >> $l
    # increase variables by 60 sec
    i=$o
    ((o+=60))
done
cat $l

ffmpeg -f concat -safe 0 -i "$l" -c copy output.mp3 -y

ffplay output.mp3
1
  • could you please explain me, how this solves it , so I can extend and use it to my needs?
    – Aarav Shah
    Commented Jan 21 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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