windows 从命令行创建无声 mp3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5276253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create a silent mp3 from the command line
提问by Stephen
I am trying to create a silent / empty mp3 file of (x) seconds using the command line. Quite a simple task I thought!
我正在尝试使用命令行创建 (x) 秒的无声/空 mp3 文件。我认为这是一个相当简单的任务!
It seems LAMEis able to do something like this, but I am unable to find anything that leads to achieving this.
似乎LAME能够做这样的事情,但我找不到任何可以实现这一目标的东西。
Has anyone been able to do something like this?
有没有人能够做这样的事情?
采纳答案by miku
Disclaimer: This is a unix-oriented approach (although sox is cross-platform and should get it done on windows only as well).
免责声明:这是一种面向 Unix 的方法(尽管 sox 是跨平台的,并且也只能在 Windows 上完成)。
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
您将需要sox- “声音处理程序的 [跨平台] 瑞士军刀”。
这个包装 perl 脚本可帮助您生成任何几秒钟的静音: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:
silence.pl
很短,所以我把它包括在这里,因为它是公共领域:
#!/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
这样吧:
$ lame silence.wav silence.mp3
回答by nico_lab
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).
更改<seconds>
为一个数字,指示您需要的静音秒数(例如,60
将创建一分钟)。
回答by user495100
Avoid the nuisance of creating a wav header, and let lame handle a raw file:
避免创建 wav 头的麻烦,让 lame 处理原始文件:
dd if=/dev/zero bs=1M count=? | lame -r - - > silence.mp3
setting ?=2 gives a 11 second file (@ standard 44KhZ, etc... parameters).
设置 ?=2 给出了一个 11 秒的文件(@标准 44KhZ 等...参数)。
Note: this was tested on Unix; I understand there are dd and lame for windows, too.
注意:这是在 Unix 上测试的;我知道 Windows 也有 dd 和 lame。
回答by Anees Sadeek
sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0
- this will create a 3sec stereo silence file.
Here nfor null file handler, ris the sample rate and cis the number of channels.
sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0
- 这将创建一个 3 秒的立体声静音文件。这里n表示空文件处理程序,r是采样率,c是通道数。
Then just lame it:
然后只是跛脚它:
$ lame silence.wav silence.mp3
$ lame silence.wav silence.mp3