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);