create (webcam capture like youtube) in my website - actionscript-3

I have a website working the same as youtube. At this moment I am trying to create a video image captured by WEBCAM.
The video image should be saved on my computer (by FLV format) first and then if the user is satisfied, he or she can upload it on the server
I am trying to use Actionscript3 in Adobe flash CS5 and Flash media server4
1- How can I do that?
2- Is the flash media server needed?
Please pay attention that we would like to allow the user to save video on his/her computer and then be able to uploaded to the server.
Many thanks.

Assuming the computer can take the overhead of doing the encoding on the fly (or has enough memory to buffer the data then can run the data through an encoding process) then the library mentioned in the SO answer here should work:
Encode video from any format to .flv format in AS3
I believe the Flash media server would only really be necessary in this case for broadcast.
Pseudocode example
private var cam:Camera;
public function Whatever()
{
//In constructor
addEventListener(Event.ENTER_FRAME, grabFrame);
cam = Camera.getCamera();
if (cam != null)
{
var vid:Video = new Video(cam.width, cam.height);
vid.attachCamera(cam);
addChild(vid);
}
}
private function grabFrame(event:Event):void
{
var bd:BitmapData = new BitmapData(cam.width, cam.height)
bd.draw(vid);
//now the BitmapData has a frame of the video, at this point you also
//would want to capture the audio then use the FLV class in the library
}

You can also check out using Red5 as an alternative open source video stream recorder.
http://distriqt.com/post/493
Cheers

Related

Flash SWF, reading the file contents from inside the browser, possible?

I have an actionscript project which I deploy as both a Air desktop application and in the browser using the Flash plugin.
My desktop deployment reads the SWF file itself, creates a hash of the file and send it to my server. If the hash does not match whats expected the SWF then uploads itself to my server for further examination. This all uses the flash.filesystem libraries.
Can the same be done when deployed as Flash file in the browser. I do not have access to flash.filesystem for browser deployment.
Does a way other than using filesystem exist to read the SWF itself.
According to this article (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html) your entire SWF content is accessible via loaderInfo.bytes:ByteArray so there's no need to load anything. Enjoy.
Fallback to loading:
var aRequest:URLRequest = new URLRequest;
// Property loaderInfo.url contains the full path to the SWF.
aRequest.url = loaderInfo.url;
var aLoader:URLLoader = new URLLoader;
// Set data format to binary instead of default text.
aLoader.dataFormat = URLLoaderDataFormat.BINARY;
aLoader.addEventListener(Event.COMPLETE, onReady);
aLoader.load(aRequest);
function onReady(e:Event):void
{
var anSWF:ByteArray = aLoader.data as ByteArray;
trace(anSWF.length);
}
To get the SWF bytes, use URLStream API to receive bytes into some bytearray variable.
You can then use ByteArray API to read (process) the bytearray.
You can deploy your Flex code to an AIR desktop application, which is translated to a SWF file, which can be used in browsers as an embedded object.
Please read more here.

In flash as3 webcam how to get newly connected webcam name at run-time?

I have a flash as3 based webcam video recorder that publishes the webcam video stream and to do this i am using the following codes :
var camera:Camera = Camera.getCamera(0);
var arr:Array = Camera.names;
if(camera != null)
{
videoWidth = topBorderContainer.width;
videoHeight = topBorderContainer.height;
camera.setMode(videoWidth, videoHeight, 30, false);
camera.setQuality(0, 100);
if (camera)
{
videoDisplay.videoObject.attachCamera(camera);
}
}
But problem is that if i am connecting a new document camera at run time and running my webcam tool then Camera.names returning the previously connected document camera name instead of returning the new document camera name.
And to get new document webcam name i have to restart my application again.
But i have no knowledge how to get newly connected document camera name at run time so if anybody know how to get the newly connected document camera name at run time please help me to solve.
It is very likely that you will not be able to pull the trick:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"Scanning the hardware for cameras takes time. When the runtime finds at least one camera, the hardware is not scanned again for the lifetime of the player instance. However, if the runtime doesn't find any cameras, it will scan each time getCamera is called. This is helpful if the camera is present but is disabled; if your SWF file provides a Try Again button that calls getCamera, Flash Player can find the camera without the user having to restart the SWF file."
It is possible that Flash Player treats Workers (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html) as separate Flash Player instances and thus a new Worker would be able to access the renewed list of Cameras. You might want to try it.

How to record video using the as3 camera class

I'm trying to add video recording into a mobile app I'm building. But am struggling with the recording part. So far I have got the camera class displaying in a video object with the code below.
private function init():void
{
var camera1:Camera = Camera.getCamera();
trace(Camera.names);
if (camera1)
{
var ui1:UIComponent = new UIComponent();
var video:Video = new Video (320, 240);
camera1.setMode(320, 240, 24);
camera1.setQuality(0, 100);
video.attachCamera(camera1);
ui1.addChild(video);
cameraGroup1.addElement(ui1);
}
}
From what I understand you can use the cameraUI class instead to achieve the recording part and add it to the library but it would mean using the default camera application when I would rather use my own. I imagine recording using the camera class would require a tick to grab each frame and then something like the videoFrame event but could really use some code or a point in the right direction.
Thanks in advance.
Best way to record using the Flash or AIR application is Media Server. You can connect your application with Media Server (Flash Media Server / Red5 / any other Media Server which is providing Media Recording and Publishing.) and publish your stream for recording.
Second way, I need to search out the code but logically I can say answer. We need to convert Camera stream buffer in to the binary data and we need to save binary data as video file o File system.
For that you can write down some code in ActionScript and need to write down some code in the Native Application as Native Extension.

Flash AS3 and webcam: problems with AIR

I'm having some problems getting the Flash AS3 Camera to work correctly. If you could help, much appreciated. I looked at olThe details:
I'm able, when publishing to a SWF, to get the webcam up and running and all works fine, popping up the 'may I access your camera dialog' which returns muted or not.
• First question: is there any way to make it so I can bypass the user permission, that is always grant it? We are running a kiosk app. Will the following method work for an AIR app? https://stackoverflow.com/questions/3266939/flash-grant-access-to-webcam-programmatically-behind-the-scenes
• Second question: as I said, I can get the webcam/Camera hookup to work fine when publishing for SWF in IDE, and in browser. But if I switch the project to publish for AIR and run the air app, or test in the IDE, I don't get the security permissions dialog coming up at all. Nothing. Perhaps the security box is off screen? Is there some way to control the placement? Is there something different about using the webcam from within AIR?
I'm happy to NOT publish to AIR, but to use SWF — simply need to be able to read/write to XML files on local disk and think that AIR only way to do that?
Thanks for any help!
The code:
private function initTracking() : void
{
var camW : int = 840;
var camH : int = 640;
// Create the camera
_cam = Camera.getCamera();
if (_cam == null)
{
trace("Unable to locate available cameras.");
return;
}
else
{
trace("Found camera: " + _cam.name);
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
_cam.setMode(camW, camH, stage.frameRate);
// Create a video
_vid = new Video(camW, camH);
_vid.attachCamera(_cam);
trace("camera ", _cam, " attached to video ", _vid);
// Create the Motion Tracker
_motionTracker = new MotionTracker(_vid);
// We flip the input as we want a mirror image
_motionTracker.flipInput = true;
}
}
private function camStatusHandler(event:StatusEvent):void
{
trace("camStatusHandler::");
if (_cam.muted)
{
trace("Unable to connect to active camera.");
}
else
{
trace("able to connect to active camera.");
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);
}
// Remove the status event listener.
_cam.removeEventListener(StatusEvent.STATUS, camStatusHandler);
}
If you publish as AIR, there is no security dialog (the security box for swfs is there to stop 'hackers' gaining control of a users webcam without their knowledge).
If your code works in a swf, it should also work in an AIR app without needing any changes - assuming AIR is running on the desktop and not a mobile device?
If you are not seeing the webcam output when you publish as an AIR app, post the relevant code.
Edit:
The StatusEvent.STATUS event does not occur with AIR apps - it fires when user closes security dialog - hence camStatusHandler never gets called.
So remove camStatusHandler function completely and also this line:
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
And add important code from camStatusHandler to the end of initTracking:
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);

AS3-ID3 event in a web radio

I'm building an online radio player using the AS3 code below:
private var soundChannel:SoundChannel;
private var stationUrl:String = "h t t p : / /205.188.215.230:8002/";
sound = new Sound();
sound.addEventListener(Event.ID3, onID3Change);
sound.load(new URLRequest(stationUrl));
soundChannel = sound.play();
private function onID3Change(e:Event):void
{
....
}
the sound plays successfully, but the problem is that the ID3 event is never triggered!
Does anyone know how to solve this?
ID3 doesn't exist in internet radio streams like this one. I am assuming you're talking about a SHOUTcast/IceCast stream.
For that, you need to implement the icy metadata protocol. For Flash, this is generally just done externally.
See this reference: http://www.smackfu.com/stuff/programming/shoutcast.html
Basically, you send icy-metadata: 1 in the headers of your GET request. The server then inserts metadata right into the middle of the stream, which you pull out before sending the data on to whatever is playing the stream. I'm not sure if this is even possible in Flash, but it certainly is possible to do this in PHP (or any server-side language really) and have your Flash application make a request to your PHP script to get that metadata.