#!/usr/bin/env bash set -euo pipefail # evaluate options through given arguments map= vbr= while [[ $# > 0 ]]; do case $1 in -map) map='-map 0:0'; shift;; -vbr) vbr='libfdk_aac -profile:a aac_he -b:a 64k'; shift;; * ) break ;; # Anything else stops command line processing. esac done # if no variable bitrate, just copy audio if [[ -z $vbr ]]; then map="$map copy" fi # ensure existence of destination folder dir="$(pwd)" dest=${dir%/*}/${dir##*/}_reencode if [[ !(-d $dest) ]]; then mkdir $dest fi for file in ./*.m4a; do echo "ffmpeg -i '$file' -c:a $vbr $map -movflags +faststart '$dest/$file'"; ffmpeg -i "$file" -c:a $vbr $map -movflags +faststart "$dest/$file"; done