使用带有silencedetect的FFMPEG来消除音频静音 [英] using FFMPEG with silencedetect to remove audio silence
问题描述
我正在尝试在最新的 ffmpeg 版本中使用以下命令来消除我的 .mp3 文件中的静音:
I am trying to use the following command with the latest ffmpeg build to remove silence from my .mp3 files:
ffmpeg -i SILENCE.mp3 -af silencedetect=n=-50dB:d=1 -y -ab 192k SILENCE_OUT.mp3
但是,会产生以下输出:
However, the following output is produced:
ffmpeg version N-66154-g1654ca7 Copyright (c) 2000-2014 the FFmpeg developers
built on Sep 5 2014 22:10:38 with gcc 4.8.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.100 / 56. 4.100
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
Input #0, mp3, from 'SILENCE.mp3':
Metadata:
title : Snowblind (Featuring Tasha Baxter)
artist : Au5
album : Snowblind (Featuring Tasha Baxter)
genre : Electronica
performer : Au5
track : 1/1
date : 2014
album_artist : Au5,Tasha Baxter
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf55.42.100
Duration: 00:05:50.80, start: 0.025057, bitrate: 192 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
Output #0, mp3, to 'SILENCE_OUT.mp3':
Metadata:
TIT2 : Snowblind (Featuring Tasha Baxter)
TPE1 : Au5
TALB : Snowblind (Featuring Tasha Baxter)
TCON : Electronica
TPE3 : Au5
TRCK : 1/1
TDRL : 2014
TPE2 : Au5,Tasha Baxter
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
TSSE : Lavf56.4.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p, 192 kb/s
Metadata:
encoder : Lavc56.1.100 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[silencedetect @ 0000000004398f40] silence_start: -0.00628118
[silencedetect @ 0000000004398f40] silence_end: 3.21413 | silence_duration: 3.22
041
[silencedetect @ 0000000004398f40] silence_start: 343.844
[libmp3lame @ 00000000043b2940] Trying to remove 1152 samples, but the queue is
empty
size= 8223kB time=00:05:50.79 bitrate= 192.0kbits/s
video:0kB audio:8222kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 0.011485%
然而,生成的音频文件仍然具有原始长度,没有消除任何静音.请参阅以下图片:
The generated audio file however still has the original length without any silence removed. See the following images:
感谢任何帮助!
好的,静音检测只是检测静音.不去除它.我会尝试为此发布解决方案.
Alright, silence detect is only DETECTING the silence. Not removing it. I will try to post a solution for this.
推荐答案
使用 silenceremove
过滤器.这只会从音轨中消除静音 - 它不会编辑视频,即,事情将不同步
它的论点有点神秘.
一个例子
ffmpeg -i input.mp3 -af silenceremove=1:0:-50dB output.mp3
这消除了沉默
- 在开头(由第一个参数
1
表示) - 最小长度为零(由第二个参数
0
表示) - 静音被归类为低于 -50 分贝(由
-50dB
表示).
- at the beginning (indicated by the first argument
1
) - with minimum length zero (indicated by the second argument
0
) - silence is classified as anything under -50 decibels (indicated by
-50dB
).
文档:FFMPEG 静音过滤器
此外,任何希望找到对静音进行分类的正确值的人都可能希望首先将其输入音频音量标准化为 0dB
,要在 ffmpeg 中执行此操作,请参阅 这个答案.
Also anyone looking to find the right value to classify silence as may wish to look into normalising their input audio volume to 0dB
first, to do this in ffmpeg see this answer.
编辑
正如@mems 所指出的,检测您的 ffmpeg 版本是否运行了过滤器
As pointed out by @mems, to detect whether your version of ffmpeg has the filter run
ffmpeg -hide_banner -filters |grep 静音删除
如果你有过滤器,它会输出类似
if you have the filter it'll output something like
silenceremove A->A 取消静音
这篇关于使用带有silencedetect的FFMPEG来消除音频静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!