*hooray* worlds first mjpeg balcony pumpkin cam

A project log for [SW] TF-520 based IP cam i/f = balcony pumpkin cam

got it cheap because of the crappy SW ("requires" IE5/Netstape and java...) - interesting stuff :D

rawerawe 07/08/2014 at 16:150 Comments


My pumpkin population exploded a bit, my whole balcony is now a pumpkin jungle! How to supervise them and check if they broken out and try to take over the world? Digitus IP cam to the rescue!

Hmm.. ok I need to get a fisheye lens, else it is not possible to see the whole picture... (already ordered, crappy 5 eur toy for smartphones :D)

No, I won't let you access my private CCTV pumpkin cam ;) But here is PHP code to build one yourself...


function get_one_jpeg()
$addr = gethostbyname("INSERT HOSTNAME OR IP HERE");
$client = stream_socket_client("tcp://$addr:4321", $errno, $errorMessage);
$header = fread($client,4);
$payload_size = unpack("n*",$header)[1];
$bytes_to_go = $payload_size;
$readmore = true;
$partsize = 512;

$payload = "";

#header('Content-Type: image/jpeg');


    if($bytes_to_go <= 0)
        $readmore = False;


return $payload;

# Used to separate multipart
$boundary = "my_mjpeg";

# We start with the standard headers. PHP allows us this much
header("Cache-Control: no-cache");
header("Cache-Control: private");
header("Pragma: no-cache");
header("Content-type: multipart/x-mixed-replace; boundary=$boundary");

# From here out, we no longer expect to be able to use the header() function
print "--$boundary\n";

# Set this so PHP doesn't timeout during a long stream

# Disable Apache and PHP's compression of output to the client
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);

# Set implicit flush, and flush all current buffers
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++)

# The loop, producing one jpeg frame per iteration
while (true) {
    # Per-image header, note the two new-lines
    print "Content-type: image/jpeg\n\n";

    # Your function to get one jpeg image
    print get_one_jpeg();

    # The separator
    print "--$boundary\n";

MJPEG code taken from , thank you Ben!