跳到正文
DEV Community· howard hua·· 2 小時前AI 評分58

如何用 FFmpeg 和 DeepFilterNet3 去除影片背景噪音而不重新編碼畫面,並比較 Studio AI

How to Remove Background Noise from Video Without Re-Encoding the Picture (FFmpeg + DeepFilterNet3 vs Studio AI)

AI 導讀

文章示範以 ffprobe 檢查影片編碼,再用 FFmpeg 擷取音訊並以 DeepFilterNet3 降噪,最後透過 -c:v copy 將處理後音訊合回相容影片,避免重新編碼畫面。

正文

If you record tutorials, developer demos, interviews, or talking-head videos at a desk, you eventually run into the same frustrating problem: the screen capture or camera footage looks sharp, but the microphone picked up a laptop fan, air-conditioner hum, keyboard clicks, or traffic outside.

The instinctive fix is to drop the clip into a full video editor, apply a noise-reduction filter, and export the whole timeline again. That works, but it has two real drawbacks:

  1. You re-encode the video stream, wasting CPU time and introducing another generation of compression loss on text and UI elements.
  2. Classic spectral filters (afftdn, static noise gates) often turn human speech metallic or "watery" as soon as background noise changes over time.

Below is the cleaner workflow I use to isolate speech noise in recorded videos—first with an open-source local pipeline (ffprobe + ffmpeg + DeepFilterNet3), and then when it makes more sense to run a browser-based comparison before committing to a full export.


Step 1: Inspect the Video Before Touching Anything

Before you extract or replace audio, inspect the container with ffprobe. The goal is to check whether the video stream is already browser-friendly H.264 (avc1) so you can stream-copy the picture later instead of re-encoding it.

ffprobe -v error -select_streams v:0 \
  -show_entries stream=codec_name,width,height,r_frame_rate \
  -of default=noprint_wrappers=1 input.mp4

Also inspect the audio stream:

ffprobe -v error -select_streams a:0 \
  -show_entries stream=codec_name,sample_rate,channels,bit_rate \
  -of default=noprint_wrappers=1 input.mp4

If the video codec is h264, you can leave every video frame byte-for-byte identical when you mux the cleaned audio back in.


Step 2: Why Classic FFmpeg Filters Struggle on Dynamic Noise

FFmpeg ships with afftdn (FFT-based noise reduction) and highpass / lowpass filters. For a constant 60 Hz electrical hum or gentle room hiss, a quick pass can help:

ffmpeg -i input.mp4 -vn -af "highpass=f=80,afftdn=nf=-25" cleaned_afftdn.wav

In practice, though, recorded speech rarely has purely stationary noise. Mechanical keyboard clicks, street traffic, distant voices, and chair creaks shift across frequencies every few hundred milliseconds. Pushing afftdn hard enough to silence those transients usually thins out consonants (s, t, f) and leaves a bubbling underwater artifact behind the voice.


Step 3: Extract 48 kHz Audio and Run DeepFilterNet3 Locally

Modern neural speech-enhancement models operate directly on speech patterns rather than subtracting a static noise floor. DeepFilterNet3 is one of the strongest lightweight open-source options: it runs on CPU at 48 kHz and handles laptop fans, HVAC hum, and moderate room noise surprisingly well.

First, extract the audio track as 48 kHz WAV:

ffmpeg -i input.mp4 -vn -ar 48000 -ac 1 -c:a pcm_s16le raw_48k.wav

Then run DeepFilterNet3 with an attenuation cap (capping attenuation around 30 dB prevents unnatural dead-silence pumping between words):

deepFilter --atten-lim-db 30 raw_48k.wav -o ./cleaned/

Two practical tips when testing neural denoisers locally:

  • Listen to the first 30 seconds on headphones at matched loudness. Raw and cleaned clips often differ slightly in perceived volume; louder audio almost always sounds "better" on a quick listen even when consonants were smeared.
  • Check quiet syllables and trailing words, not just the silent pauses. A model that makes pauses completely silent while clipping soft speech endings will sound distracting in a real video.

Step 4: Mux the Cleaned Audio Back Without Re-Encoding Video

Once you are happy with the cleaned WAV file, combine it with the original video stream using -c:v copy so FFmpeg skips video encoding completely:

ffmpeg -i input.mp4 -i ./cleaned/raw_48k.wav \
  -map 0:v:0 -map 1:a:0 \
  -c:v copy -c:a aac -b:a 192k \
  -movflags +faststart \
  output_clean.mp4

Why this matters:

  • Zero visual degradation: Screen recordings, code text, and camera detail stay untouched.
  • Fast turnaround: Remuxing a 20-minute 1080p MP4 takes seconds instead of waiting on an H.264 re-encode.
  • Clean playback: -movflags +faststart puts the moov atom at the beginning of the file for instant web playback.

(If your source clip uses an incompatible video codec for MP4 playback, drop -c:v copy and transcode to H.264 while preserving the original resolution.)


When Lightweight Neural Denoising Is Not Enough

DeepFilterNet3 is fast and effective for steady background noise—fans, air conditioners, light street rumble, and mic hiss. Where lightweight denoisers hit their ceiling is heavy non-stationary interference: loud outdoor wind gusts, crowded cafes, or strong room echo combined with distant microphone placement.

In those harder clips, heavier speech-restoration models do a noticeably better job recovering voice clarity, though they require GPU inference and cost more to run. Before spending time or money processing a 45-minute recording through a heavy model, always run an A/B comparison on the same 30-second segment to verify whether the heavier model actually beats a lightweight pass on your microphone.


Running This Workflow in the Browser (No Python or FFmpeg Setup)

If you do not want to install Rust/Python toolchains or juggle temporary WAV files on a tight deadline, we packaged this exact two-tier workflow into a web tool so you can remove background noise from video online directly from MP4, MOV, or WEBM files (and MP3, WAV, or M4A for audio-only clips).

Here is how the workflow maps to the steps above:

  • Free Basic pass (no account needed): Upload a file up to 100 MB and clean up to 5 minutes with DeepFilterNet3 (30 dB attenuation cap). Compatible H.264 videos copy the picture stream directly into a cleaned MP4; audio exports download as MP3.
  • 30-second synced Studio comparison: Right after Basic finishes, you can compare the exact same first 30 seconds at matched loudness against the heavier Studio speech engine before deciding if you need the upgrade.
  • Longer recordings: Signing up includes 3 free Studio minutes to test full-length exports; beyond that, you can use a $4.99 / 60-minute one-time pack that never expires or monthly/annual plans for files up to 2 GB and 3 hours. Free-tier files are deleted automatically after 24 hours, and paid jobs after 7 days.

Whether you run the local ffmpeg + DeepFilterNet3 commands above or use a browser background noise remover for one-off clips, the two rules that save the most time stay the same: never re-encode a compatible video track just to fix its audio, and always judge noise reduction on headphones at matched volume before exporting the full recording.

來源:DEV Community · dev.to