简体   繁体   English

需要帮助使用 ffmpeg 来“连接”多个音频文件(webm、mp4)以制作更长的 MP3 音频

[英]need help using ffmpeg to "concat" multiple audio files (webm, mp4) to make one longer MP3 of audio

I have done some searching (for several hours) and tried to manipulate many examples to work for me, but I still keep coming up empty here.我已经做了一些搜索(几个小时)并试图操纵许多例子来为我工作,但我仍然在这里空空如也。

I am using linux-mint 19, with ffmpeg installed.我正在使用 linux-mint 19,并安装了 ffmpeg。 I have a folder with several audio files.我有一个文件夹,里面有几个音频文件。 The majority of these are "webm" (with no video) and there are a few "m4a".其中大部分是“webm”(没有视频),还有一些“m4a”。 I am trying to make one long mp3 file from the audio in all of these strung together from start to finish.我试图从所有这些从头到尾串在一起的音频制作一个长的 mp3 文件。

Lets say for sake of argument, my directory has the following files:让我们说为了争论,我的目录有以下文件:

audio file a.webm
audio file b.webm
audio file c.m4a
audio file d.webm

I found a script that I could write online where someone is creating a file called "mylist.txt" with this bit of code:我找到了一个可以在线编写的脚本,其中有人使用以下代码创建了一个名为“mylist.txt”的文件:

    # with a bash for loop
for f in ./*.*; do echo "file '$f'" >> mylist.txt; done
# or with printf
printf "file '%s'\n" ./*.* > mylist.txt

this generated a text file with the following type of content:这生成了一个具有以下内容类型的文本文件:

file './audio file a.webm'
file './audio file b.webm'
file './audio file c.m4a'
file './audio file d.webm'

first, I believe the "./" is causing a problem, because when I look at other examples I don't see this but I am not sure why it is generating this way in my script because I don't see this in web examples online.首先,我相信“./”导致了问题,因为当我查看其他示例时,我没有看到这一点,但我不确定为什么它会在我的脚本中以这种方式生成,因为我在网络中看不到这个网上的例子。 Second, I have tried to "concate" this with ffmpeg but I'm not sure which is the best option.其次,我试图用 ffmpeg 来“连接”它,但我不确定哪个是最好的选择。 I found some documentation here:我在这里找到了一些文档:

https://trac.ffmpeg.org/wiki/Concatenate https://trac.ffmpeg.org/wiki/Concatenate

however this example applies to video specifically但是这个例子特别适用于视频

Can anyone lead me in the right direction?任何人都可以引导我朝着正确的方向前进吗?

EDIT******编辑******

I tried the solution below, with "mylist.txt" as the input and I am getting an error:我尝试了下面的解决方案,以“mylist.txt”作为输入,但出现错误:

    user@machine/TEMP$ ffmpeg -i mylist.txt -filter_complex "[0:a][1:a][2:a][3:a]concat=n=20:a=1:v=0[a]" -map "[a]" output.mp3
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, tty, from 'mylist.txt':
  Duration: 00:00:00.40, bitrate: 47 kb/s
    Stream #0:0: Video: ansi, pal8, 640x400, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream specifier ':a' in filtergraph description [0:a][1:a][2:a][3:a]concat=n=20:a=1:v=0[a] matches no streams.

The concat demuxer works best with inputs that all have the same attributes. concat demuxer最适合所有具有相同属性的输入。 The concat demuxer documentation states, "All files must have the same streams (same codecs, same time base, etc.)" The concat demuxer is good for when you are trying to avoid re-encoding, but that is not possible with inputs of various formats. concat demuxer文档指出, “所有文件必须具有相同的流(相同的编解码器、相同的时基等)” concat demuxer 非常适合当您试图避免重新编码时,但这对于输入各种格式。

You are providing inputs with arbitrary attributes.您正在提供具有任意属性的输入。 Use concat filter instead:改用concat 过滤器

ffmpeg -i a.webm -i b.webm -i c.m4a -i d.webm -filter_complex "[0:a][1:a][2:a][3:a]concat=n=4:a=1:v=0[a]" -map "[a]" output.mp3

Note from the concat filter documentation: "The filtering system will automatically select a common sample format, sample rate, and channel layout for audio streams."来自 concat 过滤器文档的注意事项: “过滤系统将自动为音频流选择通用的采样格式、采样率和通道布局。”

If you want to manually select the sample rate and channel layout, so you know exactly what you will get, add the aformat filter :如果你想手动选择采样率和通道布局,这样你就知道你会得到什么,添加aformat 过滤器

ffmpeg -i a.webm -i b.webm -i c.m4a -i d.webm -filter_complex "[0:a]aformat=r=44100:cl=stereo[a0];[1:a]aformat=r=44100:cl=stereo[a1];[2:a]aformat=r=44100:cl=stereo[a2];[3:a]aformat=r=44100:cl=stereo[a3];[a0][a1][a2][a3]concat=n=4:a=1:v=0[a]" -map "[a]" output.mp3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM