从命令行创建无声 mp3

发布于 2024-10-21 08:06:40 字数 186 浏览 3 评论 0原文

我正在尝试使用命令行创建一个 (x) 秒的无声/空 mp3 文件。我认为这是一个非常简单的任务!

似乎 LAME 能够做这样的事情,但我找不到任何导致实现这一点。

有人能够做这样的事情吗?

I am trying to create a silent / empty mp3 file of (x) seconds using the command line. Quite a simple task I thought!

It seems LAME is able to do something like this, but I am unable to find anything that leads to achieving this.

Has anyone been able to do something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

黑寡妇 2024-10-28 08:06:40

您可以使用此命令。

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

更改为指示您需要的静默秒数的数字(例如,60 将创建一分钟)。

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).

暗藏城府 2024-10-28 08:06:40

免责声明:这是一种面向 UNIX 的方法(尽管 sox 是跨平台的,并且也应该只在 Windows 上完成)。

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");

然后只是 lame< /代码>它:

$ lame silence.wav silence.mp3

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
酒中人 2024-10-28 08:06:40

sox -n -r 44100 -c 2silence.wav trim 0.0 3.0 - 这将创建一个 3 秒立体声静音文件。
这里n代表空文件处理程序,r是采样率,c是通道数。

然后就让它变得跛脚:

$ lamesilence.wavsilence.mp3

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

白衬杉格子梦 2024-10-28 08:06:40

避免创建 wav 标头的麻烦,让 lame 处理原始文件:

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

设置 ?=2 给出 11 秒的文件(@ 标准 44KhZ 等...参数)。

注意:这是在 Unix 上测试的;我知道 Windows 上也有 dd 和 lame 。

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.

帥小哥 2024-10-28 08:06:40

另一个解决方案是将现有文件的音量设置为零

ffmpeg -i existing_music_file.wav -t 4 -filter:a "volume=0.0001" silent.wav

Another solution is to set volume to zero on existing file

ffmpeg -i existing_music_file.wav -t 4 -filter:a "volume=0.0001" silent.wav
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文