Archive for the 'Flash Media Server' Category

Live Video from Linux to Flash Lite 3.0

You can't use Flash Media Encoder 2 in Linux, so you have to make your own publisher with Flash. Idea is to make own Flash application which connects to webcam and send/publish this live video to Flash Media Server 3 and then clients can connect to Flash Media Server 3 and start to view this live broadcast. Here are simple default instructions to send live video from Linux to Flash Lite 3.0 application.

Install Linux and Flash Media Server 3:

  • Install some Linux distribution (I installed Fedora Core 8 )
  • Download and install Flash Media Server 3 (you might have to use -platformWarnOnly)
  • go to your fms directory: cd /opt/adobe/fms
  • start Flash Media Server 3: ./fmsmgr server fms start

You can use command: "ps aux | grep fms" to see list of fms processes running. There should be following processes listed: fmscore, fmsedge, fmsmaster and fmsadmin. If not, there are some problems :-) in your configuration and maybe you want to read this: Flash Media Server does not start after successful installation on RedHat Linux

Creating own publisher with Flash is quite simple. Open NetConnection to Flash Media Server 3. After you get NetConnection.Connect.Success, you can start connection to your webcam and publish stream to Flash Media Server 3.

Publisher:

import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
import flash.media.Video;
import flash.media.Camera;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;

var nc:NetConnection;
var ns:NetStream;
var video:Video;
var camera:Camera;

// create NetConnection-object
nc = new NetConnection();
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

// connect FMS 3 default live application
nc.connect("rtmp://localhost/live");

// error handling
function asyncErrorHandler(event:AsyncErrorEvent):void {
  trace(event.text);
}

// if connected, start publishing
function netStatusHandler(event:NetStatusEvent):void {
  if (event.info.code == "NetConnection.Connect.Success") {
    startPublishing();
  }
}

// publish webcam's live to server
function startPublishing():void {
  ns = new NetStream(nc);
  ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
  camera = Camera.getCamera();
  if (camera != null){
     video = new Video();
     video.attachCamera(camera);
     ns.attachCamera(camera);
     // show video in publisher also
     addChild(video);
     ns.publish("livestream", "live");
  } else {
     trace("Please check your camera and microphone");
  }
}

Publish your live video publisher in Flash and upload it (swf, html, js) to your web server. Open your publisher in Web browser and you should see your live video in publisher. Start Flash Media Server Admin console and you should see one live application running and publishing live video.

fms admin

Next you have to make Flash Lite 3.0 application to connect your FMS 3 server and play your live stream. Create Video-object in screen and type following code in first frame in Flash.

Client:

import flash.net.ObjectEncoding;

var video:Video;
var ns:NetStream;
var nc:NetConnection = new NetConnection();
nc.objectEncoding = ObjectEncoding.AMF0;

nc.onStatus = function(info:Object):Void {
  if (info.code == "NetConnection.Connect.Success") {
    startStreaming();
  }
}

function startStreaming() {
  ns = new NetStream(nc);
  ns.setBufferTime(2);
  video.attachVideo(ns);
  ns.play("livestream",-1,-1,true);
}

status_txt.text = "Status : Connect....";
nc.connect("rtmp://your.server.ip.here:1935/live");

Note!
You might have some issues with Linux firewalls, then you must edit /etc/sysconfig/iptables to allow connect FMS ports. Add following lines to iptables to allow ports: 1111 and 1935 access from remote and restart your iptables with command: /etc/rc.d/init.d/iptables restart

# flash media server 3
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1111 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT

Download sources: all

Play FLV and Live Video with Flash Lite 3.0

I have made a few test with Flash Lite 3.0 and Flash Media Server 3 and I have to say that it is pretty easy to stream FLV Video files and Live Video from local web camera to mobile phone. Here are a quick instructions how to do it in Windows (I will publish Linux version later).

Play FLV-video from Flash Media Server 3:

  • Install Flash Media Server 3 (download developer version)
  • There are a few sample FLV files in applications/vod/media folder, so you can use one of them for testing
  • Create a new Flash Lite 3.0 file in Flash
  • Add a new Video symbol to library
  • Drag this Video symbol to Stage and give instance name to it: video
  • Type following programming to timeline:
// make a new video-object
var video:Video;
// make a new NetConnection-object
var nc:NetConnection = new NetConnection();

// check connection status from server
nc.onStatus = function(info:Object):Void {
  status_txt.text=info.code;
  if (info.code == "NetConnection.Connect.Success") {
    startStreaming();
  }
}

// start streaming video to phone
function startStreaming() {
  ns = new NetStream(nc);
  ns.setBufferTime(5);
  video.attachVideo(ns);
  // play sample.flv from server
  ns.play("sample",0);
}

// show info to user
status_txt.text = "Connecting server...";

// connect FMS 3 video on demand service (default port 1935)
nc.connect("rtmp://your.server.ip.here:1935/vod");
  • Go to Publish Settings...
  • Set Local playback security: Access network only
  • Publish your SWF-file
  • Send your SWF-file to your phone
  • Test and you should see FLV-video playing in your phone

Play live video from Flash Media Server 3:

  • Install Flash Media Server 3 (download developer version)
  • Install Flash Media Encoder 2 (Windows only)
  • Start Flash Media Encoder 2
  • You should see your live camera in Input screen
  • Press Start-button to start sending live video to Flash Media Server 3
  • Create a new Flash Lite 3.0 file in Flash
  • Add Video symbol and programming as you did earlier
  • Modify your programming:
// in startStreaming()-function
// Flash Media Encoder 2 publish stream name is "livestream"
ns.play("livestream",-1,-1,true);

// start connection to Flash Media Server 3
// Flash Media Encoder 2 publishes Flash Media Server's default
// live publishing point, so connect it
nc.connect("rtmp://your.server.ip.here:1935/live");
  • Publish, test and enjoy

Download sources: all



Get Adobe Flash playerPlugin by wpburn.com wordpress themes