How To Do Noise Reduction Using ffmpeg And sox
Need a quick, easy and free way of cleaning up a video’s audio from background noise? Follow the steps below.
First get and install the tools:
Then clean your noise!
- Split the audio and video streams into 2 seperate files:
The VIDEO stream: ffmpeg -i input.mp4 -sameq -an tmpvid.mp4
The AUDIO stream: ffmpeg -i input.mp4 -sameq tmpaud.wav
- Generate a sample of noise from the audio of the file:
ffmpeg -i input.mp4 -vn -ss 00:00:00 -t 00:00:01 noiseaud.wav
-ss: the time offset from beginning. (h:m:s.ms).
-t duration: record or transcode duration seconds of audio/video.
Choose a segment of the audio where there’s no speech, only noise (e.g. speaker was silent for a sec).
- Generate a noise profile in sox:
sox noiseaud.wav -n noiseprof noise.prof
- Clean the noise samples from the audio stream:
sox tmpaud.wav tmpaud-clean.wav noisered noise.prof 0.21
Change 0.21 to adjust the level of sensitivity in the sampling rates (I found 0.2-0.3 often provides best result).
- Merge the audio and video streams back together:
ffmpeg -i tmpaud-clean.wav -i tmpvid.mp4 -sameq vid.mp4
I’m thinking of automating this via a web interface that allows uploading a video file, selection of the noise sample and playing with the noisered levels producing a cleaned version… think it’s a useful tool?