According to the MJPEG Wikipedia page ( http://en.wikipedia.org/wiki/Motion_JPEG#M-JPEG_over_HTTP ), the MJPEG stream via HTTP is basically a sequence of JPEG frames followed by a special mime type. To capture them and save them to a video file, I'm not sure if you can just write the incoming data into a .mpg file and have a working video.
Honestly, I'm not quite sure why your script doesn’t write anything at all, but I came across the following page, which, although written for specific software, contains examples of how to capture MJPEG and pass it to the browser: http: // www. lavrsen.dk/foswiki/bin/view/Motion/MjpegFrameGrabPHP
You can try one of your examples and save it to a file instead of transferring it to the browser. You can see that they read one image at a time:
while (substr_count($r,"Content-Length") != 2) $r.=fread($input,512); $start = strpos($r,'ÿ'); $end = strpos($r,$boundary,$start)-1; $frame = substr("$r",$start,$end - $start);
If this fixes the capture part of the stream but does not save it as video, another option is to save all the frames separately as a JPEG file and then stitch them together with a tool like ffmpeg to create the video: Image sequence for quality video
Update If you decide to take the ffmpeg road, you can also capture the stream with ffmpeg only. See this question for an example.
Hope this helps.
source share