Quick convert raw g711 uLaw audio to a .au file

I had reason to playback some raw g.711 audio data. I made the following script to convert the data to a .au file that is playable.

From the AU file spec.. which is way simple by the way:
You just need to add 6 32-bit header flags.

raw2au.py:

import struct

header = [ 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 ]
o=open('out.au','wb')
o.write ( struct.pack ( ">IIIIII", *header ) )

raw = open('in.raw','rb').read()
o.write(raw)
o.close()

You can probably see that this would be extremely simple to use with other audio formats too. Modify as you need.
Header Bytes:

  1. Const AU identifier: 0x2e736e64
  2. Size of Header: 24.
  3. Size of File: use 0xffffffff for unknown, or you could replace with the actual size.
  4. Audio format. 1 is uLaw. From the spec choose whatever you need if it isn’t uLaw.
  5. Sample rate. uLaw is always 8000.
  6. Channels. 1 channel in this case.

Handbrake can convert MTS files for Mac

So a while back we purchased a JVC Everio HD camcorder. I’ll skip the commentary on whether or not that is a good idea. For me, the relevant issue is: how am I supposed to copy the MTS (AVCHD H.264) encoded files to my mac and get them in a format that I can import into iMovie and edit.

Here are a few things I discovered on my journey the last few months:

  1. VLC can play MTS files. I wasn’t able to get the stream converter to export them properly to mov files though. Perhaps there is some setting I missed somewhere, but the formats I tried either had messed up audio or Quicktime couldn’t open them.
  2. ffmpeg is probably a good option. I couldn’t get it to work though. I had the same problems with it that I had with VLC. I couldn’t seem to pick correct encodings to get the audio/video to stay in sync.
  3. iMovie can import video directly from the camera. If you plug the camera in and import the movies directly into iMovie, that works but you end up with mov files that are larger on your hard drive. Also, if you copy the camera drive in it’s entirety to a dmg image, and then mount the dmg file, iMovie can pretend like that is a camera too, and still import the files. I didn’t want this though since I didn’t want to make dmg files every time I want to import and I didn’t want to store mov files.
  4. Handbrake does the job nicely. You can queue up a bunch of files and choose a format to convert them too. I found converting to the preset Apple TV settings works pretty well for importing into iMovie.

Hope this helps someone. Skip all those ffmpeg front-end rip off programs that want to charge you money. They are GPL violating programs whose owners are attempting to make a quick buck off something you can (and should be able to) do for free.