如何使用 ffmpeg 在特定范围内设置低通滤波器?

如何使用 ffmpeg 在特定范围内设置低通滤波器?

我有一个 .m4a 音乐文件,其中第 57 秒左右有噪音部分,我只想在这个特定范围内设置低通,而不是整个音频文件。

between() 仅使用命令行删除部分视频(可能是 FFMPEG)例如-af "volume=0:enable='between(t,55,58)'"可以工作,但如果我这样做,似乎会出现错误-af "lowpass=3000:enable='between(t,55,58)'"

$ ffmpeg -i test.m4a -af "lowpass=3000:enable='between(t,55,58)'" test_3000.m4a 
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    title           : 10219424412459984
    encoder         : Lavf57.83.100
  Duration: 00:01:10.94, start: 0.000000, bitrate: 64 kb/s
    Stream #0:0(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[Parsed_lowpass_0 @ 0x55eab39197a0] Timeline ('enable' option) not supported with filter 'lowpass'
[AVFilterGraph @ 0x55eab391e5c0] Error initializing filter 'lowpass' with args '3000:enable=between(t,55,58)'
Error reinitializing filters!
Failed to inject frame into filter network: Not yet implemented in FFmpeg, patches welcome
Error while processing the decoded data for stream #0:0
Conversion failed!
$ 

如何在特定范围和多个特定范围设置低通滤波器?

答案1

将 ffmpeg 升级到最新的 git 版本(> 2019 年 5 月 1 日)。已添加时间线支持。

答案2

正如接受的答案所建议的,我需要获取最新的 git,但如何在我的 Ubuntu 18.04.2 LTS 中构建它?

我没有太多经验make,我刚刚构建了 ffmpeg 并想分享我如何做到的。

在 git clone 源代码之后,我做的第一件事就是尝试模仿我当前 Ubuntu ffmpeg 的当前配置选项,我可以通过运行以下命令查看这些选项ffmpeg -v

xb@dnxb:~/Downloads/ffmpeg$ ffmpeg -v
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
...

删除重复的--“options”,然后尝试./configure --"options above"将会得到类似的错误:

ERROR: libwebp >= 0.2.0 not found using pkg-config

我需要做以下操作apt-cache search libwebp来搜索开发包:

xb@dnxb:~/Downloads/ffmpeg$ apt-cache search libwebp
libwebp-dev - Lossy compression of digital photographic images.
libwebp6 - Lossy compression of digital photographic images.
libwebpdemux2 - Lossy compression of digital photographic images.
libwebpmux3 - Lossy compression of digital photographic images.
xb@dnxb:~/Downloads/ffmpeg/testtest/ffmpeg

开发通常以 结束-dev,然后运行sudo apt install libwebp-dev以修复此错误。重复这些步骤(因为有很多选项而花费了大量时间)以修复所有缺少的开发包错误。

但是我仍然得到一些选项未解决的错误,因此需要删除以下选项,这些选项的名称可以从错误消息中得到启发:

--enable-libcdio --enable-libflite --enable-libiec61883 --enable-libopencv --enable-libmysofa

我无法构建 opencv,我放弃并禁用此选项。

但当 时,我仍然会得到v4l2v4l2m2m错误make。我需要执行./configure --help并重复该步骤以检查的输出以确保输出中./configure --"optinos"没有v4l2和出现。v4l2m2m

最终我发现我可以使用(我--disable-v4l2-m2m直接从 获取这个名字--help--disable-encoder=<list of encoder names get from ./configure section 'encoder' output which contains v4l2m2m>,,,,,,并得出这个有效的 ./configure 命令选项:--disable-decoder=<list of decoder names get from ./configure section 'decoder' output which contains v4l2m2m>--disable-indev=<indev section has v4l2>--disable-outdev=<outdev section has v4l2>

./configure --disable-v4l2-m2m --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu \
--incdir=/usr/include/x86_64-linux-gnu  --enable-gpl --disable-stripping --enable-avresample --enable-avisynth \
--enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfontconfig \
--enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg \
--enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine \
--enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis \
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq \
--enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm \
--enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --enable-doc --enable-libopencore_amrnb \
--enable-libopencore_amrwb --enable-libtesseract --enable-debug \
--disable-encoder=h264_v4l2m2m,vp8_v4l2m2m,vc1_v4l2m2m,vp9_v4l2m2m,mpeg4_v4l2m2m,mpeg2_v4l2m2m,mpeg1_v4l2m2m,h264_v4l2m2m,h263_v4l2m2m \
--disable-decoder=h263_v4l2m2m,h264_v4l2m2m,mpeg1_v4l2m2m,mpeg2_v4l2m2m,mpeg4_v4l2m2m,vp9_v4l2m2m,vc1_v4l2m2m,vp8_v4l2m2m \
--disable-indev=v4l2 --disable-outdev=v4l2 --disable-v4l2-m2m

运行make -j7并能够成功构建,

xb@dnxb:~/Downloads/ffmpeg$ ./ffmpeg -i ../test.m4a -af "lowpass=3000:enable='between(t,55,58)'" test_3000.m4a
./ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
xb@dnxb:~/Downloads/ffmpeg$ 

我的 ubuntu 只有 libavdevice.so.57,而 libavdevice.so.58 在我的构建目录中,所以我需要设置LD_LIBRARY_PATH=来消除该错误(目录名称可以由错误启发,例如libavdevice.so.58意味着libavdevice/),我将当前路径设置为P变量:

 P=~/Downloads/ffmpeg/; LD_LIBRARY_PATH="$P"/libavdevice/:\
"$P"/libavfilter/:"$P"/libavformat/:"$P"/libavcodec/:\
"$P"/libavresample:$P/libpostproc/:$P/libswresample/:$P/libswscale/:$P/libavutil/ \
./ffmpeg -i test.m4a -af "lowpass=3000:enable='between(t,55,58)'" test_3000.m4a

它能够成功转换 .m4a。我比较了-filters原始 ffmpeg 和我构建的 ffmpeg,并确认过滤器已更改:

xb@dnxb:~/Downloads/ffmpeg$ ffmpeg -filters |& grep -n pass
39: ... allpass           A->A       Apply a two-pole all-pass filter.
53: ... aselect           A->N       Select audio frames to pass in output.
67: ... bandpass          A->A       Apply a two-pole Butterworth band-pass filter.
90: ... highpass          A->A       Apply a high-pass filter with 3dB point frequency.
94: ... lowpass           A->A       Apply a low-pass filter with 3dB point frequency.
267: ... select            V->N       Select video frames to pass in output.
xb@dnxb:~/Downloads/ffmpeg$ P=~/Downloads/ffmpeg/; LD_LIBRARY_PATH="$P"/libavdevice/:"$P"/libavfilter/:"$P"/libavformat/:"$P"/libavcodec/:"$P"/libavresample:$P/libpostproc/:$P/libswresample/:$P/libswscale/:$P/libavutil/ ./ffmpeg -filters |& grep -n pass
46: TSC allpass           A->A       Apply a two-pole all-pass filter.
62: ... aselect           A->N       Select audio frames to pass in output.
77: TSC bandpass          A->A       Apply a two-pole Butterworth band-pass filter.
101: TSC highpass          A->A       Apply a high-pass filter with 3dB point frequency.
106: TSC lowpass           A->A       Apply a low-pass filter with 3dB point frequency.
130: ... sinc              |->A       Generate a sinc kaiser-windowed low-pass, high-pass, band-pass, or band-reject FIR coefficients.
305: ... select            V->N       Select video frames to pass in output.
xb@dnxb:~/Downloads/ffmpeg$ 

此过滤器的定义:

xb@dnxb:~/Downloads/ffmpeg$ ffmpeg -filters |& grep -n Filters -A 7
15:Filters:
16-  T.. = Timeline support
17-  .S. = Slice threading
18-  ..C = Command support
19-  A = Audio input/output
20-  V = Video input/output
21-  N = Dynamic number and/or type of input/output
22-  | = Source or sink filter
xb@dnxb:~/Downloads/ffmpeg$ 

如您所见,低通和高通显示TSC意味着T时间线支持。

相关内容