First of all, -aq
sets a quality-based variable bit rate - I think you're looking for -ab
(note that I'm an ffmpeg user, so my knowledge of avconv syntax is limited - I've no idea how far it's drifted since the fork).
Regardless, the built-in avconv/ffmpeg AAC encoder is pretty bad.
fdk_aac
The only really good AAC encoder for avconv/ffmpeg is libfdk_aac - but the license for that is incompatible with the GPL, so in order to get access to it you'll have to compile your own (that's an ffmpeg compilation guide, since I don't know of one for avconv - the Ubuntu guide should be fine for Debian, since I don't think there's anything Ubuntu-specific in there).
Once you've got it, follow the AAC encoding guide; I strongly recommend trying out fdk_aac's -vbr
option - a setting of 3 sounds transparent to me on all the files I've tried, if you want the placebo of a higher bit rate, or you're a sound engineer, you can try a setting of 5.
ffmpeg -i input.flac -c:a libfdk_aac -vbr 3 output.m4a
No need for -map_metadata
, since ffmpeg will automatically transfer metadata (and I'm pretty sure that avconv will too).
For a fixed bit rate 320 kbit/s (seriously, this isn't worth it, AAC achieves audio transparency vs. original CD audio at around fixed 128 kbit/s):
ffmpeg -i input.flac -c:a libfdk_aac -b:a 320k
neroAacEnc
Nero's AAC encoder should be considered on-par with fdk_aac and qaac (Quicktime AAC). Different people will give different opinions on which one is better, but you'll only notice any differences at very low bit rates, and everyone agrees that they're all very high-quality.
neroAacEnc
is available from the Nero website. Unzip it and put it somewhere in your $PATH.
Unfortunately neroAacEnc
can only take WAV audio as input; you can get around this by using avconv or ffmpeg as a decoder:
avconv -i input.flac -f wav - | neroAacEnc -if - -ignorelength -q 0.4 output.m4a
Unfortunately, this will strip metadata; to transfer that over, use avprobe/ffprobe (with -show_format
) to extract and neroAacTag to insert. A bash script would probably be in order.
See the HydrogenAudio page on neroAacEnc: from memory, a -q
setting of 0.4 sounded great to me. You can target a bit rate with -br
(again, I think this would be way overkill):
avconv -i input.flac -f wav - | neroAacEnc -if - -ignorelength -br 320000 output.m4a
EDIT: here is a script for converting audio files to m4a with neroAacEnc, then tagging with ffprobe and neroAacTag (requires them all to be in a directory in your $PATH). It can take multiple input files, so if you save it as convert-to-m4a
, you can convert every FLAC file in a directory with
convert-to-m4a *.flac
It isn't limited to just FLAC files; any audio format that your ffmpeg/avconv can decode will work. You may want to change ffprobe and ffmpeg to avprobe and avconv:
#!/usr/bin/env bash
until [[ "$1" = '' ]]; do
ffmpeg -i "$1" -f wav - | neroAacEnc -if - -ignorelength -q 0.4 "${1%.*}.m4a"
tags=()
while read -r; do
tags+=("$REPLY")
done < <(ffprobe -i "$1" -show_format 2>/dev/null | sed -ne 's/date/year/' -e '/TAG:/s/TAG/-meta/p')
neroAacTag "${1%.*}.m4a" "${tags[@]}"
shift
done
exit 0
Install the flac
command from the package of the same name and run
#!/bin/bash
find . -name '*.wav' |
while read file # eg stuff/artist/album/title.wav
do file="$PWD/${file#./}" # make absolute to get more info
album=${file%/*} # stuff/artist/album
artist=${album%/*} # stuff/artist
album=${album##*/} # album
artist=${artist##*/} # artist
title=${file##*/} # title.wav
title=${title%.wav} # title
flac -s --best --delete-input-file \
--tag="TITLE=$title" \
--tag="ALBUM=$album" \
--tag="ARTIST=$artist" \
"$file" # creates .flac removes .wav
done
The title is the basename of the file, minus the .wav suffix,
album is the immediate directory above, and artist the
directory above that. The --delete-input-file
option
removes the .wav. See Parameter Expansion in the bash
man page for ${var%pattern}
which removes the glob pattern (i.e. formed with *
?
and [...]
)
at the end of the variable, or at the start (${var#pattern});
the %% and ## versions remove the longest matches.
Best Answer
The ffmpeg error you're getting makes me think you might just have a corrupted file. You could try
sox audiofile.wv audiofile.flac
. Alternatively, you could use the wavpack tools:Note that wiill not copy over any metadata; you'll need to do that separately.
If even the wavpack tools can't successfully read the file, then your file is probably just corrupt.