3

I have MP3 files that tend to be very short, like 1 second, containing syllables of words. I would like to have an overlap (end of one merged with the beginning of the next one). I have found several topics about crossfading but I am not sure I need it (crossfading), i.e., to lower the volume of one and raise the volume of the next one as we transition into it. I think just a merge of the audio is enough at this time.

The overlap needs to be on the order of microseconds. I see FFmpeg has decimals of a seconds on some of the options. Currently I am concatenating of bunch of short MP3s with the following:

    /// <summary>
    /// <para/>20170114
    /// </summary>
    /// <returns></returns>
    public void ConcatMP3s(String InFiles, String OutputFile)
    {
        // http://superuser.com/questions/87040/how-to-stich-mp3s-together-with-ffmpeg
        var _IN_PARAMS = " -f concat ";
        var _IN_FILES = "-safe 0 -i " + DQuote(InFiles);
        var _OUT_PARAMS = " -c copy -y ";  // -y to overwrite the output file
        var _OUT_FILE = DQuote(OutputFile);
        //
        var _FFMPEG_ARGS = _IN_PARAMS + _IN_FILES + _OUT_PARAMS + _OUT_FILE;
        //return _FFMPEG_ARGS;
        //
        RunFFmpeg(_FFMPEG_ARGS);
    }

I would like a command or technique that will concatenate several files at once, but if you show me how to do it for two files, I can loop through all of them. It's an ugly but acceptable answer :).

@Mulvya, what I could grab from your link is the following FFmpeg command line structure (all in one command line string)

ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -i 4.mp3
   -filter_complex
     "[1]adelay=delay1|delay1[b];
      [2]adelay=delay2|delay2[c];
      [3]adelay=delay3|delay3[d];
      [0][b][c][d]amix=4"
merged.mp3

What do delay1, delay2, and delay3 need to be? Are they the durations in milliseconds of 1.mp3, 2.mp3, and 3.mp3 respectively?

What is the best way to retrieve these durations? e.g., are file-system file properties accurate?

Are the letters [b], [c], [d] something arbitrary? channel-names? I will need to generate?

Where do I specify, for example, 10 milliseconds overlap between 1.mp3 and 2.mp3, 2 and 3, and then 3 and 4?

Or should I minus 10 milliseconds from delay1, delay2, delay3?

Addition: here is a snapshot of a manual montage I put together to explain what I am trying to achieve programmatically (assume a constant overlap; here I am trying about 100 ms). Please explain what values for delay1, delay2, delay3 above should be.

snapshot of a manual montage

MP3 durations from FFmpeg output are 550, 440, 500, 960, 440 ms respectively.

========= Current Output from FFmpeg

_VDO\FFmpeg 20160310\bin\FFmpeg -i "S:\_W\ARP_WEB\SRC\SND\A4_23\1\01.mp3" -i "S:\_W\ARP_WEB\SRC\SND\A2\1\22.mp3" -i "S:\_W\ARP_WEB\SRC\SND\A2\3\23.mp3" -i "S:\_W\ARP_WEB\SRC\SND\A3\1\24.mp3" -i "S:\_W\ARP_WEB\SRC\SND\A2\2\03.mp3" -filter_complex "[1]adelay=279[b];[2]adelay=592[c];[3]adelay=916[d];[4]adelay=1712[e]; [0][b][c][d][e]amix=5" -y "S:\_W\ARP\AMSSTUDIO\SRC\DATA\FFMPEG\DEBUG Concat with Overlap\OUT.MP3"

