Concerning .aac, .mp4 and raw sound wave.

Why

At my school a little team is working on a Raspberry Pi for a secret project. You'll only know that they need to play sound with the fewer resources.

As you may know, a Raspberry Pi is tiny little computer :

The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It is a capable little computer which can be used in electronics projects, and for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. We want to see it being used by kids all over the world to learn programming.

They chose to use the aplay utility. It can only read raw bytes describing numbers describing suondwaves. And their sound files were recorded with Apple products, in .aac

What

First of all, .aac is a codec, not a container.

  • mp4, ogg, mkv, webm, avi are media containers
  • vorbis, flac, mpeg, are audio codecs

Example of container containing two streams from here on my blog :

$ avconv -i Despicable\ Me\ 2\ -\ Minion\ Dance\ Y.M.C.A.webm
Input #0, matroska,webm, from 'Despicable Me 2 - Minion Dance Y.M.C.A.webm':
  Duration: 00:01:05.16, start: 0.000000, bitrate: N/A
  Stream #0.0: Video: vp8, yuv420p, 640x360, PAR 1:1 DAR 16:9, 1k fps, 29.97 tbr, 1k tbn, 1k tbc (default)
  Stream #0.1: Audio: vorbis, 44100 Hz, stereo, s16 (default)

So, I had a lot of .aac files, containing only the audio, encoded in .aac, not suitable for playing. I wrapped them in .mp4 containers with avconv because sox can't handle raw encoded data.

for filename in *.aac;
do
  avconv -i ${filename} -c:a copy ${filename/aac/mp4}
  echo ${filename} 
done

Then I used sox to convert every .mp4 file in a raw file containing only the soundwave described with numbers:

for filename in *.mp4;
do
  # 16 bit signed precision
  # 44100 Hz rate
  sox ${filename} --rate 44100 --encoding signed --bits 16 --channels 1 ${filename/mp4/raw};
done;

Now we can use aplay to read the file and make our speakers oscillate :

# Signed 16 bits Little Endian
aplay --format S16_LE --rate 44100

They (the little team) didn't need to install vlc or some big music player. (They had other reasons I can't tell you there)

blogroll

social