Skip to main content

Displaying Unifi camera feed on a 📞 Snom phone

Snom phones ☎️ can do a lot of things. One of those things is displaying a ‘video’ 📹 feed from an intercom or a surveillance camera. With video I mean a lot of pictures 📷📷📷 after eachother. For that to work, the pictures need to be a certain size.

I own a Snom D785 and a Unifi UVC-G3 camera and obviously I wanted both to work together. Unfortunatly the Snom expects a certain size of pictures. The Unifi only spits out 1080p snaphots through the default snapshot url http://$IP/snap.jpeg. Does that mean it can’t be done?

Of course not! I don’t give up that easily. We need something that will dynamicly scale down the image. Whats the only programming language I sort-of know? Yes, PHP! 👨‍💻

I put this on a webserver that the phone could reach:

imageResizer("http://$IP/snap.jpeg", $H, $W);

function imageResizer($url, $width, $height) {
    header('Content-type: image/jpeg');
    list($width_orig, $height_orig) = getimagesize($url);
    $ratio_orig = $width_orig/$height_orig;

    if ($width/$height > $ratio_orig) {
      $width = $height*$ratio_orig;
    } else {
      $height = $width/$ratio_orig;
    }

    // This resamples the image
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($url);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
    // Output the image
    imagejpeg($image_p, null, 100);
}

If you’re playing along at home, you need to set $IP (of the camera), $H (height) and $W (width). Also be sure to enable anonymous snapshots in the camera settings.

Of course the phone doensn’t have a web browser 🌍. So how are we going to request this thing on our phone?

XML! No really…

Create a new file on the webserver and put the following in it:

<?xml version="1.0" encoding="UTF-8"?>
<SnomIPPhoneImageFile state="others_except_mb" dtmf="off">
        <LocationX>00</LocationX>
        <LocationY>00</LocationY>
        <URL>http://$WebserverIP/camerasnapshot.php</URL>
        <fetch mil="200">http://$WebserverIP/playback.xml</fetch>
</SnomIPPhoneImageFile>

Of course you can name the files whatever you want. I’m a blogpost, not a cop 👮.

Now program one of your phones functionkeys to call that URL. And voilà 🎉

Snom WebUI
It working
Click here to see it in action

Have fun or whatever.