header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Amina
Points:270
Posts:12

3/6/2010 9:25:34 AM

Title: Connect en IP camera


Hello everybody
I strongly wish to know how to connect an IP camera using flex builder 3.
Is the function getCamera can do the trick?!
Thank you in advance



1
Wasim
Points: 0
Posts:0
3/6/2010 10:36:38 AM



Amina the best way is to right click on any flash movie and click settings then click camera tab and see if your camera is listed in the list. If camera is available in the list and works in flash player settings then certainly you can access and use it in any flash application . If the camera is not appearing in the list that means the driver of that camera is not accessible to flash player. In that case you can try reinstalling the camera driver.

2
Jupiter
Points: 0
Posts:0
3/6/2010 10:52:43 AM



you can use the following code to get a camera in flex

  private var myCam:Camera;
// I am getting default camera , to get some other camera use index value 
// i.e to get 3rd camera we will use Camera.getCamera("2");  
//
  myCam = Camera.getCamera();
  myVideo = new Video();
  myVideo.width = cam.width;
  myVideo.height = cam.height; 
  myVideo.attachCamera(myCam);
  addChild(myVideo);

3
Amina
Points: 270
Posts:12
3/6/2010 12:10:54 PM



yes thank you guys for replies
I managed to make a video using the webcam connected to my computer but I wonder is it that my system will work if I put up cameras instead of IP webcam knowing that I used the function getCamera for retrieving video streams

4
Inder
Points: 2880
Posts:0
3/6/2010 12:32:37 PM



In flash we can only use the camera which is attached to computer, since IP camera is not attached to computer and its driver is not on computer so it cannot be directly used in flex.

If the camera supports a virtual driver which simulates the IP camera as webcam then only flash can access and use it.

to make your ip camera work in flash you need to search some virtual cam software that can capture source as your IP camera stream and simulates as camera. there are many virtual cams available on internet that take source as video files, images etc , but i couldn't find any cam with source as IP cam stream . I will tell you as soon as i found one such virtual cam software.

5
Amina
Points: 270
Posts:12
3/7/2010 1:50:36 AM



thank you so much for the informations
best regards

6
Beetle
Points: 0
Posts:0
3/7/2010 2:25:07 AM



http://johnbeales.com/tag/ip-camera/

this link might be helpful to you. The person in article is using WOWZA media server to stream IP camera.WOWZA is another server like Flash Media Server.

7
Amina
Points: 270
Posts:12
3/7/2010 2:57:02 AM



by searching the web I found this

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
	<mx:Script>
		<![CDATA[
			import utils.video.mjpeg.MJPEG;
			public function init():void{
		 		Security.loadPolicyFile("xmlsocket:http://10.8.0.54/crossdomain.xml");
		 		trace("xmlsocket:http://10.8.0.54/crossdomain.xml")
		 		var vid:MJPEG = new MJPEG("10.8.0.54", "", 8081);
				video.rawChildren.addChild(vid);
			}
		]]>
	</mx:Script>
	<mx:VBox id="video"></mx:VBox>
</mx:Application>
//////////////////////////
package  utils.video.mjpeg
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.net.Socket;
	import flash.utils.ByteArray;
	
	import mx.utils.Base64Encoder;
	
	/**
	 * This is a class used to view a MJPEG
	 * @author Josh Chernoff | GFX Complex
	 * 
	 */
	public class  MJPEG extends Loader
	{
		private var _user:String; 									//Auth user name
		private var _pass:String;									//Auth user password
		
		private var _host:String; 									//host server of stream
		private var _port:int;  									//port of stream		
		private var _file:String;									//Location of MJPEG
		private var _start:int = 0; 								//marker for start of jpg

		private var webcamSocket:Socket = new Socket();				//socket connection
		private var imageBuffer:ByteArray = new ByteArray();		//image holder
		
		/**
		 * Create's a new instance of the MJPEG class. Note that due a sandbox security problem, unless you can place a crossdomain.xml 
		 * on the host server you will only be able to use this class in your AIR applications.
		 * 
		 * @example import MJPEG;
		 *			var cam:MJPEG = new MJPEG("192.168.0.100", "/img/video.mjpeg", 80);
		 *			addChild(cam);
		 *			
		 * @param	host:String | Host of the server. Do not include protocol 
		 * @param	file:String | Path to the file on the server. Start with a forward slash
		 * @param	port:int    | Port of the host server;
		 * @param	user:String | User name for Auth
		 * @param	pass:String | User password for Auth
		 */
		public function MJPEG (host:String, file:String, port:int = 80, user:String = null, pass:String = null )
		{
			_host = host;
			_file = file;
			_port = port;
			_user = user;
			_pass = pass;
			
			webcamSocket.addEventListener(Event.CONNECT, handleConnect);
			webcamSocket.addEventListener(ProgressEvent.SOCKET_DATA, handleData);
			webcamSocket.connect(host, port);
			
		}
		
		private function handleConnect(e:Event):void 
		{
			// we're connected send a request
			var httpRequest:String = "GET "+_file+" HTTP/1.1\r\n";
			httpRequest+= "Host: localhost:80\r\n";
			/* 
			if(_user != null && _pass != null){
			 				var source:String = String(_user + ":" + _pass);
							var auth:String = Base64.encode(source);
							httpRequest += "Authorization: Basic " + auth.toString()+ "\r\n";	//NOTE THIS MAY NEEED TO BE EDITED TO WORK WITH YOUR CAM
 			}
 			 */
			httpRequest+="Connection: keep-alive\r\n\r\n";
			webcamSocket.writeMultiByte(httpRequest, "us-ascii");
		}

		private function handleData(e:ProgressEvent):void {
			//trace("Got Data!" + e);
			// get the data that we received.

			// append the data to our imageBuffer
			webcamSocket.readBytes(imageBuffer, imageBuffer.length);
			//trace(imageBuffer.length);
			while(findImages()){
			//donothing
			}

			
		}


		private function findImages():Boolean
		{

			var x:int = _start;
			var startMarker:ByteArray = new ByteArray();	
			var end:int = 0;
			var image:ByteArray;

			if (imageBuffer.length > 1) {
				if(_start == 0){
					//Check for start of JPG
					for (x; x < imageBuffer.length - 1; x++) {
						 
						// get the first two bytes.
						imageBuffer.position = x;
						imageBuffer.readBytes(startMarker, 0, 2);
						
						//Check for end of JPG
						if (startMarker[0] == 255 && startMarker[1] == 216) {
							_start = x;
							break;					
						}
					}
				}
				for (x; x < imageBuffer.length - 1; x++) {
					// get the first two bytes.
					imageBuffer.position = x;
					imageBuffer.readBytes(startMarker, 0, 2);
					if (startMarker[0] == 255 && startMarker[1] == 217){
						
						end = x;
										
						image = new ByteArray();
						imageBuffer.position = _start;
						imageBuffer.readBytes(image, 0, end - _start);
										
						displayImage(image);
										
						// truncate the imageBuffer
						var newImageBuffer:ByteArray = new ByteArray();
						
						imageBuffer.position = end;
						imageBuffer.readBytes(newImageBuffer, 0);
						imageBuffer = newImageBuffer;

						_start = 0;
						x = 0;
						return true;
					}
				}
			}

			return false;
		}

		private function displayImage(image:ByteArray):void
		{
			this.loadBytes(image);
		}
		
	}
	
}
He uses a crossdomain I do not know what it is

8
jupiter
Points: 0
Posts:0
3/7/2010 8:14:36 AM



cross domain file is a xml file to provide permissions to access content from domains.

simply paste the below code in a notepad and save as "crossdomain.xml" to provide access to all domians. The policy file needs to be uploaded on the domain from where you are accessing the files. ie you swf is from abc.com domain accessing files from xyz.com then you should upload file to xyz.com

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy 
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>

9
Amina
Points: 270
Posts:12
3/8/2010 2:34:40 AM



Hi
Thank you very much jupiter :D

10
asif
Points: 0
Posts:0
4/2/2010 10:43:20 AM



how to use a ip camera images/video in vb.net?

11
geekorgy
Points: 0
Posts:0
6/7/2010 4:33:36 PM



I have written scripts for OSX which allow IP Camera to FMS, Wowza, Red5 or any other Flash Media compatible server : by presenting the IP Camera to Flash as a standard Webcam.

Works with Skype, MSN or any other webcam apps also.

Please read the full article i have posted here;
http://www.geekorgy.com/index.php/2010/06/ip-camera-to-fms-flash-video-howto-osx/

12
Amina
Points: 270
Posts:12
6/8/2010 2:16:25 AM



waw very very interesting! Thank you for your help geekorgy :)

13
jorge orengo
Points: 0
Posts:0
7/4/2010 9:32:08 AM



I test this, but don´t work with dlink 920 ip camera. the mjpeg cgi webcam server is /VIDEO.CGI? and this showed by mozila browser. I use flex3 sdk 3.5.


14
Amina
Points: 270
Posts:12
7/4/2010 11:47:56 AM



hi
it works not with me yet: S!!

15
John Omesili
Points: 0
Posts:0
2/6/2011 9:40:23 AM



This code works!
However, the picture of each frame does not fully load before the next one shows up, What I am trying to say is, the frame loads half way vertically, it does not show the full image.

Thanks though, let me see what I can do About that

16
Kees van Dieren
Points: 0
Posts:0
9/7/2011 5:02:52 AM



The MJPEG class could be simplified a lot by using an URLStream (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLStream.html).

We use an URLStream, and proxy http motion jpeg requests via a java proxy servlet. With that the crossdomain.xml is just the standard http one, not needing to write code for xml socket crossdomain file.

17
Vijay Joshi
Points: 0
Posts:0
1/12/2012 4:21:03 AM



var vid: utils.video.mjpeg.MJPEG = new utils.video.mjpeg.MJPEG("10.234.11.102", "/img/video.asf",80);
Produce error "type was not find"


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 7+1 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions