Learnosity Logo
Learnosity Banner Image

Extracting from sound from Flash (aka NellyMoser)

A current project that we are working on requires us to be able to record sound via a flash plugin. Initially I thought it would be nice and easy as I've seen demos of both video and audio broadcasting - however, the one big problem is that the current flash client only allows you to record video to a netstream, you can't get any access to it in the flash player.

So you need something like Flash Media Server or Red5 to record it.

However, once you record it to the server it is an flv and the audio codec is stored as a NellyMoser encoded audio portion. This codec is not supported by many applications and after a quick google found the nelly2pcm project on google code.

This will convert a flv sound file to a raw pcm file - which you can then do useful stuff with. So here's how to do it on a Ubuntu machine.

$ tar -xjvf nelly2pcm.tar.bz2
$ cd nelly2pcm
$ make
cc -Wall -c -o nelly2pcm.o nelly2pcm.c
cc -Wall -c -o nelly.o nelly.c
cc -Wall -c -o nelly_tables.o nelly_tables.c
cc -Wall nelly2pcm.o nelly.o nelly_tables.o -lm -o nelly2pcm
You should now have a nelly2pcm executable file in this directory.

You can run it as follows:

$ ./nelly2pcm test.flv > test.raw
mono Nellymoser stream with 16-bit samples at 44kHz

This will create a raw sound file with no headers and output the line above which you'll need for the next part.

To play this file back you can use sox (apt-get install sox)

$ play -r 44100 -c 1 -2 -s test.raw

If you've got all the options correct then this will play the file back. Once you got it correct you can then use sox to create a wav file which is essentially the same except that it has a header which contains all the settings (eg bitrate etc)

$ sox -r 44100 -c 1 -2 -s test.raw test.wav

From a wav you can convert to whatever you like. I'm looking forward to the Flash Player 10 release as this messing will no longer be necessary as it will support encoding with the free Speex codec.

Cheers, Mark

Update:

In the 12 hours since I wrote this post it appears that a DMCA takedown notice has been served on the nelly2pcm site and google have taken it down. I've no idea if it's related to this post or not and no details are available yet on the chillingeffects site but hopefully it will be updated shortly. As I mentioned earlier, I can't wait for flash 10 with the speex codec so we don't have to use Nellymoser, well done Adobe for including it.

Comments
todd sharp's Gravatar FFMPEG can extract MP3 from FLV too (it may use that same utility that you mentioned, not sure)...
# Posted By todd sharp | 7/23/08 2:37 PM
todd sharp's Gravatar Man I guess I should have finished reading the post...you aren't converting to MP3...Doh!
# Posted By todd sharp | 7/23/08 2:40 PM
Mike Duguid's Gravatar I believe that recent releases of ffmpeg have integrated code from nelly2pcm to handle nelly moser.
# Posted By Mike Duguid | 7/23/08 4:08 PM
Rich Rodecker's Gravatar yeah, ffmpeg added support for nellymoser a while ago.
# Posted By Rich Rodecker | 7/23/08 4:20 PM
Mark Lynch's Gravatar Ok - I'll have to check out ffmpeg. Thanks for the tip.

Cheers,
Mark
# Posted By Mark Lynch | 7/24/08 12:02 AM
Mark Lynch's Gravatar I had a look at ffmpeg and it looks like there is only a very old version - pre nellymoser code in the ubuntu repository.

I'll have a look at building from source one of these days.

Cheers,
Mark
# Posted By Mark Lynch | 7/28/08 4:51 AM