Last active
September 5, 2018 06:49
-
-
Save ianthrive/5105216 to your computer and use it in GitHub Desktop.
Grabs a single frame from a motion-JPEG stream. Useful for IP-cameras that have such capability.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function mjpeg_grab_frame($url) { | |
$f = fopen($url, 'r'); | |
if($f) { | |
$r = null; | |
while(substr_count($r, "\xFF\xD8") != 2) $r .= fread($f, 512); | |
$start = strpos($r, "\xFF\xD8"); | |
$end = strpos($r, "\xFF\xD9", $start)+2; | |
$frame = substr($r, $start, $end-$start); | |
fclose($f); | |
return $frame; | |
} | |
} | |
header("Content-type: image/jpeg"); | |
echo mjpeg_grab_frame('http://10.10.10.10/mjpg/1/video.mjpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DANKE