[FFmpeg-user] Removing audio noise

Cecil Westerhof Cecil at decebal.nl
Sun Apr 20 10:06:06 CEST 2014


Op Sunday 20 Apr 2014 03:52 CEST schreef littlebat:

> On Sat, 19 Apr 2014 12:27:21 +0200
> Cecil Westerhof <Cecil at decebal.nl> wrote:
>
>> At the moment I am using:
>> ffmpeg -async 1
>> -f alsa
>> -ac 1
>> -i hw:1,0,0
>> -f x11grab -s 1920x1080
>> -r 25
>> -i :0.0
>> -acodec libmp3lame
>> -ar 22050
>> -ab 64k
>> -qscale:video 4
>> 2014-04-19_12:24.avi
>>
>> This works reasonably good. The only problem is that there is some
>> white noise in the audio. Is there a way to filter this away?
>>
>
> Maybe this article will help: How To Do Noise Reduction Using ffmpeg
> And sox:
> http://www.zoharbabin.com/how-to-do-noise-reduction-using-ffmpeg-and-sox/

Certainly did. Had to remove the sameq of-course. ;-)

I made the following function (fatal and showMessage are functions I
defined):
    function removeWhiteNoise {
      if [[ ${#} -ne 2 ]] ; then
        fatal "${FUNCNAME} <INPUT> <OUTPUT>"
        return
      fi

      local -r REM_WHITE_NOISE_INPUT_FILE="${1}"; shift
      local -r REM_WHITE_NOISE_OUTPUT_FILE="${1}"; shift

      showMessage "${DEBUG}" "Create video only"
      ffmpeg                                    \
          -y                                    \
          -i "${REM_WHITE_NOISE_INPUT_FILE}"    \
          -qscale:video 0 -an                   \
          tmpvid.mp4 2>/dev/null
      showMessage "${DEBUG}" "Create audio only"
      ffmpeg                                    \
          -y                                    \
          -i "${REM_WHITE_NOISE_INPUT_FILE}"    \
          -qscale:audio 0                       \
          tmpaud.wav 2>/dev/null
      showMessage "${DEBUG}" "Create noise file"
      ffmpeg                                    \
          -y                                    \
          -i "${REM_WHITE_NOISE_INPUT_FILE}"    \
          -vn -ss 00:00:00 -t 00:00:01          \
          noiseaud.wav 2>/dev/null
      showMessage "${DEBUG}" "Create noise profile"
      sox noiseaud.wav -n noiseprof noise.prof
      showMessage "${DEBUG}" "Create cleaned audio"
      sox tmpaud.wav tmpaud-clean.wav noisered noise.prof 0.21
      showMessage "${DEBUG}" "Create cleaned file"
      ffmpeg                    \
          -y                                    \
          -i tmpaud-clean.wav   \
          -i tmpvid.mp4         \
          -qscale:video 0       \
          -qscale:audio 0       \
          "${REM_WHITE_NOISE_OUTPUT_FILE}" 2>/dev/null
      showMessage "${DEBUG}" "Remove temp files"
      rm tmpvid.mp4 tmpaud.wav noiseaud.wav noise.prof tmpaud-clean.wav
      showMessage "${DEBUG}" "Ready"
    }

This works reasonably good. It sounds a little bit like you are
talking into a tin, but I am not using equipment that costs thousands
of dollars, so I should accept it I think.

It take a reasonable amount of time. For a seven minute audio I get
the following output:
    09:47:14: Going to remove white-noise
    09:47:14: Create video only
    09:48:34: Create audio only
    09:48:35: Create noise file
    09:48:35: Create noise profile
    09:48:35: Create cleaned audio
    sox WARN noisered: noisered clipped 23 samples; decrease volume?
    sox WARN dither: dither clipped 21 samples; decrease volume?
    09:48:41: Create cleaned file
    09:49:24: Remove temp files
    09:49:24: Ready
    09:49:24: Ready removing white-noise

So it takes about a third of the length of the video. I have to play a
little bit more, becuase of the two warnings I get. But I am already a
far way on the right track.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the ffmpeg-user mailing list