ffmpeg version N-79000-g66edd86 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 5.3.0 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib libavutil 55. 19.100 / 55. 19.100 libavcodec 57. 28.100 / 57. 28.100 libavformat 57. 28.100 / 57. 28.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 39.102 / 6. 39.102 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [mp3 @ 0000000000584ba0] Estimating duration from bitrate, this may be inaccurate Input #0, mp3, from 'S:\_W\ARP_WEB\SRC\SND\A4_23\1\01.mp3': Duration: 00:00:00.55, start: 0.000000, bitrate: 320 kb/s Stream #0:0: Audio: mp3, 44100 Hz, mono, s16p, 320 kb/s [mp3 @ 00000000005a2a20] Estimating duration from bitrate, this may be inaccurate Input #1, mp3, from 'S:\_W\ARP_WEB\SRC\SND\A2\1\22.mp3': Duration: 00:00:00.44, start: 0.000000, bitrate: 320 kb/s Stream #1:0: Audio: mp3, 44100 Hz, mono, s16p, 320 kb/s [mp3 @ 000000000058af00] Estimating duration from bitrate, this may be inaccurate Input #2, mp3, from 'S:\_W\ARP_WEB\SRC\SND\A2\3\23.mp3': Duration: 00:00:00.50, start: 0.000000, bitrate: 320 kb/s Stream #2:0: Audio: mp3, 44100 Hz, mono, s16p, 320 kb/s [mp3 @ 000000000058cb80] Estimating duration from bitrate, this may be inaccurate Input #3, mp3, from 'S:\_W\ARP_WEB\SRC\SND\A3\1\24.mp3': Duration: 00:00:00.96, start: 0.000000, bitrate: 127 kb/s Stream #3:0: Audio: mp3, 44100 Hz, mono, s16p, 128 kb/s [mp3 @ 00000000005c5c00] Estimating duration from bitrate, this may be inaccurate Input #4, mp3, from 'S:\_W\ARP_WEB\SRC\SND\A2\2\03.mp3': Duration: 00:00:00.44, start: 0.000000, bitrate: 320 kb/s Stream #4:0: Audio: mp3, 44100 Hz, mono, s16p, 320 kb/s Output #0, mp3, to 'S:\_W\ARP\AMSSTUDIO\SRC\DATA\FFMPEG\DEBUG Concat with Overlap\OUT.MP3': Metadata: TSSE : Lavf57.28.100 Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, mono, fltp (default) Metadata: encoder : Lavc57.28.100 libmp3lame Stream mapping: Stream #0:0 (mp3) -> amix:input0 Stream #1:0 (mp3) -> adelay Stream #2:0 (mp3) -> adelay Stream #3:0 (mp3) -> adelay Stream #4:0 (mp3) -> adelay amix -> Stream #0:0 (libmp3lame) Press [q] to stop, [?] for help Error while filtering: Cannot allocate memory size= 5kB time=00:00:00.54 bitrate= 70.2kbits/s speed=42.3x video:0kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.938003%

9
  • Merging audio with overlap isn't that different from crossfading, and crossfading will give better results. You can do that e.g. with sox, but you may need to convert to .wav files first (which can be done in batch). Mp3 files encode audio in frames of a certain length, so you might not be able to do microsecond-scale overlapping audio in mp3 without re-encoding, anyway.
    – dirkt
    Jan 27, 2017 at 9:06
  • The answer here can be adapted.
    – Gyan
    Jan 27, 2017 at 15:35
  • You have created two user accounts. You should merge them. this account created question but your now using this account.
    – Ramhound
    Jan 27, 2017 at 19:28
  • I've edited for now, but yeah, you really need to ask for a merge, rather than posting what should be edits as an answer @marie
    – Journeyman Geek
    Jan 28, 2017 at 2:36
  • Welcome to Super User.  As others have said, it would appear that you have accidentally created two accounts.  Use the contact form and select “I need to merge user profiles” to have your accounts merged.  In order to merge them, you will need to provide links to the two accounts.  For your information, these are superuser.com/users/690627/marie and superuser.com/users/690629/marie.  You’ll then be able to edit, comment on, and accept answers to this question. Jan 28, 2017 at 7:16

1 Answer 1

1

Use a command of the form

ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -i 4.mp3
   -filter_complex
     "[1]adelay=delay1|delay1[b];
      [2]adelay=delay2|delay2[c];
      [3]adelay=delay3|delay3[d];
      [0][b][c][d]amix=4"
merged.mp3

Each delayN in milliseconds is the starting offset of an audio from the start of the audio stream. So, if you want file2 to start at 14.2 seconds of the final mix, use adelay=14200|14200 for a stereo input. You can use adelay=14200 for a mono input. In your screenshot, these are the Start column values.

The label pads [a] ..etc are arbitrary and assigned to the outputs of filters so that they can be used later in other filters or mapped for output. Each pad can be consumed once. They are alphanumeric but avoid assigning pure integers like [2] since ffmpeg uses those to refer to the input files.

2
  • below is the command line I am attempting to prototype with according to your explanation. I used the start column values and mono. ffmpeg seems to fail allocating memory? and barely mixes the first two files when I view the waveform. Also, please let me know what is the best way to obtain the durations of these files, Windows file property dialog seem to show 00:00:00 but I have not attempted to actually query the filesystem API (hopefully it's only trimming the fractional part of the seconds in the "humans" dialog). (See tail of base post, I can't type here anymore)
    – Meryan
    Jan 28, 2017 at 22:43
  • Upgrade ffmpeg and try. Your ffmpeg is over 4000 commits old. If it still fails, run with -report added. Link to the report file.
    – Gyan
    Jan 29, 2017 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .