Skip to content

Commit

Permalink
Merge pull request #322 from mediamicroservices/audio-fixes
Browse files Browse the repository at this point in the history
Audio fixes
  • Loading branch information
dericed authored May 7, 2024
2 parents 727a468 + 70d91d5 commit 3f7ea2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
6 changes: 6 additions & 0 deletions makederiv
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ while [[ "${@}" != "" ]] ; do
MIDDLEOPTIONS+=(-b:a 320k)
MIDDLEOPTIONS+=(-ar 48000)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "window" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-b:a 320k)
MIDDLEOPTIONS+=(-ar 48000)
_get_audio_mapping "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "resourcespace" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
Expand Down
52 changes: 17 additions & 35 deletions mmfunctions
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,14 @@ _find_input (){
find "${LOOKHERE}" -type f -size +0 "${OBJECTS_FIND_EXCLUSIONS[@]}" | sort | while read file ; do
streamcount=$(ffprobe -loglevel quiet "$file" -show_entries format=nb_streams -of default=nw=1:nk=1)
duration_ts=$(ffprobe -loglevel quiet "$file" -show_entries stream=duration_ts -of default=nw=1:nk=1)
# Cast empty value into 0 integer
if [ -z "$streamcount" ]; then
streamcount=0
fi
if [ -z "$duration_ts" ]; then
duration_ts=0
fi
# Cast empty value into 0 integer
if [ -z "$streamcount" ]; then
streamcount=0
fi
if [ -z "$duration_ts" ]; then
duration_ts=0
fi

if [[ "$streamcount" > 0 && "${duration_ts}" != 1 ]] ; then
_report -d "Input file: $file"
Expand Down Expand Up @@ -1107,18 +1107,11 @@ _find_input (){
_report -dt "Using ${SOURCEFILE} for assessment."
_report -wt "Extracting to ${MOUNTPATH}. Please unmount ${MOUNTPATH} later."
elif [[ "${SOURCEFILE#*.}" = "mkv" || "${SOURCEFILE#*.}" = "mka" ]] ; then
# flag to track if presentation information is found
presentation_found=false
# variable to store the first file with presentation information
FIRST_PRESENTATION_FILE=""

# loops through each file in INPUTFILES
while IFS= read -r INPUTFILE; do
# if the source file is an mkv or mka, then check if it has a Presentation Chapter Edition
if [[ -n $(mkvextract tags "${INPUTFILE}" | xmlstarlet sel -t -m "/Tags/Tag/Simple[String='Presentation']" -v String) ]] ; then
_report -dt "The input file ($(basename "${INPUTFILE}")) contains a Chapter Edition called 'Presentation', will use that for transcoding."
LISTCHAPTERS=$(mkvextract chapters "${INPUTFILE}" | xmlstarlet sel -t -m Chapters/EditionEntry[EditionFlagDefault='1']/ChapterAtom -v ChapterTimeStart -o "-" -v ChapterTimeEnd -o "-" -v ChapterSegmentUID -n -)
SegmentUIDs=$(mkvextract chapters "${INPUTFILE}" | xmlstarlet sel -t -m Chapters/EditionEntry[EditionFlagDefault='1']/ChapterAtom/ChapterSegmentUID -v . -n | sort -u)
if [[ -n $(mkvextract tags "${SOURCEFILE}" | xmlstarlet sel -t -m "/Tags/Tag/Simple[String='Presentation']" -v String) ]] ; then
_report -dt "The input file ($(basename "${SOURCEFILE}")) contains a Chapter Edition called 'Presentation', will use that for transcoding."
LISTCHAPTERS=$(mkvextract chapters "${SOURCEFILE}" | xmlstarlet sel -t -m Chapters/EditionEntry[EditionFlagDefault='1']/ChapterAtom -v ChapterTimeStart -o "-" -v ChapterTimeEnd -o "-" -v ChapterSegmentUID -n -)
SegmentUIDs=$(mkvextract chapters "${SOURCEFILE}" | xmlstarlet sel -t -m Chapters/EditionEntry[EditionFlagDefault='1']/ChapterAtom/ChapterSegmentUID -v . -n | sort -u)
if [[ -n "${LISTCHAPTERS}" ]]; then
_report -d "Found this chapter list:"
_report -d "${LISTCHAPTERS}"
Expand All @@ -1142,15 +1135,12 @@ _find_input (){
done < <(find "${MKVFOLDER}" -type f \( -name "*.mkv" -o -name "*.mka" \))
if [[ -n "${MATCHMKV}" ]]; then
INPUTFILE="$MATCHMKV"
if [[ -z "${FIRST_PRESENTATION_FILE}" ]]; then
FIRST_PRESENTATION_FILE="${INPUTFILE}"
fi
else
echo "Error: did not find a file to match ${CHAPSEGMENTUID}"
exit
fi
else
INPUTFILE="${INPUTFILE}"
INPUTFILE="${SOURCEFILE}"
fi
printf "file " >> "${FFCONCATFILE}"
printf '%q' "${INPUTFILE}" >> "${FFCONCATFILE}"
Expand All @@ -1160,18 +1150,8 @@ _find_input (){
done < <(echo "${LISTCHAPTERS}")
FFMPEGINPUT+=(-i)
FFMPEGINPUT+=("${FFCONCATFILE}")
# set flag to true if presentation information is found
presentation_found=true
# exit loop if presentation information is found
break
fi
fi
done < "$INPUTFILES"
# report and exit if no presentation is found
if ! $presentation_found; then
_report -d "No presentation chapters found in any input file."
exit
fi
fi
}

Expand Down Expand Up @@ -1229,7 +1209,7 @@ _get_channel_layout(){
_get_audio_mapping(){
OPTIND=1
unset PBSMIX
unset ADD_VOLADJ
ADD_VOLADJ="N"
while getopts ":bvlr" OPT ; do
case "${OPT}" in
b) PBSMIX="Y" ;;
Expand Down Expand Up @@ -1263,8 +1243,10 @@ _get_audio_mapping(){
_add_audio_filter "[0:a:0][0:a:1]amerge,pan=stereo|c0=0.5*c0+0.5*c1|c1=0.5*c0+0.5*c1"
elif [[ "${AUDIOMAP}" = "A" ]] ; then
unset AMERGE_LIST
for i in {0.."${AUDIO_TRACK_COUNT}"} ; do
C=0
while "$C" -lte "${AUDIO_TRACK_COUNT}" ; do
AMERGE_LIST+="[0:a:$i]"
((C++))
done
_report -wt "Will mix together ${AUDIO_TRACK_COUNT} tracks into a stereo output."
_add_audio_filter -p "${AMERGE_LIST}amerge=inputs=${AUDIO_TRACK_COUNT}"
Expand Down

0 comments on commit 3f7ea2b

Please sign in to comment.