Skip to content

Commit

Permalink
Merge pull request #7 from amiaopensource/so-many-updates-part-2
Browse files Browse the repository at this point in the history
[WIP] So many updates part 2
  • Loading branch information
dericed authored Nov 19, 2022
2 parents 047e831 + 4e15bbc commit 1d7a5b3
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions astataudit
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Provide visual and information reporting on audio files.
Usage:
${THIS_NAME} [options] file1.wav [file2.wav ...]
or
${THIS_NAME} [options] list_of_wave_filepaths_to_process.txt
or
${THIS_NAME} [options] directory/
The input can be a list of files or a directory of audio files. If the input is
a directory, then ${THIS_NAME} will review all audio files immediately within
that directory.
The input can be a list of files, a text document that contains a list of files
or a directory of audio files. If the input is a directory, then ${THIS_NAME}
will review all audio files immediately within that directory.
Options:
By analyzing audio files, ${THIS_NAME} will provide the following outputs.
Expand Down Expand Up @@ -177,7 +179,7 @@ _find_a_font(){
_finish_xml(){
INVENTORY_XML="${1}"
_report -d "Finalizing xml output at ${INVENTORY_XML}"
xmlstarlet select \
"${XMLSTARLET_PATH}" select \
-N "rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#" \
-N "asa=https://github.com/amiaopensource/astatsaudit" \
-N "ffprobe=http://www.ffmpeg.org/schema/ffprobe" \
Expand All @@ -197,15 +199,15 @@ _finish_xml(){
--elem "astats:report" --copy-of "document(@astats)/astats/text()" -b \
--elem "bwfme:fullReport" \
--copy-of "document(@bwf)/*" \
"${INVENTORY_XML}" | xmlstarlet fo
"${INVENTORY_XML}" | "${XMLSTARLET_PATH}" fo
}

_flat_ffprobe_parse(){
FFPROBE_DOC="${1}"
KEY="${2}"
VALUE="$(grep "^${KEY}=" "${FFPROBE_DOC}" | cut -d "=" -f2- | sed -e 's/^"//' -e 's/"$//')"
VALUE_LINE_COUNT="$(echo -n "${VALUE}" | grep -c '^')"
if [[ "${VALUE_LINE_COUNT}" > 1 ]] ; then
if [[ "${VALUE_LINE_COUNT}" -gt 1 ]] ; then
_report -w "The parsed value for '${KEY}' is in ${VALUE_LINE_COUNT} lines, which may be unintended"
fi
echo -n "${VALUE}"
Expand All @@ -227,7 +229,7 @@ _astats_parse(){
VALUE="$(grep "${FILTER_PREFIX}" "${ASTATS_DOC}" | sed -n "s/Overall$/Channel: X/g;/Channel: ${SECTION}/,/Channel/p" | grep "] ${KEY}:" | cut -d : -f2- | sed 's/ //g')"
fi
VALUE_LINE_COUNT="$(echo -n "${VALUE}" | grep -c '^')"
if [[ "${VALUE_LINE_COUNT}" > 1 ]] ; then
if [[ "${VALUE_LINE_COUNT}" -gt 1 ]] ; then
_report -w "The parsed value for '${KEY}' is in ${VALUE_LINE_COUNT} lines, which may be unintended"
fi
echo -n "${VALUE}"
Expand Down Expand Up @@ -356,7 +358,6 @@ _get_csv_row(){
_add_column -f ffprobe streams stream.0.codec_name
_add_column -f astats 1 "Bit depth"
_add_column -f astats 2 "Bit depth"
_add_column -f astats Overall "Bit depth"
_add_column -f astats 1 "Crest factor"
_add_column -f astats 2 "Crest factor"
_add_column -P astats 1 "DC offset"
Expand Down Expand Up @@ -427,6 +428,7 @@ _get_csv_row(){
_add_column bwfmetaedit Tech SampleRate
_add_column bwfmetaedit Tech BitRate
_add_column bwfmetaedit Tech BitPerSample
_add_column astats Overall "Bit depth"
_add_column bwfmetaedit Tech Duration
_add_column bwfmetaedit Tech UnsupportedChunks
_add_column bwfmetaedit Tech bext
Expand Down Expand Up @@ -487,8 +489,8 @@ _make_astats_csv(){
while getopts "o:" opt ; do
case "${opt}" in
o) OUTPUT_DIR="${OPTARG}" ;;
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
Expand Down Expand Up @@ -537,7 +539,6 @@ _make_graph(){
DRAWGRAPH_SETTINGS="bg=Black"
BORDER_COLOR="LightGrey"
HORIZONTAL_MARKINGS_240="drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:height=ih/16,drawgrid=thickness=1:color=${BORDER_COLOR}@0.5:height=ih/4,drawgrid=thickness=1:color=${BORDER_COLOR}@0.8:height=ih/2"
HORIZONTAL_MARKINGS_120="drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:height=ih/8,drawgrid=thickness=1:color=${BORDER_COLOR}@0.5:height=ih/4,drawgrid=thickness=1:color=${BORDER_COLOR}@0.8:height=ih/2"
GRAPH_W=6000
AUDIO_FRAME_SIZE="$(echo "((${DURATION}*${AUDIO_SAMPLE_RATE})/${GRAPH_W})+1" | bc)"
# adding 0.5 in the above equation to ensure that the result is rounded to the nearest integer, rather than simply rounded down
Expand Down Expand Up @@ -600,10 +601,10 @@ _make_graph(){
min=-0.01:max=0.01:
slide=picture:
s=${GRAPH_W}x${GRAPH_H},${HORIZONTAL_MARKINGS_240}[dcoff1];
[l]${AUDIOFORMAT},aphasemeter=video=0,
[l]${AUDIOFORMAT},asubcut=order=6:cutoff=25,aphasemeter=video=0,
adrawgraph=${DRAWGRAPH_SETTINGS}:
m1=lavfi.aphasemeter.phase:fg1=if(gte(VAL\,0.9)\,0xFF00FF00\,if(gte(VAL\,0)\,0xFF00FFFF\,if(gte(VAL\,-0.5)\,0xFF0096FF\,0xFF0000FF))):
max=1:min=-1:
max=1.01:min=-1:
slide=picture:
s=${GRAPH_W}x${GRAPH_H},${HORIZONTAL_MARKINGS_240}[phase1];
[Header]
Expand Down Expand Up @@ -638,8 +639,8 @@ _process_file(){
while getopts "o:" opt ; do
case "${opt}" in
o) OUTPUT_DIR="${OPTARG}" ;;
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
Expand Down Expand Up @@ -688,6 +689,7 @@ _process_file(){
}

_check_dependencies bwfmetaedit ffmpeg ffprobe bc xmlstarlet
XMLSTARLET_PATH="$(which xmlstarlet)"
_find_a_font

FILE_NUMBER="0"
Expand All @@ -697,7 +699,9 @@ CSV_ROW=""
INPUT="$1"
FFPROBE_SETTINGS=(-of xml=x=1:q=1 -noprivate -show_format -show_streams -show_chapters)
NOW="$(_get_iso8601_c)"
if [[ -f "${INPUT}" ]] ; then
INPUT_EXT="${INPUT##*.}"

if [[ -f "${INPUT}" && "${INPUT_EXT}" != "txt" ]] ; then
_report -d "${THIS_NAME} will process this list of files: ${@}"
OUTPUT_CSV="astatsaudit_${NOW}.csv"
while [[ "${@}" != "" ]] ; do
Expand All @@ -722,7 +726,7 @@ if [[ -f "${INPUT}" ]] ; then
fi
shift
done
elif [[ -d "${INPUT}" ]] ; then
elif [[ -d "${INPUT}" || ( -f "${INPUT}" && "${INPUT_EXT}" == "txt" ) ]] ; then
if [[ -n "${SET_OUTPUT_DIR}" ]] ; then
OUTPUT_DIR="${SET_OUTPUT_DIR}"
else
Expand All @@ -739,15 +743,27 @@ elif [[ -d "${INPUT}" ]] ; then
OUTPUT_XML="${OUTPUT_DIR}/astatsaudit_${NOW}.xml"
OUTPUT_CSV="${OUTPUT_DIR}/astatsaudit_${NOW}.csv"
echo "<files>" > "${FILES_XML_TMP}"
while read FILE ; do
IS_AUDIO="$(ffprobe "${FFMPEG_VERBOSE[@]}" -v 0 "${FILE}" -show_entries stream=codec_type -select_streams a:0 -of default=nk=1:nw=1)"
if [[ "${IS_AUDIO}" = "audio" ]] ; then
_process_file -o "${OUTPUT_DIR}" "${FILE}"
((FILE_NUMBER++))
else
_report -d "Skipping: ${FILE} (no audio stream found)"
fi
done < <(find "${INPUT}" -maxdepth 1 -type f ! -name ".*")
if [[ -d "${INPUT}" ]] ; then
while read FILE ; do
IS_AUDIO="$(ffprobe "${FFMPEG_VERBOSE[@]}" -v 0 "${FILE}" -show_entries stream=codec_type -select_streams a:0 -of default=nk=1:nw=1)"
if [[ "${IS_AUDIO}" = "audio" ]] ; then
_process_file -o "${OUTPUT_DIR}" "${FILE}"
((FILE_NUMBER++))
else
_report -d "Skipping: ${FILE} (no audio stream found)"
fi
done < <(find "${INPUT}" -maxdepth 1 -type f ! -name ".*")
else
while read FILE ; do
IS_AUDIO="$(ffprobe "${FFMPEG_VERBOSE[@]}" -v 0 "${FILE}" -show_entries stream=codec_type -select_streams a:0 -of default=nk=1:nw=1)"
if [[ "${IS_AUDIO}" = "audio" ]] ; then
_process_file -o "${OUTPUT_DIR}" "${FILE}"
((FILE_NUMBER++))
else
_report -d "Skipping: ${FILE} (no audio stream found)"
fi
done < "${INPUT}"
fi
echo "</files>" >> "${FILES_XML_TMP}"
if [[ "${XML_OUTPUT}" = "y" ]] ; then
_finish_xml "${FILES_XML_TMP}" > "${OUTPUT_XML}"
Expand Down

0 comments on commit 1d7a5b3

Please sign in to comment.