2

I want to create an mp3 file from the linux command line that is the concatenation of two mp3 files with a period of silence in the middle. I'm using the Google text-to-speech gtts package (https://pypi.org/project/gTTS/) to create the two (non-silent) mp3 files:

gtts-cli 'hello' --output hello.mp3
gtts-cli 'goodbye' --output goodbye.mp3

Then I create an mp3 file with the ffmpeg software:

ffmpeg -filter_complex aevalsrc=0 -t 10 10SecSilence.mp3

I listen separately to each of the mp3 audios and they're fine.

Then I concat the three audios with ffmpeg:

ffmpeg -i "concat:hello.mp3|10SecSilence.mp3|goodbye.mp3" -acodec copy test.mp3

Here's the output.

  ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_7 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mp3 @ 0x7fbe7b00d200] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'concat:hello.mp3|10SecSilence.mp3|goodbye.mp3':
  Duration: 00:00:10.85, start: 0.000000, bitrate: 64 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, mono, fltp, 64 kb/s
Output #0, mp3, to 'test.mp3':
  Metadata:
    TSSE            : Lavf58.45.100
    Stream #0:0: Audio: mp3, 44100 Hz, mono, fltp, 64 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp3 @ 0x7fbe7b010000] Audio packet of size 227 (starting with 49443304...) is invalid, writing it anyway.
size=      85kB time=00:00:11.61 bitrate=  60.0kbits/s speed=3.01e+03x    
video:0kB audio:85kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.291438%

When I listen to test.mp3 I hear "Hello", immediately followed by "Goodbye" and then the pause.

How can I fix this?

Updated to include output of ffmpeg concat command(above) and to show detail for each of the input streams (below).

ffmpeg -i hello.mp3 -i 10SecSilence.mp3 -i goodbye.mp3 test.mp3
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_7 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mp3 @ 0x7fc59e009600] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'hello.mp3':
  Duration: 00:00:00.77, start: 0.000000, bitrate: 32 kb/s
    Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Input #1, mp3, from '10SecSilence.mp3':
  Metadata:
    encoder         : Lavf58.45.100
  Duration: 00:00:10.03, start: 0.025057, bitrate: 64 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, mono, fltp, 64 kb/s
[mp3 @ 0x7fc59e00cc00] Estimating duration from bitrate, this may be inaccurate
Input #2, mp3, from 'goodbye.mp3':
  Duration: 00:00:00.82, start: 0.000000, bitrate: 32 kb/s
    Stream #2:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (mp3float) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'test.mp3':
  Metadata:
    TSSE            : Lavf58.45.100
    Stream #0:0: Audio: mp3 (libmp3lame), 24000 Hz, mono, fltp
    Metadata:
      encoder         : Lavc58.91.100 libmp3lame
size=       3kB time=00:00:00.76 bitrate=  36.4kbits/s speed=91.7x    
video:0kB audio:3kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.261029%

Updated to provide much more detail.

ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=44100 -t 10 10SecSilence.mp3
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_7 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, lavfi, from 'anullsrc=channel_layout=mono:sample_rate=44100':
  Duration: N/A, start: 0.000000, bitrate: 352 kb/s
    Stream #0:0: Audio: pcm_u8, 44100 Hz, mono, u8, 352 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_u8 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to '10SecSilence.mp3':
  Metadata:
    TSSE            : Lavf58.45.100
    Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, mono, s16p
    Metadata:
      encoder         : Lavc58.91.100 libmp3lame
size=      79kB time=00:00:10.00 bitrate=  64.3kbits/s speed= 310x    
video:0kB audio:78kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.282873%

$ cat input.txt 
file 'hello.mp3'
file '10SecSilence.mp3'
file 'goodbye.mp3'
$ ffmpeg -f concat -i input.txt -c copy output.mp3
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_7 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mp3 @ 0x7fa695009200] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'input.txt':
  Duration: N/A, start: 0.000000, bitrate: 32 kb/s
    Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Output #0, mp3, to 'output.mp3':
  Metadata:
    TSSE            : Lavf58.45.100
    Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp3 @ 0x7fa695013800] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 17856 >= 17831
[mp3 @ 0x7fa696019800] Estimating duration from bitrate, this may be inaccurate
size=      85kB time=00:00:11.59 bitrate=  59.9kbits/s speed=3.42e+03x    
video:0kB audio:85kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.273723%

hello.mp3 is here: https://drive.google.com/file/d/1VkT0Uuune8D9RnD5gZ4BgqHLY-ddorSt/view?usp=sharing

goodbye.mp3 is here: https://drive.google.com/file/d/1STdYIHhOeuWAQ5RONEiP5k0anrpUbNLt/view?usp=sharing

8
  • 1
    Show the complete output of ffmpeg -i hello.mp3 -i 10SecSilence.mp3 -i goodbye.mp3
    – llogan
    Jan 17, 2021 at 19:17
  • I added the output.
    – Sol
    Jan 17, 2021 at 19:28
  • 1
    You showed the output of your command (which is usually helpful), but I'm looking for the details of each file as provided by ffmpeg -i hello.mp3 -i 10SecSilence.mp3 -i goodbye.mp3. Your command does not provide individual details as using concat considered them to be 1 input.
    – llogan
    Jan 17, 2021 at 19:29
  • Ok. Ran your version of the command to show details of each of the input streams.
    – Sol
    Jan 17, 2021 at 19:37
  • 1
    M command isn't making an output. It was only to get file info.
    – llogan
    Jan 17, 2021 at 19:41

1 Answer 1

1

All inputs must have the same channel layout and sample rate. Your silent audio has a different sample rate. Make it again with:

ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=24000 -t 10 10SecSilence.mp3

Then use the concat demuxer instead of the concat protocol. The concat protocol is simplistic and doesn't work with most formats. I almost never use it.

Make input.txt containing:

file 'hello.mp3'
file '10SecSilence.mp3'
file 'goodbye.mp3'

Then concatenate:

ffmpeg -f concat -i input.txt -c copy output.mp3

If your input file names have spaces or special characters then add the -safe 0 input option to the concatenation command.

12
  • Using your recipe I get an 11-second audio that says hello, then goodbye then 11 seconds of silence. If I run your concat command without output.mp3 then it shows only one stream: concat from 'input.txt' and a message that trailing options(s) found in the command line may be ignored. I can log more output but I need to figure out what to log.
    – Sol
    Jan 17, 2021 at 20:11
  • If I do "ffmpeg -i hello.mp3 -i 10SecSilence.mp3 -i goodbye.mp3" then I see 3 inputs, and I get the same output that I already logged. In particular, the silent portion mp3 still has a bitrate of 64 kbps and goodbye.mp3 still starts at 0.
    – Sol
    Jan 17, 2021 at 20:18
  • @Sol Works for me. I can't duplicate the issue using the same version of ffmpeg. Show the contents of input.txt (if it differs from my example), your command (the one with -f concat) and the complete log. And provide links to your input files if possible.
    – llogan
    Jan 17, 2021 at 20:32
  • Do you have gtts installed to test gtts-cli and my entire process?
    – Sol
    Jan 17, 2021 at 20:42
  • @Sol I was hoping to avoid installing that (requires compilation on my distro).
    – llogan
    Jan 17, 2021 at 20:47

You must log in to answer this question.

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