Contributed by Khurshidali Shaikh on 28 Nov 2011
Wowza Media Server is a popular, Java-based streaming server used for streaming live and on-demand audio and video content for consumption on various clients like browser, iOS, 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 your 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.
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
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;
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 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" } } ] }); </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. Here’s how to do this.
<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> <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> </Overlay> </Overlays> <Parameters> </Parameters> </Video> <Properties> </Properties> </Decode> <Properties> </Properties> </Transcode> </Root>
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.
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.
Wowza use cases at Neev
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.
Tags: cuppertino, flv, HTML, HTML5, jwplayer, live broadcast, live radio, rtmp, streaming, streaming media, wowza, wowza server
© 2016 Neevtech Blog | Neev Technologies
Leave a Comment