Jump to content

Recommended Posts

I would like to stream web cam video, but I'm not quite sure how I would do this.

 

All I know is:

The client computer uses flash to grab the video from the cam

 

Here are things I would like to know:

1. How to send that video to a server

2. How to have the server send that video to another connected client

 

I have already gotten a chat server working, so I would assume that it would/could be fairly similar, or am I wrong?

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/
Share on other sites

I have already gotten a chat server working, so I would assume that it would/could be fairly similar, or am I wrong?

 

 

Yes, except for video data instead of plain text.  If you don't want to use flv, you would have to code an applet that can use codecs.

 

Do you plan to code this your self?

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/#findComment-734524
Share on other sites

Well, you'll need 3 basic components, which can be broken down farther.

 

 

1.  A client application.

-This will connect to the server and get streamed video data

-It will then display it.  (FLV would be the file type, most likely.)

 

Now, since it will be streaming live, it won't be as simple as downloading a file.  You will have to open a connection to the server and the server will have to continually push the new video data to the client.  It might become difficult to handle lag, since you will have to code in the ability to tell the server to skip ahead x seconds, incase the client gets behind, since you want a very small buffer on live video.

 

 

2.  A server applicaton.

-This will handle 2 things:

--Getting video data from someone and transmitting it to the correct people (or person).

 

3.  A second client application

-This one would read the webcam and transmit it to the server.  The server could handle the encoding of the content (IE convert it from something to FLV) or the client side stuff could attempt to do it.

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/#findComment-734534
Share on other sites

Now, since it will be streaming live, it won't be as simple as downloading a file.  You will have to open a connection to the server and the server will have to continually push the new video data to the client.  It might become difficult to handle lag, since you will have to code in the ability to tell the server to skip ahead x seconds, in case the client gets behind, since you want a very small buffer on live video.

 

This is the part I am not 100% sure of how it works.

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/#findComment-734554
Share on other sites

Do you not get how it would read data from the webcam and send it back?  I have no idea how it would read data from the webcam.  You might not be able to use Flash for that.  As for sending it back, that would be easy.

 

 

And as for the server sending the data to everyone, that would be easy too.

 

 

I'm still wondering what specific part you don't know how to do.  If it's the camera reading part, I have no idea x.x.

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/#findComment-734847
Share on other sites

Simple.  You have to keep track of multiple socket connections.  If you plan on writing the server side part in a language I know, I could probably give you a small example.  It's really the same thing as a chat server though, just 1 person 'writing' and multiple 'reading'.  (It actually would be called writing and reading, but I meant it there as in like typing and reading the chat room.)

 

 

 

In pseudo code, it would be this:

 

-listen for new connections

-On accept new connection:

--See if it's a web cam person, or someone watching something

--If it's a web cam person, make a 'room' or something like that (or if its 1-1 chat, make some sort of thing to keep track of people)

--If it's a client, put them in the 'room'

 

Then, the rest of the pseudo code would go like this (I would make this a multithreaded application, by the way, especially if you plan on having lots of people using it at the same time.  If you didn't make it multithreaded, all it takes is a couple of laggy connections, and suddenly the program is at a crawl since it would be waiting to read or write to those sockets for a long time.)

 

-For each room:

--Receive data from the cam

---Send data to all people of the "room" except the cam person.

 

 

 

Depending on the language, rooms could be arrays, or vectors.  (In a language where array size is dynamic, like PHP, you could use an array, but in a language where arrays are not dynamic, unless you allocate a pointer and keep realloc'ing, you would find it easier to use a vector [since it is, in a lot of ways, a dynamic array].)

 

 

 

Hopefully you can see where the multithreaded-ness would be useful.  I would highly suggest not writing the server side in PHP.  C++/C/Java would be my choices.  I would personally probably code it in Java, but that's just because I'm more comfortable in Java with threads than in C/C++.  If I weren't going to make it multithreaded, I would probably code it in C++.

Link to comment
https://forums.phpfreaks.com/topic/140363-web-cam-chat/#findComment-734891
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.