Create a silent mp3 from the command line

旧城冷巷雨未停 提交于 2019-12-03 02:49:54
miku

Disclaimer: This is a unix-oriented approach (although sox is cross-platform and should get it done on windows only as well).

  • You'll need sox - "the [cross-platform] Swiss Army knife of sound processing programs".

  • This wrapper perl script, helps you generate any seconds of silence: http://www.boutell.com/scripts/silence.html

    $ perl silence.pl 3 silence.wav
    

silence.pl is quite short, so I include it here, since it's public domains:

#!/usr/bin/perl

$seconds = $ARGV[0];
$file = $ARGV[1];
if ((!$seconds) || ($file eq "")) {
        die "Usage: silence seconds newfilename.wav\n";
}

open(OUT, ">/tmp/$$.dat");
print OUT "; SampleRate 8000\n";
$samples = $seconds * 8000;
for ($i = 0; ($i < $samples); $i++) {
        print OUT $i / 8000, "\t0\n";
}
close(OUT);

# Note: I threw away some arguments, which appear in the original
# script, and which did not worked (on OS X at least)
system("sox /tmp/$$.dat -c 2 -r 44100 -e signed-integer $file");
unlink("/tmp/$$.dat");

Then just lame it:

$ lame silence.wav silence.mp3

You can use this command.

ffmpeg -f lavfi -i anullsrc=r=44100:cl=mono -t <seconds> -q:a 9 -acodec libmp3lame out.mp3

Change <seconds> to a number indicating the number of seconds of silence you require (for example, 60 will create a minute).

Avoid the nuisance of creating a wav header, and let lame handle a raw file:

dd if=/dev/zero bs=1M count=? | lame -r - - > silence.mp3

setting ?=2 gives a 11 second file (@ standard 44KhZ, etc... parameters).

Note: this was tested on Unix; I understand there are dd and lame for windows, too.

sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0 - this will create a 3sec stereo silence file. Here n for null file handler, r is the sample rate and c is the number of channels.

Then just lame it:

$ lame silence.wav silence.mp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!