Motion - Mjpeg Grab And Proxy Using PH Pwith GD
PHP script to grab, proxy, resample and combine from mjpeg streams

Introduction

This script has 2 clearly seperated functions and is easy to figure out. It will proxy and grab a single image from a mjpeg stream and it grabs and resizes 4 pictures and fits them in an empty image of the original size using PHP with GD. Not the most efficient but it works, the grabber and resize portions can be easily seperated.

Installation

Make sure you have a current version of PHP installed and enabled. You will also need GD with the PEAR canvas module

Code

<?php
  // ***************
  // * Jim Anthony *
  // ***************
  function get_image($port)
  {
    $packetsize = 2048;
    $handle = fopen("http://127.0.0.1:$port/", "rb");
    $response = fread($handle, 75);
    $jpglength = substr($response, 65);
    $packets = floor($jpglength / $packetsize);
    for ($i = 0, $jpgfile = ''; $i < $packets; $i++)
      $jpgfile .= fread($handle, $packetsize);
    $jpgfile .= fread($handle, $jpglength % $packetsize);   
    fclose($handle);
    $image = imagecreatefromstring($jpgfile);
    return($image);
  }

  $image = imagecreatetruecolor(640, 480);
  imagecopyresampled($image, get_image(8001), 0, 0, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8002), 320, 0, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8003), 0, 240, 0, 0, 320, 240, 640, 480);
  imagecopyresampled($image, get_image(8004), 320, 240, 0, 0, 320, 240, 640, 480);
  header("Content-type: image/jpeg");
  imagejpeg($image);
  destroy($image);
?>

Comments and Bug Reports

Based on John Huongs script


Fatal error: Call to undefined function imagecreatetruecolor() in /var/www/fusetech/live.php on line 20

-- RomanGaufman - 23 Jul 2008

RelatedProjectsForm edit

ProjectSummary This script has 2 clearly seperated functions and is easy to figure out. It will proxy and grab a single image from a mjpeg stream and it grabs and resizes 4 pictures and fits them in an empty image of the original size using PHP with GD. Not the most efficient but it works, the grabber and resize portions can be easily seperated.
ProjectStatus Stable
ReleaseVersion 0
ProjectSubmitter JimAnthony
Topic revision: r2 - 23 Jul 2008, RomanGaufman
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.