Fügen Sie Stille am Ende einer MP3 hinzu

8044
Max Williams

Kennen einige von Ihnen eine Möglichkeit, das Ende eines MP3s in Linux um eine festgelegte Dauer zu verlängern? Zum Beispiel mit MEncoder, FFmpeg usw.?

Es muss eine Befehlszeile sein, da es auf unserem Server Skript erstellt und ausgeführt wird.

Ich habe gegoogelt und das Beste, was ich tun kann, ist die Verwendung der padFunktion in SoX, aber das funktioniert nicht mit MP3s.

Ich könnte es in WAV konvertieren, SoX verwenden, es dann wieder in MP3 konvertieren und die Metadaten (abzüglich der Dauer) vom Original in die neue MP3-Datei kopieren. Aber bevor ich ein Skript dafür schreibe, dachte ich, ich würde sehen, ob es eine One-Hit-Lösung gibt.

8
I think you can accomplish something like this with [mp3DirectCut](http://mpesch3.de1.cc/mp3dc.html) (Windows only, but they say it's compatible with Linux under Wine), which avoids recompressing the sound data. If you were to go MP3 -> WAV -> MP3, you would be recompressing the already MP3 compressed data stream, losing a lot of quality on the way. Breakthrough vor 11 Jahren 2
Thanks. Can you run windows software via Wine from the command line? I'd prefer to avoid Wine solutions if possible as i'm reluctant to install Wine on our server. Max Williams vor 11 Jahren 0
Hmm, you might want to avoid the Wine route if you don't have it already. Wine itself is a fairly large download, well above a megabyte or two for a simple MP3 cut/merge tool. I'm sure there's an equivalent, Linux-native solution. If I find any additional tools, I'll be sure to let you know. Breakthrough vor 11 Jahren 0

2 Antworten auf die Frage

12
evilsoup

With ffmpeg, you can use the aevalsrc filter to generate silence, and then in a second command use the concat protocol to combine them losslessly:

ffmpeg -filter_complex aevalsrc=0 -t 10 10SecSilence.mp3 ffmpeg -i "concat:input.mp3|10SecSilence.mp3" -c copy output.mp3 

You can control the length of silence by altering -t 10 to whatever time in seconds you would prefer. Of course, you only need to generate the silence once, then you can keep the file around and use it to pad each of the files you want to. You may also want to look up the concat demuxer - it's slightly more processor-intensive, but you may find it easier to drop into a shell script.

If you want to do it in a single command, you can use the concat filter - this will require you to re-encode your audio (since filtergraphs are incompatible with -codec copy), so the option above will probably be best for you. But this may be useful for anyone working with raw PCM, looking to add silence to the end before encoding the audio:

ffmpeg -i input.mp3 \ -filter_complex 'aevalsrc=0::d=10[silence];[0:a][silence]concat=n=2:v=0:a=1[out]' \ -map [out] -c:a libmp3lame -q:a 2 output.mp3 

Control the length of the silence by changing d=10 to whatever time (in seconds) you want. If you use this method, you may find this FFmpeg MP3 encoding guide useful.

thanks @evilsoup. I just tried that and got the following - max-thinkpad-linux:~ $ ffmpeg -filter_complex aevalsrc=0 -t 4.61 silence.mp3 `ffmpeg version 0.8.4-4:0.8.4-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers built on Nov 6 2012 16:51:33 with gcc 4.6.3 *** THIS PROGRAM IS DEPRECATED *** This program is only provided for compatibility and will be removed in a future release. Please use avconv instead. Unrecognized option 'filter_complex' Failed to set value 'aevalsrc=0' for option 'filter_complex' ` Max Williams vor 11 Jahren 0
@max First of all, you're actually using avconv from the libav project - they're a fork of FFmpeg that Debian & Ubuntu are using instead of the main project, and they provide a crippled version of ffmpeg. Try using `avconv` instead - the syntax should be the same, just replace `ffmpeg` with `avconv`. evilsoup vor 11 Jahren 0
Wenn dies nicht funktioniert, versuchen Sie, ein Upgrade auf eine neuere Version von ffmpeg durchzuführen. Da Sie sich auf Ubuntu befinden, sollten Sie [diese PPA] (https://launchpad.net/~jon-severinsson/+archive/ffmpeg) oder die neueste Version verwenden können, die Sie aus dem Quellcode kompilieren können ] (https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide). evilsoup vor 11 Jahren 0
@ MaxWilliams Oder Sie können [statischen Build herunterladen] (http://ffmpeg.org/download.html), den Sie nicht erst kompilieren müssen. Einfach herunterladen, extrahieren, verwenden. slhck vor 11 Jahren 1
Schön, dass Sie nicht neu codieren müssen. Wie können die Metatags in die neue Datei kopiert werden? StormPooper vor 9 Jahren 0
6
Fabien Snauwaert

Mit dem padArgument von SoX und der folgenden Syntax können Sie dies problemlos tun :

sox <oldfile> <newfile> pad <silence at beginning of file> <silence at end of file> 

Beispiel:

sox mp3.mp3 mp3withsilence.mp3 pad 0 1 

Diese Stille ist in Sekunden. (Andere Verwendungen sind mit einer anderen Syntax möglich, um diese Stille an bestimmten Positionen einzufügen. Weitere Informationen finden Sie in der SoX-Dokumentation.)

Ich sollte beachten, dass ich es mit MP3-Dateien getestet habe (mit libmad-0.dll und libmp3lame-0.dll für die Decodierung und Codierung von MP3s.). Soweit möglich, würde ich empfehlen, mit einem verlustfreien Format zu arbeiten und nur zu konvertieren MP3 nur am Ende. Fabien Snauwaert vor 10 Jahren 0
das ist echt cool - danke fabien! Max Williams vor 10 Jahren 0
Ist das verlustfrei? Geremia vor 6 Jahren 0
Update: Ich habe in der Sox-Manpage gelesen, dass sie in ein internes Format konvertiert und dann neu codiert… Geremia vor 6 Jahren 0
MP3 ist ein verlustbehaftetes Format. Durch das Kodieren und Umcodieren in ein verlustbehaftetes Format wird die Qualität des Audios nach und nach verschlechtert (unabhängig davon, ob Sie es hören oder nicht.) Daher empfiehlt es sich, mit verlustfreien Formaten zu arbeiten und am Ende nur ein verlustbehaftetes Format zu kodieren. Eine Liste der verlustbehafteten Audiocodecs finden Sie unter https://en.wikipedia.org/wiki/Lossy_compression#Audio und eine Liste der verlustfreien Audiocodecs https://en.wikipedia.org/wiki/Lossless_compression#Audio Fabien Snauwaert vor 6 Jahren 0