You are on page 1of 6

Live audio broadcast using Wowza Media Server

Wowza Media Server is a popular, java based streaming server used for streaming live and ondemand audio and video content for consumption on various clients like browser, iPhone, Android, etc. Wowza provides a lot of features out of the box. Its written in java and can be extended by writing components in Java. In order to stream live radio we will use a flex based client that will capture the audio input from you microphone and send the same to Wowza server for broadcasting. This will need knowledge of flex api and actionscript. For listening to the live stream one can use JWPlayer(for flash based browsers) or HTML5 for iPhone/iPAD browsers. Setting up Wowza Server Assuming we have a Wowza Media Server already installed we need to setup an application under Wowza Media Server. Lets call this liveradio. To do this 1. 2. 3. 4. Create a folder named liveradio under Wowza installations application directory. Create a folder named liveradio under Wowza installations conf directory. Create a file names Application.xml by copying an existing file from conf directory. Open the newly created Application.xml and modify the value of /Root/Streams/StreamType node to live. 5. Restart Wowza server Coding the Flex client for broadcasting This will need some knowledge with flex api and ActionScript (AS). You will need to setup an AS project. An IDE like FlashDevelop can be used for the same. Below are the typical steps you need to code to capture audio and send to Wowza. Setting up the Microphone In the AS code one can get hold of the microphone and set it up as follows. myMic = Microphone.getMicrophone(); myMic.setSilenceLevel(0); myMic.rate = 11; myMic.gain = 50; // increase this to boost the microphone audio myMic.codec = SoundCodec.SPEEX; // this is important myMic.encodeQuality = 5; myMic.framesPerPacket = 2; Setting up the Network Connection We need to setup a network connection to the Wowza server to send the captured audio data. nc = new NetConnection(); // create a new network connection nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus); // netStatus method will be Neev Information Technologies Pvt. Ltd. www.neevtech.com sales@neevtech.com

notified on network connection events. nc.connect(rtmp://<SERVER-IP>/liveradio); // adjust the url based on your setup. // this is how netStatus looks like private function netStatus(event:NetStatusEvent):void { switch (event.info.code){ case NetConnection.Connect.Success : ns = new NetStream(nc); // create a new NetStream ns.attachAudio(myMic); // attach the audio to the same ns.bufferTime = 20; ns.publish(audio, live); // audio is the name of the stream break; // handle other events as needed .. } } Build your project, create the swf client which can be embedded on a HTML page to broadcast audio using your microphone. Creating a page for playing to the live broadcast The broadcasted audio can be played by using a flash based player or HTML5 audio tag based on the browser. One can also use a player like JWPlayer that can embed audio/video in flash format with HTML5 fallback. You can also use any other flv player that supports RTMP steaming. <script> jwplayer('player').setup({ width: 300, height: 100, wmode: 'transparent', controlbar: 'bottom', modes: [ { type: "flash", src: "flash/player.swf", config: { streamer: "rtmp:///liveradio", file: "audio", provider: "rtmp" } }, { type: "html5", config: { file: "http://:1935/liveradio/audio_ios/playlist.m3u8", provider: "sound" Neev Information Technologies Pvt. Ltd. www.neevtech.com sales@neevtech.com

} } ] }); </script> In the above code there are two configurations viz for RTMP and HTML5. RTMP is only supported in browsers that support flash. Since both iPhone and iPAD do not support flash we used the HTML5 fallback and the Cuppertino streaming support in Wowza for iPhone and iPAD. Challenges There are some challenges here. The streams published from your flex based client is in RTMP format and can be streamed it to a RTMP/flash based player successfully. But the audio codec used, SPEEX, needs to be converted to a H.264 compatible codec like AAC to be able to play from an iPhone/iPAD. There are two ways to do the same. 1. Use the Wowza Transcoder AddOn: The Wowza Transcoder AddOn can trancode any configured incoming stream from one format to other. Here we encoded our live audio format codec from SPEEX to AAC. Heres how to do this.

