我想从 linux 命令行创建一个 mp3 文件,该文件是两个 mp3 文件的串联,中间有一段静默期。我正在使用 Google text-to-speech gtts 包(https://pypi.org/project/gTTS/)来创建两个(非静音)mp3 文件:
gtts-cli 'hello' --output hello.mp3
gtts-cli 'goodbye' --output goodbye.mp3
然后我用 ffmpeg 软件创建一个 mp3 文件:
ffmpeg -filter_complex aevalsrc=0 -t 10 10SecSilence.mp3
我分别收听每个 mp3 音频,它们都很好。
然后我用 ffmpeg 连接三个音频:
ffmpeg -i "concat:hello.mp3|10SecSilence.mp3|goodbye.mp3" -acodec copy 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 @ 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%
当我听 test.mp3 时,我听到“Hello”,紧接着是“Goodbye”,然后是停顿。
我怎样才能解决这个问题?
更新以包括 ffmpeg concat 命令的输出(上)并显示每个输入流的详细信息(下)。
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%
更新以提供更多详细信息。
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 在这里:https ://drive.google.com/file/d/1VkT0Uuune8D9RnD5gZ4BgqHLY-ddorSt/view?usp=sharing
goodbye.mp3 在这里:https ://drive.google.com/file/d/1STdYIHhOeuWAQ5RONEiP5k0anrpUbNLt/view?usp=sharing