From cf57ab492de2ea228518aed40fce33035ba2ba45 Mon Sep 17 00:00:00 2001 From: Digital Studium Date: Sat, 9 Mar 2024 08:36:34 +0300 Subject: [PATCH] feat(remove\_noise.sh): add script to extract, clean and re-insert audio from .mp4 files with noise reduction and normalization This script does the following: 1. Extracts audio from all .mp4 files using ffmpeg. 2. Takes the first second of the first extracted audio file as a noise sample using SoX. 3. Applies noise reduction and normalization filters to each audio file using SoX. 4. Re-insertes the cleaned audio back into the corresponding videos using ffmpeg. 5. Removes the original audio files and the noise profile file. --- remove_noise.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 remove_noise.sh diff --git a/remove_noise.sh b/remove_noise.sh new file mode 100755 index 0000000..f6b1af6 --- /dev/null +++ b/remove_noise.sh @@ -0,0 +1,20 @@ +# 1. extract audio from all videos (assuming .mp4 videos). +for FILE in *.mp4; do ffmpeg -i $FILE ${FILE%%.mp4}.wav; done + +# 2. use the first second of the first audio file as the noise sample. +sox `ls *.wav | head -1` -n trim 0 1 noiseprof noise.prof + +# Replace with a specific noise sample file if the first second doesn't work for you: +# sox noise.wav -n noiseprof noise.prof + +# 3. clean the audio with noise reduction and normalise filters. +for FILE in *.wav; do sox -S --multi-threaded --buffer 131072 $FILE ${FILE%%.wav}.norm.wav noisered noise.prof 0.21 norm; done + +# 4. re-insert audio into the videos. +# If you need to include an audio offset (+/- n seconds), add parameter "-itsoffset n" after the second -i parameter. +for FILE in *.norm.wav; do ffmpeg -i ${FILE%%.norm.wav}.mp4 -i $FILE -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 ${FILE%%.norm.wav}.sync.mp4; done + +# 5. Remove artefacts +rm -f *.wav noise.prof + +# 6. That's it. You're done!