Setup Wowza Transcoder AddOn. Note that tha AddOn works on only 64 machines. Create a transcoder template audio_speex.xml in Wowzas transcoder/templates folder with the following content <Root> <Transcode> <Encodes> <Encode> <Enable>true</Enable> <Name>iOS</Name> <StreamName>mp3:${SourceStreamName}_ios</StreamName> <Video> <!-- H.264, PassThru --> <Codec>PassThru</Codec> <!-- default, CUDA, QuickSync --> <Transcoder>default</Transcoder> <FrameSize> <!-- letterbox, fit-width, fit-height, crop, stretch, match-source --> <FitMode>fit-height</FitMode> <Width>320</Width> <Height>240</Height> </FrameSize> <Profile>baseline</Profile> <Bitrate>${SourceVideoBitrate}</Bitrate> <KeyFrameInterval> <FollowSource>true</FollowSource> <Interval>60</Interval> </KeyFrameInterval> www.neevtech.com sales@neevtech.com

Neev Information Technologies Pvt. Ltd.

<Overlays> <Overlay> <Enable>false</Enable> <Index>0</Index> <ImagePath>${com.wowza.wms.context.VHostConfigHome}/content/wowzalogo.png</ ImagePath> <Opacity>100</Opacity> <Location> <X>5</X> <Y>5</Y> <Width>${ImageWidth}</Width> <Height>${ImageHeight}</Height> <!-- horiz: left, right, hcenter - vert: top, bottom, vcenter --> <Align>left,top</Align> </Location> </Overlay> </Overlays> <Parameters> </Parameters> </Video> <Audio> <!-- AAC, PassThru --> <Codec>AAC</Codec> <Bitrate>${SourceAudioBitrate}</Bitrate> </Audio> <Properties> </Properties> </Encode> </Encodes> <Decode> <Video> <Deinterlace>false</Deinterlace> <Overlays> <Overlay> <Enable>false</Enable> <Index>0</Index> <ImagePath>${com.wowza.wms.context.VHostConfigHome}/content/wowzalogo.png</ ImagePath> <Opacity>100</Opacity> <Location> <X>5</X> <Y>5</Y> <Width>${ImageWidth}</Width> <Height>${ImageHeight}</Height> <!-- horiz: left, right, hcenter - vert: top, bottom, vcenter --> <Align>left,top</Align> </Location> www.neevtech.com sales@neevtech.com

Neev Information Technologies Pvt. Ltd.

</Overlay> </Overlays> <Parameters> </Parameters> </Video> <Properties> </Properties> </Decode> <Properties> </Properties> </Transcode> </Root> Edit Application.xml and set /Root/Transcoder/Templates to ${SourceStreamName}_speex.xml, transrate.xml

The Wowza Transcoder AddOn is quite powerful and can transcode the incoming streams to multiple formats and bit rates for consumption on different types of players and devices with varying bandwidths. 2. Use an intermediate tool like FFmpeg: FFmpeg is a set of tools to record, play and convert audio and video from/to various formats. It can be used with Wowza Media Server to encode the live audio stream from our application from SPEEX to AAC codec. Below are the steps to get it working with Wowza.

Install FFmpeg for you platform. This is a challenging task as FFmpeg has a lot of dependencies. If you are lucky it will get installed using yum for CentOS or aptitute get install on Ubuntu. Make sure FFmpeg is configured with enable-librtmp and enable-libfaac. You can check if these are enabled by running ffmpeg command without any arguments. Start broadcasting your audio from the flex client Run the below command to transcode the live stream called audio from Wowza and make it available as another stream called audio_ios for playing on iPhone/iPAD ffmpeg -i rtmp:///liveradio/audio -acodec libfaac -vcodec copy -f flv rtmp:///liveradio/audio_ios

Extending the setup for live video The above setup can be extended easily to stream live video along with audio. This can be done as below.

In your flex client setup the Cameralike done for the Microphone and attach the same to the flash NetStream In you JWPlayer code change the provider for html2 from sound to video

Wowza use cases at Neev

Neev Information Technologies Pvt. Ltd.

www.neevtech.com

sales@neevtech.com

Over last few months we at Neev Technologies have successfully used Wowza Media Server for applications involving on-demand streaming of movies/TV programs, live audio/video streaming. In addition there are other use cases like live re-streaming/recording of IP camera streams, live video/chat where we see Wowza as a great fit. Some applications were deployed on a single node and some used Origin-Edge cluster for high load and scalability. Using the Java API we were also able to customize Wowza to add additional security features like time based expiry of stream URLs. Visit us at Neevtech.com to know more about our offerings.

Neev Information Technologies Pvt. Ltd.

www.neevtech.com

sales@neevtech.com

You might also like