Share Coding

Tutorials, Problems, Stuffs …

Peer To Peer Live Video Streaming on Actionscript 3.0 With OpenRTMFP/Cumulus Server

To read this post, you need to finish H.264 Live Streaming first and know how to have a live streaming in Actionscript 3.0.
The target is to have a high quality(H.264) and high performance(Peer to peer) Web meeting.
This post only contain actionscript code at publisher and player. You must set up a OpenRTMFP/Cumulus Server.

Follow this post to start a server and use this post to modify your H.264 Live Streaming project.

Web Meeting Publisher & Player



var userid:String;
var groupname:String;

// Receive Flash Parameters from web page
userid = LoaderInfo(this.root.loaderInfo).parameters["userid"];
groupname = LoaderInfo(this.root.loaderInfo).parameters["groupname"];
if (userid==""||userid==null) {
	userid = "456";
if (groupname==""||groupname==null) {
	groupname = "swfever";


nc = new NetConnection(); 
nc.objectEncoding= ObjectEncoding.AMF3;
nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); 
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); 
nc.connect("rtmfp://");// Port must be setted at server


case "NetConnection.Connect.Success" : // In your netStatu listener
	var groupSpec:GroupSpecifier = new GroupSpecifier(groupname); 
	groupSpec.peerToPeerDisabled = false; 
	var groupId:String = groupSpec.groupspecWithAuthorizations(); 
	netGroup = new NetGroup(nc,groupId); 
	netGroup.addEventListener(NetStatusEvent.NET_STATUS, netGroup_onNetStatus); 


// Suggestted to combine NetConnection/NetStream/NetGroup netstate listener
// NetStream Listener will receive all of the event of NetGroupStateEvent, because NetState event is his super class
function netGroup_onNetStatus(e:NetStatusEvent) {	
	if ( == "NetGroup.Neighbor.Connect") {
		var msg = {nearid:nc.nearID};;
	} else if ( == "NetGroup.Neighbor.Disconnect") {
		trace("NetGroup Neighbor Count = " + netGroup.neighborCount);
	} else if ( == "NetGroup.SendTo.Notify") {
		trace("From: ";
	} else if( == "NetGroup.MulticastStream.PublishNotify"){


function publish(groupId:String):void {
	if (nc.connected) {
		nc.client = this;
		in_ns = new NetStream(nc,groupId);
		in_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
		in_ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
		in_ns.inBufferSeek = false;
		if (cam != null) {
			h264Settings = new H264VideoStreamSettings();
			h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3);
			h264Settings.setMode(width, height, camFPS);
			in_ns.videoStreamSettings = h264Settings;

			panel.txtCamStatus.htmlText = "<font color='#33CC00'>ON</font>";
		if (mic != null) {
			panel.txtMicStatus.htmlText = "<font color='#33CC00'>ON</font>";

		soundControler.volume = 0;
		in_ns.soundTransform = soundControler;
		in_ns.publish("testStreamName", "live"); // Stream Name Must be same

Client and Publisher use the same code.
You may add this code to client after NetGroup has been create

netGroup = new NetGroup(nc,groupId);
netGroup.receiveMode = NetGroupReceiveMode.NEAREST;

In a normal Live Streaming, you identify user by stream name which is created by your web page.
1. Now, you need to create a group name by web page.
2. Tell GroupSpecifier the group name.
3. Tell NetStream the groupSpec.groupspecWithAuthorizations().
4. Stream Name must the same in publisher and client.
5. Client has the same stream name but different group could not see others.


3 responses to “Peer To Peer Live Video Streaming on Actionscript 3.0 With OpenRTMFP/Cumulus Server

  1. Graig 2013/07/03 at 5:42 am

    Wenn man mit dem wohnmobil reise unterwegs schon Probleme mit der Khlanlage beim
    Fahrzeug, lsst sich eine Fahrt in die nchstgelegene Werkstatt manchmal
    nicht vermeiden.

  2. ibsenleo 2014/02/16 at 10:41 am

    hi! i used your code and works ok! is publishing, but now i dont know how to recieve the streamings published in that group, and attach them to vid. i mean, how to capture

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: