Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created May 28, 2014 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gazer/25c50e77332a8cfd0ccc to your computer and use it in GitHub Desktop.
Save Gazer/25c50e77332a8cfd0ccc to your computer and use it in GitHub Desktop.
Noise Removal using avconv and sox
#!/bin/sh
# Tested with :
# * avconv version 9.13-6:9.13-0ubuntu0.14.04.1,
# * SoX v14.4.1
#
# Just run clean.sh input_file.mp4 output_file.mp4
INPUT=$1
OUTPUT=$2
LOG="$OUTPUT".log
echo "Extrayendo video ..."
avconv -i "$INPUT" -an -vcodec copy /tmp/tmpvid.mp4 >> "$LOG" 2>&1
echo "Extrayendo audio ..."
avconv -i "$INPUT" -vn -acodec copy /tmp/tmpaud.mp3 >> "$LOG" 2>&1
echo "Preparando Noise Sample ..."
avconv -i "$INPUT" -vn -ss 00:00:00 -t 00:00:01 /tmp/noiseaud.mp3 >> "$LOG" 2>&1
echo "Generando Noise Profile ..."
sox /tmp/noiseaud.mp3 -n noiseprof /tmp/noise.prof >> "$LOG" 2>&1
echo "Eliminando Ruido ..."
sox /tmp/tmpaud.mp3 /tmp/tmpaud-clean.mp3 noisered /tmp/noise.prof 0.21 >> "$LOG" 2>&1
echo "Generando nuevo video ..."
avconv -i /tmp/tmpaud-clean.mp3 -i /tmp/tmpvid.mp4 -acodec copy -vcodec copy "$OUTPUT" >> "$LOG" 2>&1
echo "Limpiando archivos temporales ..."
rm -rf /tmp/*.mp3 /tmp/*.mp4 >> "$LOG" 2>&1
echo "Listo."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment