Hi Khaine!!!

Thanks for the insights.

This is what I got back from GetData.cgi:

HTTP/1.0 200 OK Date: Thu, 01 Jan 1970 03:07:59 GMT Server: WYM/1.0 Connection: close Content-Type: multipart/x-mixed-replace;boundary=WINBONDBOUDARY Last-Modified: Thu, 01 Jan 1970 03:07:59 GMT Pragma: no-cache Cache-Control: no-cache Expires: 01 Jan 1970 00:00:00 GMT 

Something I probably should have mentioned before: here's exactly what GetData.cgi is supposed spit out according to the cam's manual:

http://www.canvision.net/support/pt300-cgi/GetData.htm

Hope any of this helps us further along.

Thanks a million for your help so far!!!!!!!!!

    Now I understand, and it complicates things. But just so I am 100% clear. You need javascript to reference a file on the local server that is actually performing a proxy to a remote server script which contains the streaming data.

    Firstly I was wrong to lead you along the curl route. It does do what I originally said and gets the data, but because of the transmission, there is no EOF. So curl will continue until time out.

    There are 2 things we can try.

    Firstly htaccess, but my memories of doing this are a little shaky. Easiest one to try though.

    You need to set up a file called .htaccess in the website root. (hoping that htaccess files are allowed and not just ignored)

    RewriteEngine on
    RewriteOptions inherit
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} /GetData.cgi.*
    
    # where they all go.
    RewriteRule http://194.x.x.104/GetData.cgi [QSA,L]
    

    This will allow you to access GetData.cgi on the local server and it will be redirected to the remote one. Javascript is calling a local file so shouldn't complain.

    The second option is a script that might get rather complex.

      Been corrected on what is actually required as a redirect. The htaccess file just needs

      Redirect 301 /GetData.cgi http://194.x.x.104/GetData.cgi?12345&status=XX
      
        khaine;10925575 wrote:

        Been corrected on what is actually required as a redirect. The htaccess file just needs

        Redirect 301 /GetData.cgi http://194.x.x.104/GetData.cgi?12345&status=XX
        

        Hey Khaine,

        Wow, this info startles me! I'm not sure if I'm really following what you're saying. I'm getting the part that I need to create a new file on my shared hosting server where I'm running the website (.htaccess) .. Btw, I can't place any files on my cam's build-in web server, it's completely un-updatable (is that even English??), but I'm guessing that won't be necessary.

        So, I have two questions:

        1) what exactly do I place in the htaccess file, is it just the code in your last post? Or do I append this code to the code you pasted in the post before that one?

        2) when I have created this htaccess file, how can I test it works on my web server? And if it does work, how do I get the streaming data from GetData.cgi inside my IMG tag then? Do I still have to use my PHP proxy file - since the GetData.cgi is protected by Basic Authentication.. ?

        Hope to hear from you!
        Can't say how incredible thankful I am your helping me, reallY!!!!!!!!!!!!!!!!!!!! ๐Ÿ™‚

        Roel.

          Hey Khaine,

          I found this on the web, could this work???? (I'm not able to test it myself for at least 8 hours but I will when I get home from work).

          I wrote the following PHP script to pull the MJPEG stream directly from the CB-V10 camera on itโ€™s native 65310 streaming port:

          <?
          // Set time limit to indefinite execution
          set_time_limit(0);
          // create TCP socket
          $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
          // connect to the camera's native stream protocol IP:Port
          socket_connect($sock,"10.0.0.20", 65310);
          // handshake with the camera
          socket_write($sock,"START\r\n");
          // ignore the handshake response
          socket_read($sock, 12000);
          // daemonize this script
          while (true) {
              // simulate 4 escape sequences "\0A" with "\r\n" - or chr(0)
              socket_write($sock,"\r\n\r\n\r\n\r\n");
              // read the image from the stream (max 80k)
              print socket_read($sock, 80000);
              // limit to ~6 frames per second
              usleep(166666);
          }
          ?>

          Source: http://www.overset.com/2007/01/22/live-streaming-of-a-webcam-feed-from-canon-vb-c10c50-from-a-relay-proxy-server/

            I forgot about authentication on the htaccess stuff. So it won't work.

            As for the proxy server script, I can only say give it a go. I don't have access to a camera here and the stream source I am using is just a basic stream. I think it may run into blocking though. As all PHP scripts can. Basically the PHP is waiting to see the end of the input data. Since is is a continual stream it dosn't have one. My guess, and this is only a guess, is that the above script will run until timeout, which it sets to never. So you could end up with a runaway script. When you test it set the

            set_time_limit(0)

            ;

            line to something that will allow a timeout, although I think apache will timeout anyway. Something like 120 would do it. You should get a stream which then stops. If you do then it would be ok to set it to 0.

              7 months later

              I've had the same problem with a 7links px 3309 and found a solution I'd like to share - maybe it helps someone.

              The trick is that the camera sends several images one after another seperating each of them with a boundary. When you use your own PHP Script to forward the images you will have to send this boundary inside the header. So the solution is:

              # To stop apache from killing the script
              set_time_limit(0);
              
              # Sending the correct header
              # The boundary=ipcamera is important.
              # You will have to change "ipcamera" to whatever your camera uses to seperate the 
              # images. Mine uses "--ipcamera" as seperator. You can omit the leading --, but have
              # to use the rest.
              header('Content-Type: multipart/x-mixed-replace;boundary=ipcamera');
              
              # Sending the images
              # You probably have to adapt the url to the video screen of your cam.
              readfile('http://user:pass@ip_adresse_of_camera/video.cgi')
              
              
              
                2 months later

                Hello,
                I have the same need, I want to see the stream of an IP Camera.
                I tried your solution (I change the boundary and the path of the cgi) but it doesn't work!

                Can you help me with a more complete code? ๐Ÿ˜•
                Thanks.

                  Actually - that's all the code I needed - there is nothing more inside my script.

                    8 months later

                    Was a final solution ever found for this? I'm using the following code with some Panasonic IP cams. It seems to work, but I feel it could probably be optimized...

                    <?php
                    
                    set_time_limit(0);
                    
                    $fp = fsockopen([camera.ip.address], 80, $errno, $errstr, 30);
                    
                    if(!$fp) {
                    	echo "/public/images/error.jpg";
                    } else {
                    	fputs($fp, "GET /nphMotionJpeg?Resolution=320x240&Quality=Standard HTTP/1.0\r\n\r\n");
                    	header("Cache-Control: no-cache");
                    	header("Cache-Control: private");
                    	header("Pragma: no-cache");
                    	header('Content-type: image/jpeg');
                    	while($str = trim(fgets($fp, 4096)))
                    	header($str);
                    	fpassthru($fp);
                    	fclose($fp);
                    }
                      2 months later

                      Hello,

                      maybe this is helpful.

                      You nee the cambozola.jar
                      http://www.lavrsen.dk/foswiki/bin/view/Motion/KedMotionTools

                      connect.php

                      <?php
                        set_time_limit(0);
                        $fp = fsockopen ("127.0.0.1",9999 , $errno, $errstr, 30);
                        if (!$fp) {
                          echo "$errstr ($errno)<br>\n";
                        } else {
                          $urlstring = "GET / HTTP/1.0\r\n\r\n";
                          fputs ($fp, $urlstring);
                          while ($str = trim(fgets($fp, 4096)))
                            header($str);
                          fpassthru($fp);
                          fclose($fp);
                        }
                      ?>
                      
                      <applet code="com.charliemouse.cambozola.Viewer"
                      {{{
                              archive="cambozola.jar"
                              width="320" height="240"
                              style="border-width: 1px; border-color: black; border-style: solid;">
                        <param name="url" value="connect.php" />
                        <param name="accessories" value="none" />
                        <param name="retries" value="5" />
                        <param name="delay" value="1000" />
                        <param name="failureimage" value="/images/offline.gif" />
                      </applet>
                      

                      Bye

                        6 months later

                        With the help of everything posted in this forum, I was able to get it working for me... While I'd like to think that this will help everyone who stumbles upon this thread, I doubt it will work for everyone. I'm not sure if all cameras include boundary information in their MJPEG streams (but maybe they do; maybe that's industry standard)... Thanks and good luck to everyone else!

                        Anyways, here is my working code... I connect to the camera's MJPEG image stream (mine was a CGI file, which is password protected by Basic Authentication), and then use that MJPEG image stream to build and output a new image in PHP...

                        The first thing I had to do was to determine what boundary my camera server was using to separate the images in the image feed. To do that, I commented out the header('Content-type: image/jpeg'); line. Refresh, wait about 2 seconds, and then click the STOP button on your browser. You should be able to find in that giberish of RAW JPEG data, the boundary. Mine was --nuuoserverpushjpeg. I think boundaries always start with --. You can leave that line commented out (or just remove it).

                        Take that boundary and replace YOUR_BOUNDARY_HERE in the PHP code below. By adding that, the PHP started outputting an image stream instead of a RAW textual JPEG image. Hurray! ๐Ÿ˜ƒ

                        Then just replace URL_TO_THE_MJPEG_STREAM and USERNAME๐Ÿ˜›ASSWORD with your unique information, and you should be good to go.

                        Side note: My camera server would only output a MJPEG stream (which is what I prefered) to an iPhone browser. If the user-agent was a PC-based browser, it would send the browser to this nice GUI interface (which was not what I wanted for this project). Because of this, I added the $useragent cURL option to my code in order to trick the server into thinking my PHP script was really an iPhone, so that it would server the MJPEG feed. Feel free to remove those two lines if you don't need them, or replace the $useragent variable with the name of your web application.

                        header('Content-type: multipart/x-mixed-replace; boundary=[B]YOUR_BOUNDARY_HERE[/B]');
                        $useragent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
                        
                        while (@ob_end_clean());
                        //	header('Content-type: image/jpeg');
                        // create curl resource
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
                        curl_setopt($ch, CURLOPT_URL, 'http://[B]URL_TO_THE_MJPEG_STREAM[/B]');
                        curl_setopt($ch, CURLOPT_HEADER, 0);
                        //curl_setopt($ch, CURLOPT_POSTFIELDS, '?1234&status=false');  <- disabling this line helped to make it work!! However, GetData.cgi needs these parameters.
                        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                        curl_setopt($ch, CURLOPT_USERPWD, '[B]USERNAME:PASSWORD[/B]');
                        // $output contains the output string
                        $output = curl_exec($ch);
                        echo $output;
                        // close curl resource to free up system resources
                        curl_close($ch);
                        
                          5 months later

                          I was able to get the mjpg feed from a php script similar to the one below. However, when I have a webpage with two iframes, each calling the php script simultaneously (either retrieving from the same or different camera source), only the first script (first iframe) would execute successfully while the rest would not display anything and then after awhile it shows the "internal server error" page.

                          Actually, I get the same result when running the php script twice simultaneously in two different tabs of a same browser. Only one of the tab would get data and the other one would continue loading. It works fine when I use two different browsers.

                          Any idea how to get this to work? Also, it would be great if instead of making a new connection to the source each time the php script is called, it can reuse the same data stream and connection for every request. For example, making it script static in a way.

                          Thanks!

                          AndrewBucklin;10986910 wrote:

                          With the help of everything posted in this forum, I was able to get it working for me... While I'd like to think that this will help everyone who stumbles upon this thread, I doubt it will work for everyone. I'm not sure if all cameras include boundary information in their MJPEG streams (but maybe they do; maybe that's industry standard)... Thanks and good luck to everyone else!

                          Anyways, here is my working code... I connect to the camera's MJPEG image stream (mine was a CGI file, which is password protected by Basic Authentication), and then use that MJPEG image stream to build and output a new image in PHP...

                          The first thing I had to do was to determine what boundary my camera server was using to separate the images in the image feed. To do that, I commented out the header('Content-type: image/jpeg'); line. Refresh, wait about 2 seconds, and then click the STOP button on your browser. You should be able to find in that giberish of RAW JPEG data, the boundary. Mine was --nuuoserverpushjpeg. I think boundaries always start with --. You can leave that line commented out (or just remove it).

                          Take that boundary and replace YOUR_BOUNDARY_HERE in the PHP code below. By adding that, the PHP started outputting an image stream instead of a RAW textual JPEG image. Hurray! ๐Ÿ˜ƒ

                          Then just replace URL_TO_THE_MJPEG_STREAM and USERNAME๐Ÿ˜›ASSWORD with your unique information, and you should be good to go.

                          Side note: My camera server would only output a MJPEG stream (which is what I prefered) to an iPhone browser. If the user-agent was a PC-based browser, it would send the browser to this nice GUI interface (which was not what I wanted for this project). Because of this, I added the $useragent cURL option to my code in order to trick the server into thinking my PHP script was really an iPhone, so that it would server the MJPEG feed. Feel free to remove those two lines if you don't need them, or replace the $useragent variable with the name of your web application.

                          header('Content-type: multipart/x-mixed-replace; boundary=[B]YOUR_BOUNDARY_HERE[/B]');
                          $useragent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
                          
                          while (@ob_end_clean());
                          //	header('Content-type: image/jpeg');
                          // create curl resource
                          $ch = curl_init();
                          curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
                          curl_setopt($ch, CURLOPT_URL, 'http://[B]URL_TO_THE_MJPEG_STREAM[/B]');
                          curl_setopt($ch, CURLOPT_HEADER, 0);
                          //curl_setopt($ch, CURLOPT_POSTFIELDS, '?1234&status=false');  <- disabling this line helped to make it work!! However, GetData.cgi needs these parameters.
                          curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                          curl_setopt($ch, CURLOPT_USERPWD, '[B]USERNAME:PASSWORD[/B]');
                          // $output contains the output string
                          $output = curl_exec($ch);
                          echo $output;
                          // close curl resource to free up system resources
                          curl_close($ch);
                          
                            Write a Reply...