1
0
mirror of https://github.com/2ec0b4/kaamelott-soundboard.git synced 2025-12-09 16:05:35 +00:00

(master) Crée une configuration Docker pour l'harmonisation du volume des fichiers sons

This commit is contained in:
Antoine
2020-06-17 16:14:51 +02:00
parent 97b7b2a0a7
commit 02ed48e584
5 changed files with 25 additions and 63 deletions

View File

@@ -0,0 +1,13 @@
FROM jrottenberg/ffmpeg:4.2-ubuntu
RUN apt-get -yqq update && \
apt-get install -yq --no-install-recommends python3-pip && \
apt-get autoremove -y && \
apt-get clean -y
RUN pip3 install ffmpeg-normalize
COPY normalize.sh /normalize.sh
RUN chmod +x /normalize.sh
ENTRYPOINT ["/normalize.sh"]

View File

@@ -0,0 +1,25 @@
# Noramlizing audio level
> Audio normalization is the application of a constant amount of gain to an audio recording to bring the amplitude to a target level (the norm). Because the same amount of gain is applied across the entire recording, the signal-to-noise ratio and relative dynamics are unchanged. Normalization is one of the functions commonly provided by a digital audio workstation. https://en.wikipedia.org/wiki/Audio_normalization
In other words, normalizing Kaamelott sounds allow each sound to have a ~same perceived audio loudness. So it reduce the volume of very loud sound and increase the volume of less audible ones.
## Prerequisite
- install `ffmpeg` using your preferred package managed (brew or apt-get for eg) or [this link](https://www.ffmpeg.org/download.html)
- install `ffmpeg-normalize` following [this](https://github.com/slhck/ffmpeg-normalize#installation)
With Docker:
```
docker build -t ks-normalize .docker/normalize/
```
## Usage
Normalize a given sound file
```
docker run --rm -v $(pwd):$(pwd) -w $(pwd) ks-normalize sounds/victoriae_mundis.mp3
```
It will copy replace the file with the new normalized sound to `victoriae_mundis.mp3`.

46
.docker/normalize/normalize.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
TEMP_FILE=temp.mp3
PADDED_FILE=paddedNormalized.temp.mp3
# Check than ffmpeg && ffmpeg-normalize is installed
if ! [ -x "$(command -v ffmpeg)" ]; then
echo 'Error: ffmpeg is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v ffmpeg-normalize)" ]; then
echo 'Error: ffmpeg-normalize is not installed.' >&2
exit 1
fi
# Check that input mp3 is present & exist
if [ -n "$1" ]
then
inputFile=$1
else
echo 'Error: missing input file' >&2
exit 1
fi
if [ ! -f ./$inputFile ]; then
echo "File not found!"
fi
cleanup () {
rm -f $TEMP_FILE
rm -f $PADDED_FILE
rm -f final.mp3
}
cleanup
# Normalize the file
# Due to an issue with ffmpeg-normalize, file shorter than 3s cannot be normalized
# The following use a solution from https://github.com/slhck/ffmpeg-normalize/issues/87#issuecomment-488944192
ffmpeg -i $inputFile -af "adelay=10000|10000" $TEMP_FILE
ffmpeg-normalize $TEMP_FILE -o $PADDED_FILE -c:a libmp3lame
ffmpeg -i $PADDED_FILE -ss 00:00:10.000 -acodec copy $inputFile -y
cleanup