Skip to content

Instantly share code, notes, and snippets.

@mrworf
Created October 4, 2015 20:01
Show Gist options
  • Save mrworf/f847dea5fe3a8cda0a35 to your computer and use it in GitHub Desktop.
Save mrworf/f847dea5fe3a8cda0a35 to your computer and use it in GitHub Desktop.
When you need to normalize the audio of a video file
#!/bin/bash
#
# Normalizes the audio in the supplied video file. Will cause some audio
# degradation since there is a recompression step going on here.
#
# You must have a done folder and processed folder in the same path as
# this script.
#
# Script depends on avconv (ffmpeg on ubuntu 14.x) and sox
#
FILE="$1"
OUT="done/$(basename "${FILE}")"
if [ ! -f "${FILE}" ]; then
echo "No such file: " ${FILE}
exit 1
fi
echo "Processing \"$(basename "${FILE}")\"..."
if [ -f "${OUT}" ]; then
echo "Already processed, skipping ${OUT}"
exit 0
fi
rm processed/*
echo Extracting video...
avconv -v error -i "${FILE}" -vcodec copy -an processed/video.mp4
echo Extracting audio...
avconv -v error -i "${FILE}" -vn processed/audio.wav
echo Normalizing audio...
sox --norm processed/audio.wav processed/audio_norm.wav >/dev/null
echo "Muxing..."
avconv -v error -i processed/video.mp4 -i processed/audio_norm.wav -vcodec copy processed/processed.mp4
echo "Moving result into done"
mv processed/processed.mp4 "${OUT}"
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment