bytearray from a webcam - actionscript-3

i try to get a bytearray from a webcam. i can get the image of the webcam, copy it to bitmapdata and get the bytearray. but is it possible to get the bytearray from the image and sound from the client's webcam ?

audio data to ByteArray:
* Microphone.sampleData Event
* SoundMixer.computeSpectrum() method
i know only the following way to get a ByteArray from Video instance:
* to draw a BitmapData each time the screen is updated and then BitmapData.getPixels(new Rectangle(0, 0, BitmapData.width, BitmapData.height))
it's also possible to join ByteArrays with video and audio data but it depends on how it'll be treated on the server side

if i had the rep, i'd thumbs up www0z0k's reply... should help me with my own app.
Mel, however you're planning on processing the ByteArray on the server (i'd assume something with NetConnection.send()), i'd be sure to ByteArray.inflate()/ByteArray.deflate() your data transfer.

Related

Detach video/audio from NetStream

I wan't to create a Skype-like experience where two persons can communicate by video/audio. Now I want to be able to turn off the video or the audio on the receiving side, meaning I not only want to not display the video or turn down the volume of the audio on the stream, I wan't to make sure the client doesn't stream the data (to save bandwidth). Is this possible?
Let me give an example of what I'm doing now.
Host
var stream:NetStream = new NetStream(connection);
stream.attachCamera(camera);
stream.attachAudio(microphone);
stream.publish('myStream');
Client
var stream:NetStream = new NetStream(connection);
var stream.play('myStream');
On the client I would love if there was a way to tell the stream to detach the video or the audio, like you can attach them on the host side. Something like: stream.detachAudio()
Please let me know if I'm going about this the wrong way or there's a different way to achieve this.
For that, you can use NetStream.receiveVideo and NetStream.receiveAudio like this :
ns.receiveVideo(true); // to receive the video stream
ns.receiveVideo(false); // to stop receiving the video stream
And
ns.receiveAudio(true); // to receive the audio stream
ns.receiveAudio(false); // to stop receiving the audio stream
Of course you can verify that you are not receiving video or audio stream using NetStream.info :
trace('ns.videoBytesPerSecond : ' + ns.info.videoBytesPerSecond);
trace('ns.audioBytesPerSecond : ' + ns.info.audioBytesPerSecond);
Hope that can help.

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 media server (FMS) reattach camera to new stream

I'm using flash media server and trying to record the stream but having a problem as I've outlined below. Thanks for taking the time to read this post.
How do I detach my camera from one stream and attach it to a new stream? What I'm trying to do is record the camera stream for 10 seconds and then play it live on a different stream..I try to netstream.close and then netstream.attachCamera(cam0) but it won't let me attach it to the second new stream. What's wrong?
You dont have to close the stream. You can use the attachCamera method with a null argument.
netstream.attachCamera(null);

create (webcam capture like youtube) in my website

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

How to load a ByteArray FLV in OSMF?

I'm working on a local application ( it's not a website or nothing related ) and I have various FLVs with a very simple encryptation method by now (just like adding 10 at each byte).
I can load/play them using NetStream.appendBytes() after decrypting, but that happens only after I read all video data it's not streamed.
What I really need is to stream those videos from a remote url, and decrypting while receiving data, using a OSMF based player that I already have built.
I'm lost on how OSMF deals with FLV, otherwise, I would try to create a plugin or something like.
I'd be very thankful if someone point me how to deal with that.
But I'd be happy if someone help me to find a way to load a local file using OSMF, passing a ByteArray value, instead of a url (below). Or even giving me directions to create a OSMF plugin to solve my problem.
videoElement.resource = "video_url/video.flv";
This is my current code just to play my decoded FLV byte array
private function playBytes(bytes:ByteArray):void
{
// detecting it's header
if (bytes.readUTFBytes(3) != "FLV")
{
_text.appendText("\nFile \""+ file +"\" is not a FLV")
return void;
}
bytes.position = 0;
netConnection.connect(null);
netStream = new NetStream(netConnection);
netStream.client = { onMetaData:function(obj:Object):void { } }
video.attachNetStream(netStream);
addChild(video);
// put the NetStream class into Data Generation mode
netStream.play(null);
// before appending new bytes, reset the position to the beginning
netStream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
// append the FLV video bytes
netStream.appendBytes(bytes);
}
Interesting post, I'd be interested to see the answer. Looking at something similar myself, though not with a stream, I came across the following.
http://ntt.cc/2008/07/15/bitsreader-read-bits-from-given-bytearray.html
After passing the byte array you can use bits.read(8) of a 10 bit array. Perhaps this would send you down the correct path? Otherwise, I'm thinking you'd need to break it apart and essentially do smaller sections to buffer in order to concatenate all the buffered data...
Just a thought,