Get jpeg-frame from mjpeg stream with PHP
Code opens mjpeg stream and grabs one frame of it. After that it outputs the image.
Syntax:
PHP
- TinyURL for this snippet: http://tinyurl.com/ld3mpd
<? $camurl="http://myhost:8080/cameras/1?q=40"; $boundary="\n--"; $f = @fopen($camurl,"r") ; if(!$f) { //**** cannot open echo "error"; } else { //**** URL OK while (substr_count($r,"Content-Length") != 2) $r.=@fread($f,512); $start = strpos($r,'ΓΏ'); $end = strpos($r,$boundary,$start)-1; $frame = substr("$r",$start,$end - $start); header("Content-type: image/jpeg"); echo $frame; } fclose($f); ?>