"Relaying" video streams

Frank DiPrete fdiprete at comcast.net
Wed Nov 19 08:22:15 EST 2008



Bruce Dawson wrote:
> We've got several web cams that people like to visit
> (www.milessmithfarm.net). However, they're chewing up bandwidth when
> more than one person at a time views them.
> 
> Is anyone aware of a Linux based video re-broadcaster (either software
> or a service)?
> 
> We'd like to upload the video streams to a single server that multiple
> people can connect to and view them. This way, we're only sending one
> video stream up to the server, and the server can rebroadcast it to all
> the connected clients.
> 
> --Bruce

It sounds like the sources are live streams (web cams) and not files 
that can be uploaded to another server for download / viewing.

A multi unicast scenario.

I don't know of an off the shelf open video streaming server that does 
this. I've used Darwin and it works well for streaming stored files on 
request - as long as they are 3gp's or mp4 mov's.

What your server would have to do is:
1) anchor the stream from the webcam
2) send it back out to the viewing client on request

This can start to get tricky if you want people to be able to view it on 
a web page as opposed to using whatever native client they have. Viewing 
it on a web page often is done with a flash app flv movie player (ie 
re-creating youtube - some people may know what I mean by that ;) )

In that case your server would
1) anchor the stream from the webcam
2) transcode the stream to flv
3) use a flash flv player to display the video

But we haven't solved the original problem yet.
Item 1) starts a stream from the webcam so you still pound your uplink 
for each request, but a little program logic may work here.

I've done this sort of thing with php.
These code examples are for an flv source for a youtube re-creatiom 
problem I worked on recently, but you would just change the mime / file 
type.

Your server could:

1) anchor the stream with php curl

function proxy_stream($flv_url) {

  $curl_handle=curl_init();
  curl_setopt($curl_handle, CURLOPT_URL, $flv_url );
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,3);
  curl_exec($curl_handle);
  curl_close($curl_handle);

}

2) take that output to a pipe and shove it down the browser's throat
The important bit is the fpassthru function so as not to mangle the 
stream but just send it out again raw.

function transmit_stream($flv_file) {

  $pos = 0;

  header("Content-Type: video/x-flv");
  header('Content-Length: ' . filesize($flv_file));
  $fh = fopen($flv_file,"rb");
  fseek($fh, $pos);
  fpassthru($fh);
  fclose($fh);

}

The trick now it to connect the ouput pipe from curl into the retransmit 
   function instead of operating on files. If a pipe from a webcam in 
proxy_stream() is already open, then don't call the curl function. In 
theory it would work (haven't tried it yet)

Including a player frame on the server page is another added fun bit.
I used flowplayer and ffmpeg.



> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
> 
> 


More information about the gnhlug-discuss mailing list