audiobook-dl icon indicating copy to clipboard operation
audiobook-dl copied to clipboard

AAC to MP3 conversion for macos

Open lemonhead94 opened this issue 2 months ago • 0 comments

For me your way of combining the aac files did not work on macos arm, so I built this little bash script in order to create a single MP3 file. Maybe it is useful for someone else just leaving this here :)

I also used -af "aresample=44100,lowpass=8000" to fix some of the package losses / audio hickups encountered in the downloaded aac files from scribd/everand

#!/bin/bash

# Define the path
output_name="AUDIOBOOK_NAME"
base_path="/downloads"
aac_path="/downloads/${output_name}"
output_file="/downloads/${output_name}.mp3"

list_file="${base_path}/mylist.txt"
output_aac="${base_path}/output.aac"

touch "${list_file}"

# demux the aac files into a common format
# so that there is no Error during demuxing: Input/output error
mkdir -p "${base_path}/demux"
find "${aac_path}" -name '*.aac' -print0 | xargs -0 -n 1 -P 9 -I {} sh -c '
  f="{}"
  o="/Users/jorit/Desktop/downloads/demux/$(basename "${f}" .aac).mp3"
  faad -o - "${f}" | ffmpeg -i pipe:0 -af 'aresample=44100,lowpass=8000' -c:a libmp3lame "${o}"
'

# Get all .mp3 files, sort them and add to the list file
ls -v "${base_path}"/demux/*.mp3 | sort -V | while IFS= read -r file; do
  printf "file '%s'\n" "${file}"
done > "${list_file}"

echo "Concatenating .aac files into output.mp3..."
# Use ffmpeg to concatenate them
ffmpeg -f concat -safe 0 -i mylist.txt -af "aresample=44100,lowpass=8000" -c:a libmp3lame "${output_name}.mp3"

# Clean up
rm "${list_file}"
rm -rf ./demux

lemonhead94 avatar May 08 '24 20:05 lemonhead94