Wednesday, June 29, 2011

Adding visual audio level monitors

With the ability to overlay images to the video stream tackled the next task was to analyse the audio and overlay VU meters to allow us to see how noisy the little tyke is without having to actually listen to him (it is a him btw, he popped out on the 22nd June).

The camera uses the linux open sound system (OSS), which has been replaced by ALSA in linux 2.5 and above and isn't particulary nice to work with. The camera streaming server (camserv) , for which there is no source code, opens the audio-in device on startup and as it can only be opened once (and without it being available camserv refuses to work) I had to look at other avenues to get the audio.

Fortunately, camserv actually offers the audio out in a mangled stream which can be found at http://[cam-ip]/cgi/audio/audio.cgi - this stream provides chunks of audio data in 16bit PCM stream at what appears to be about 8KHz (although the frequency is only being guessed at). The stream isn't presented in a friendly format (i.e. browsers don't recognise it and simply try and download it as a series of files) but it is quite easy to write a bit of code to connect to the port and analyse the audio.

I put together some code to connect to the stream and display the current, peak and average volume overlayed on the video stream. It uses some of the same code used for the text display on the previous entry and seems to run around 1/4 sec behind the actual audio (this is due to the audio being streamed locally, analysed and then overlayed onto the video).

I have included the source code and a compiled version here, and below is a short video of it being streamed to an iPad:

And here it is on Apple TV2 via XBMC:

To use the code on your camera it does need to authenticate to the local camera web server; it defaults to username:admin pasword:admin as do the cameras out of the box, if you are using your own username and password (and I strongly suggest you do) you will need to specify the base64 encode of the username and password on the command line via -a . There are a number of websites which can do is encode so I haven
't included this in the code; the format needs to be a hash of the username:password (e.g. 'admin:admin' which has a hash of 'YWRtaW46YWRtaW4=')


  1. Hi !
    Thank you for your tricks.

    I have a TV IP312W too; and my camera is very unstable. Sometimes it run perfectly, and suddenly, I get a white screen on my IE or FFox window. Motion Detection stop to run, and automatic FTP upload stop to work.

    The only thing I can do is access the web panel to reboot or configure my camera.

    Did you have this problem too ?

    Thank you.


    PS : I'm French, so sorry for my speaking :)

  2. Aha,

    Firstly check to see you have a relatively modern firmware loaded - and then enable telnet as my previous posts (or you have use the firmware I have made available...)

    The crash sounds like camserv has stopped running which is the daemon responsible for streaming and handling the motion detection call-backs.

    If you want a quick and dirty fix you could wrap a script around it to restart it whenever it crashes.

    Let me know how you get on

  3. MuddyFunkster

    I bought this camera because of your blog and I must say I'm impressed with the work you've done. I'm an IT guy but am a complete novice when it comes to coding. I have yet to update the firmware on the camera but wanted to ask the following question anyway to get your input. I have the camera pulled up on my ipad and my iphone in about 20 different ip camera apps including the trendnet branded app. I cannot get the audio to come through on any app. I checked and the audio is enable but the speaker on the camera is disabled due to the fact that I do not have speakers hooked to the device. Any ideas?

  4. This comment has been removed by the author.

  5. muddyfunkster said...

    It is probably due to the stream either being without audio (the mjpeg streams) or the audio not being recognised by the application.

    I would recommend using the vlc app (or another app which supports RTSP and mpeg4) on the ipad or iphone, to open the stream you need to open the web-browser and entering the RTSP url as below:


    I will be adding another post early next week with a finished firmware and all the associated components to have this running out of the box without the need for setting up the build environment.

    Best of luck - and let me know how you get on

  6. I'm attempting to implement your audio fix now. I'll be looking forward to the release of the firmware.