3

I need to insert a short beep into another audio file (similar to a censorship bleep) using linux and/or php.

I'm thinking there should be some way to do it with ffmpeg (with some combination of -t, concat, map, async, adelay, itsoffset?) or avconv or mkvmerge - but haven't found anyone doing this. Maybe I need to do it in 2 stages somehow?

For example if I have a 60 second mp3 and want to beep out 2 seconds at 2 places the desired result would be:

0:00-0:15  from original
0:15-0:17  beep (overwrites the 2 secs of original)
0:17-0:40  from original
0:40-0:42  beep
0:42-0:60  from original

I have a 2 second beep.mp3, but can use something else instead like -i "sine=frequency=1000:duration=2"

Redzarf
  • 2,578
  • 4
  • 30
  • 40
  • Thanks @pepperjack - I just reread https://stackoverflow.com/help/on-topic to check, and I think this is the right place. A good clue is the ffmpeg tag above has 14k questions :-) (superuser has 4k questions for the same tag - maybe the person who knows the answer would only see it there, but I thought better to try here first). – Redzarf Dec 28 '17 at 20:51

2 Answers2

4

You can use the concat demuxer.

Create a text file, e.g.

file main.wav
inpoint 0
outpoint 15
file beep.wav
file main.wav
inpoint 17
outpoint 40
file beep.wav
file main.wav
inpoint 40
outpoint 42

and then

ffmpeg -f concat -i list.txt out.mp3

Convert the beep file to have the same sampling rate and channel count as the main audio.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Great! +1 for you. I was able to `concat` the files, but I have a problem with the inpoints and outpoints. I posted a question here:https://stackoverflow.com/questions/51305770/adding-silence-between-words-in-audio-file-using-ffmpeg I hope you can take a look and help me with this. Thanks again. – Joe T. Boka Jul 12 '18 at 12:36
1

First, you need to have beep.mp3 time equal to 60 seconds or little bit less than your mp3 file time.

Then, you can use ffmpeg code -ss <start_time> -t <duration> -i <your_file>.mp3

ffmpeg -ss 00:00:00 -t 15 -i ./original.mp3 -ss 00:15:00 -t 2 -i ./beep.mp3 -ss 00:17:00 -t 23 -i ./original.mp3 -ss 00:40:00 -t 2 -i ./beep.mp3 -ss 00:42:00 -i ./original.mp3 -filter_complex '[0:0][1:0] concat=n=2:v=0:a=1[out]' -map '[out]' ./output.mp3

at the end you will get output.mp3 file as you needed.

  • You're missing the `-i` before some of the inputs. `ffmpeg` will not automatically concatenate or downmix the segments, so the output will only consist of the longest segment. You'll need to use filters to do that such as the concat filter. – llogan Apr 02 '19 at 16:51
  • Oh! I missed to add filter complex and -i. Thank you llogan. I have edited above answer. – pushpika liyanaarachchi Apr 03 '19 at 06:26