#!/usr/bin/bash

for file in /media/nas_video/music/*.{mp4,m4a}
do
   if [ -f "$file" ]
   then
      export fdir=$(dirname "$file")
      export fext=${file##*.}
      export fname=$(basename "$file" ".$fext")
      echo "Processing '$fdir/$fname.$fext'..."
      ls -l "$fdir/$fname.$fext"
      ffmpeg -i "$fdir/$fname.$fext" "$fdir/$fname.mp3" && rm -f "$fdir/$fname.$fext" && ls -lh "$fdir/$fname.mp3"
   fi
done