Skip to content

Instantly share code, notes, and snippets.

@tinpark
Created November 19, 2018 18:49
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 tinpark/f8bd4ce4d0fb409b964b9ec2a28a3a9e to your computer and use it in GitHub Desktop.
Save tinpark/f8bd4ce4d0fb409b964b9ec2a28a3a9e to your computer and use it in GitHub Desktop.
Batch inject meta data into BWF files using the command line
#!/bin/sh
# metaInject.sh
#
#
# Created by PARKER Martin on 16/11/2018.
#
# Dependencies
# this script requires a full install of the FFMPEG
# and the CLI for BWFMETAEDIT https://mediaarea.net/BWFMetaEdit, must be the latest version
# input arguments are: the data file you want to use to populate the files with
# example usage bash metaInject.sh metaData.csv, note we don't allow different file types other than .wav files just to be sure that we're making broadcast wave versions only.
# arg 1 must be a .csv file based on the template provided or make your own template omitting fields you don't want to embed. Provide the name and extension.
METADATA=$1
# first setup some variables, we need to know the date, time and year so we can embed this into the script. I'm doing this dymanically so that the file will have the date and time that I ran the script, but you can do by typing in the date and time that you want the wav file to have
DATE=`date +%Y-%m-%d`
TIME=`date +%H:%M:%S`
YEAR=`date +%Y`
# analyse the audio for loudness standards and write a file with what is discovered. Grab that file, extract True peak, integrated loudness and loudness range and embed into the audio file
# here's a complicated loop that passes through all the .wav files your folder, does loudness analysis of the files, writes a text file with the loudness data and then extracts the data from the file and embeds it into your sound files.
for f in *.wav; do
ffmpeg -nostats -i "$f" -filter_complex ebur128=peak=true -f null - 2>"$f.txt";
# pull data from resulting text file and store in variables, probably better ways to do this
TP=`sed '/Integrated loudness:/h;//!H;$!d;x' "$f.txt" | grep -w 'Peak:' | awk '{print $2}'`
LV=`sed '/Integrated loudness:/h;//!H;$!d;x' "$f.txt" | grep -w 'I:' | awk '{print $2}'`
LRA=`sed '/Integrated loudness:/h;//!H;$!d;x' "$f.txt" | grep -w 'LRA:' | awk '{print $2}'`
# inject data into the wav file with BWFMETAEDIT
# first read through your metaData file (argument 1) and parse the columns into commands for BWFMETAEDIT
while IFS=, read col1 col2 col3; do bwfmetaedit --$col1="$col2" "$f"; done < $METADATA
# NEXT take the values from your loudness analysis done above and poke those into the file, along with the date and time created when the script started:
bwfmetaedit --LoudnessValue=$LV --LoudnessRange=$LRA --MaxTruePeakLevel=$TP --OriginationDate=$DATE --OriginationTime=$TIME --ICRD=$DATE "$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment