-
-
Save drlinux/ba9a08a23ee93cd9674b788fcfc7e94d to your computer and use it in GitHub Desktop.
Apply a loudness correction for a video file with ffmpeg and libebur128, without re-transcoding the video stream
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/sh | |
# This script needs ffmpeg v3.2 (--enable-libebur128) + jq | |
SOURCE=$1; | |
JSON_ANALYST_FILE="$SOURCE.json" | |
DEST_I="-23" | |
DEST_LRA="15" | |
DEST_TRUE_PEAK="-3" | |
RAW_FFMPEG_ANALYST=$(ffmpeg -hide_banner -nostats -i "$SOURCE" -af loudnorm=print_format=json -f null - 2>&1); | |
echo "$RAW_FFMPEG_ANALYST" | tail -12 > $JSON_ANALYST_FILE | |
LOUDNESS_input_i=$(jq -c -r -M .input_i "$JSON_ANALYST_FILE"); | |
LOUDNESS_input_tp=$(jq -c -r -M .input_tp "$JSON_ANALYST_FILE"); | |
LOUDNESS_input_lra=$(jq -c -r -M .input_lra "$JSON_ANALYST_FILE"); | |
LOUDNESS_input_thresh=$(jq -c -r -M .input_thresh "$JSON_ANALYST_FILE"); | |
LOUDNESS_input_offset=$(jq -c -r -M .target_offset "$JSON_ANALYST_FILE"); | |
AF_FILTER="loudnorm=I=$DEST_I:TP=$DEST_TRUE_PEAK:LRA=$DEST_LRA:measured_I=$LOUDNESS_input_i:measured_LRA=$LOUDNESS_input_lra:measured_TP=$LOUDNESS_input_tp:measured_thresh=$LOUDNESS_input_thresh:offset=$LOUDNESS_input_offset:linear=true:print_format=summary"; | |
ffmpeg -y -i "$SOURCE" -codec:v copy -codec:a aac -b:a 320k -af $AF_FILTER -f mov "$SOURCE-CORRECTED.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment