Skip to content

Instantly share code, notes, and snippets.

@ianthrive
Last active September 5, 2018 06:49
Show Gist options
  • Save ianthrive/5105216 to your computer and use it in GitHub Desktop.
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.
<?
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');
@WeWin55
Copy link

WeWin55 commented Sep 5, 2018

DANKE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment