Created
October 4, 2015 20:01
-
-
Save mrworf/f847dea5fe3a8cda0a35 to your computer and use it in GitHub Desktop.
When you need to normalize the audio of a video file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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