Melvin Roest
Melvin Roest

Reputation: 1492

ffmpeg complex filtering: how to get around

Alright, I have my own compiled ffmpeg with --enable-lv2. This allows for 3rd-party plugins to work. The plugin I use is: https://github.com/lucianodato/speech-denoiser it's a plugin that wraps around this RNN noise reduction library: https://github.com/GregorR/rnnoise-models

The following commands work:

(1) ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio]' -map "[audio]" output.wav

(2) ffmpeg -i input.mov -filter_complex '[0:v]copy[video]' -map "[video]" output.mov

But when I do the combination, that doesn't work.

ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio];[0:v]copy[video]' -map "[audio]" -map "[video]" output.mov

I think the error is essentially this:

Channel layout change is not supported
Error while filtering: Not yet implemented in FFmpeg, patches welcome
Failed to inject frame into filter network: Not yet implemented in FFmpeg, patches welcome
Error while processing the decoded data for stream #0:0

My guess: this 3rd-party filter is not configure to work with any other output stream other than audio.

My question: can I somehow trick this 3rd-party plugin that it is outputting to an audio file, while still outputting everything to a video file?

Note: I know, I can simply split this up in 2 commands and be done with it, so I'm wondering if I can accomplish this via one ffmpeg command. How I would split it up in 2 commands is as follows:

ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav 

&&

ffmpeg -i out_cropped.mov -i out_cropped_denoised.wav -c:v copy -map 0:v:0 -map 1:a:0 out_cropped_denoised.mov

But I want to be able to put it all in one complex filter (ideally) or at least in one ffmpeg command.

Appendix: here is the full interaction

ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio];[0:v]copy[video]' -map "[audio]" -map "[video]" output.mov
ffmpeg version N-95577-g68f623d644 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.8)
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --enable-lv2 --samples=fate-suite/
  libavutil      56. 35.101 / 56. 35.101
  libavcodec     58. 60.100 / 58. 60.100
  libavformat    58. 33.100 / 58. 33.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 65.100 /  7. 65.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf58.29.100
  Duration: 00:16:19.11, start: 0.000000, bitrate: 1341 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1080x960, 1262 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
File 'output.mov' already exists. Overwrite? [y/N] y

#ote: I typed yes and then this came.

Stream mapping:
  Stream #0:0 (h264) -> copy
  Stream #0:1 (aac) -> lv2
  lv2 -> Stream #0:0 (aac)
  copy -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[out_0_0 @ 0x7fa6811066c0] Channel layout change is not supported
Error while filtering: Not yet implemented in FFmpeg, patches welcome
Failed to inject frame into filter network: Not yet implemented in FFmpeg, patches welcome
Error while processing the decoded data for stream #0:0

Upvotes: 2

Views: 3920

Answers (1)

Melvin Roest
Melvin Roest

Reputation: 1492

I forgot to post an answer here, but I recompiled the ffmpeg project.

And then I could use this command ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav

I remember that I wrote a compilation guide to myself as compiling it seemed a scary thing to do. And it was (just a little), but ultimately it was perfectly doable.

Here's the guide.

How to compile ffmpeg, lv2 and speech-denoiser for mac and denoise your audio files (and put it into videos) on a Mac!

Helpful guide for compiling ffmpeg on MacOS:

Install depencencies
brew install automake fdk-aac git lame libass libtool libvorbis libvpx \
opus sdl shtool texi2html theora wget x264 x265 xvid nasm
Install lilv (dependency for lv2)
brew install lilv #because of ERROR: lilv-0 not found using pkg-config when doing ./configure right away
Configure ffmpeg
./configure  --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass \
--enable-libfdk-aac --enable-libfreetype --enable-libmp3lame \
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --enable-lv2 \
--samples=fate-suite/
Make & Install
make
sudo make install
Install speech denoiser dependencies + the project itself
brew update
brew cask uninstall oclint
brew install lv2 meson ninja pkg-config autoconf m4 libtool automake

#Download and install speech denoiser
git clone https://github.com/lucianodato/speech-denoiser.git
cd speech-denoiser
chmod +x install.sh && ./install.sh
Check fo see if install exists
lv2ls #You got this command from installing lilv

Output: https://github.com/lucianodato/speech-denoiser (yep a URL)

Use your command!
#audio to denoised audio
ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav 

#for if you want to put it with a video
&&

ffmpeg -i out_cropped.mov -i out_cropped_denoised.wav -c:v copy -map 0:v:0 -map 1:a:0 out_cropped_denoised.mov

Upvotes: 1

Related Questions