Be a Supporter!

Using the webcam api and a server..

  • 440 Views
  • 19 Replies
New Topic Respond to this Topic
Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Using the webcam api and a server.. 2009-04-23 01:48:56 Reply

Hey,
Does anyone know how to use the webcam/mic. api to save a still image from the webcam and then upload it to a server?

webCamVid = Camera.get();
webCam.attachVideo(webCamVid);

The local webcam stuff is fine - i just don't know how to save a still image from the webcam (I want a still image to be saved about every 5 seconds and then uploaded)

The PHP uploader side should be pretty easy - so if anyone can help me out with the actionscript that would be great :)


lawl

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 02:19:33 Reply

Draw webCam to BitmapData, encode the image with a library and upload that. (Not possible with AS2.)


BBS Signature
Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 04:56:24 Reply

really? Not possible at all in as2?!?!
How come even before as3 was out there was the warning

Are you sure you want to allow "domain.com" to access your webcam and microphone? If you do, you may be recorded

lawl

BBS Signature
atomoxic
atomoxic
  • Member since: Feb. 16, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 08:59:48 Reply

As far as I know you can use the bitmap draw in AS2 but I dont know if it will work the the camera. Is the camera being loaded into a movieclip? If so I dont see why it isnt possible to caputre that particular frame by using bitmap draw.


BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 12:05:20 Reply

At 4/23/09 04:56 AM, Captainhams wrote: really? Not possible at all in as2?!?!

Encoding the image is not possible. You'll break the server by sending it raw images every five seconds.


BBS Signature
cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 14:50:49 Reply

Hey I got a working one, but it lags ALOT. In fact I'll try and fix it right now.

I have it making a new rectangle every loop, maybe drawing into a bitmap data will have less consumption.

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 15:23:17 Reply

At 4/23/09 02:50 PM, cool901 wrote: Hey I got a working one, but it lags ALOT. In fact I'll try and fix it right now.

I have it making a new rectangle every loop, maybe drawing into a bitmap data will have less consumption.

I'll rephrase that, I have it creating a bitmapData, but i DON'T want to create a new rectangle from it every loop, is this possible.

Maybe not making new rectangles and redrawing to the same one would be less consuming.

Well, the best I can get it is at about 2 fps with 75x75 images.

I'll try an interval of 5 seconds and see what happens.

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 15:32:44 Reply

Well, every 5 seconds it isn't too bad, it captures it without lag for 200x200 images.

But as far as video goes, 75x75 images at 2fps is best I can get.

One time I was trying 30 fps with 150x150 images, man it was terrible, the images were about 6 minutes behind the actual webcam feed.

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-23 15:43:26 Reply

Oh problem with all of this is you need to follow this tutorial http://giantflyingsaucer.com/blog/?p=224 and download the Base64 Class http://www.google.com/search?hl=en&clien t=firefox-a&rls=org.mozilla%3Aen-US%3Aof ficial&hs=rQk&q=base64&btnG=Search before even being able to use my fla's.

And to understand, the idea is to get the webcam feed, convert it draw an image from it every 5 seconds, write that image to a bytearray, encode it to a string, send it over the xmlSocket server that you make with the tut at http://giantflyingsaucer.com/blog/?p=224 and then decode and draw it on the other side.

Won't provide fla's until you actually get the tutorial and download of Base64 over with.

Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-24 04:04:21 Reply

thanks but I can't install any of that stuff on my server (lame webhost)

Anyone know of a webhost that has this stuff (perhaps even smartfox too)??


lawl

BBS Signature
cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-24 21:44:34 Reply

hmmm... I don't quite follow because this is all stuff that makes a server, it is a javascript server lol.

You make it and run it in netbeans easy as pie.

I dunno why it wouldn't work.

As far I know, all you have to do is make the server, have the ports there on forwarded and then simply connect.

Making the server is as easy as installing netbeans and typing in some java.

Or install netbeans and download the project files.

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-24 21:50:05 Reply

At 4/24/09 04:04 AM, Captainhams wrote: (perhaps even smartfox too)??

Well, I was using that before, but the server I'm running is easier for me to understand since its hand coded and has no Actionscript api.

That makes it seem done, but actually, I say ive gotten pretty dam far for only using a server that only can receive and redirect data.

I made a signup,login,character creation/selection screen, actual area of chat(somewhat), and a way of storing all the user data for a game with pure actionscript baby.

Shows how diverse Ive gotten in flash eh?

All the server is for is to have a way of sending and receiving data to and from clients.

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-24 21:51:41 Reply

Sorry I meant "That makes it seem dumb"

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to Using the webcam api and a server.. 2009-04-24 22:43:04 Reply

Hmm.. I did a similar thing, but minus the webcam :p Basically on my site I have a flash where you can load an image, draw on it, then save that image (it was my basic test of FileReference local saving) - after every few mouse clicks the image in the flash is saved to my server. When the flash is loaded (i.e., when the site is loaded) the image is loaded into the flash.

The fla can be found here though it won't compile unless you have my RGB class D= Basically just look at the bottom of the code to see how it's uploaded to the server. The php is basically just:

$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
$imgf = fopen("imgtemp_home.jpg", "a");
fwrite($imgf, $jpg);

Sup, bitches :)

BBS Signature
Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-25 18:33:57 Reply

At 4/24/09 09:44 PM, cool901 wrote: hmmm... I don't quite follow because this is all stuff that makes a server, it is a javascript server lol.

You make it and run it in netbeans easy as pie.

I dunno why it wouldn't work.

As far I know, all you have to do is make the server, have the ports there on forwarded and then simply connect.

Making the server is as easy as installing netbeans and typing in some java.

Or install netbeans and download the project files.

Well, before I bother installing it, can you tell me what the delay/ping is like?
Is it fast enough to allow realtime games with at least one remote player??

If it's not then I may as well just write my own basic server side in php :-/


lawl

BBS Signature
cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-25 21:26:20 Reply

At 4/25/09 06:33 PM, Captainhams wrote: Well, before I bother installing it, can you tell me what the delay/ping is like?
Is it fast enough to allow realtime games with at least one remote player??

If it's not then I may as well just write my own basic server side in php :-/

Sorry if the reply seems late, well um the lag it has depends on how much data the server is processing and how fast its coming in. In all honesty the data that isn't sent over for the image is pretty big.

But if you only want it coming in at 5 seconds then it shouldn't lag at all, or atleast an unnoticeable amount.

But any faster than 2 fps and the images being bigger than 75x75 and it would give you a small amount of lag. But if the image is any bigger than that when going at 2 fps or higher, the lag will be terrible. So basically the only way to perform it like an actual video is 75x75 images and 2fps.

Just to clarify two things...

1. You aren't talking about image file creation right, you just want it to be viewable right?

2. You shouldn't have anymore than one image being sent though one server, otherwise it might lag twice as bad. But you are free to make multiple servers.

Now if you don't mind I got fix a lag problem that just suddenly started up with my game for no apparent reason.

one moment it works fine, next time I test it about 30 minutes later without changing anything, I HAVE LAG!

I mean, wtf!

cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-04-25 21:28:06 Reply

At 4/25/09 09:26 PM, cool901 wrote: the data that isn't sent over for the image is pretty big.

Sorry, "the data that IS sent over for the image is pretty big."

Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-28 08:02:13 Reply

yes, I do just want a still image - even if it was uploaded just once (not a feed at all, just a still)
Like how does Facebook do it? With their "Take a photo using webcam" - it uses flash and takes a still that gets uploaded to their databases :-/

Also, I didn't mean what the lag was like with image uploading i meant what the lag is like for just text strings being sent - is it fast enough for realtime games?


lawl

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Using the webcam api and a server.. 2009-04-28 08:24:28 Reply

At 4/28/09 08:02 AM, Captainhams wrote: yes, I do just want a still image - even if it was uploaded just once (not a feed at all, just a still)

Maybe if it's below about 300x300, you can convert the bitmap pixel values to a string and send that to PHP which it would then encode. That might be possible (with both the client and server processing at full capacity) within five seconds.

Like how does Facebook do it? With their "Take a photo using webcam" - it uses flash and takes a still that gets uploaded to their databases :-/

AS3

Also, I didn't mean what the lag was like with image uploading i meant what the lag is like for just text strings being sent - is it fast enough for realtime games?

Lag doesn't depend on the server.


BBS Signature
cool901
cool901
  • Member since: Feb. 27, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Using the webcam api and a server.. 2009-05-02 11:41:56 Reply

I'm starting to wonder if there is a way to send over large amounts of pixels colors in an onEnterFrame loop without lag.

Do you think some how getting each pixel getting put in an array would be less laggy, idk.

Nor do I know how without needing to go through an onEnterFrame loop.

I don't wanna do it pixel by pixel placement into the array, I would basically wanna create an array from the pixels, add the array to an object,compress the array , convert object to string, and send the string over.