Skip to content

Instantly share code, notes, and snippets.

@sguter90
Created November 10, 2022 13:20
Show Gist options
  • Save sguter90/07a86b01f052e4fcd4076ccdc1da27e6 to your computer and use it in GitHub Desktop.
Save sguter90/07a86b01f052e4fcd4076ccdc1da27e6 to your computer and use it in GitHub Desktop.
Grab screenshot from Synology SurveillanceStation camera
<?php
// login: <synologyUrl>/webapi/auth.cgi?api=SYNO.API.Auth&method=login&version=7&account=<user>&passwd=<pass>&session=SurveillanceStation&format=sid
// camera list: <synologyUrl>/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=7&start=0&limit=100&_sid=<sid>
$synologyUrl = 'https://192.168.1.XX:5001';
$user = "<user>";
$pass = "<password>";
$cameraID = 1; // field "ID" from camera list
$cameraStream = 1; // 0 = live stream, 1 = recording stream, 2 = mobile stream
$apiVersion = 7;
$enableSecureConnection = false; // set to true if you have a valid certificate
$connectionOptions = [];
if ($enableSecureConnection === false) {
$connectionOptions['ssl']['verify_peer'] = false;
$connectionOptions['ssl']['verify_peer_name'] = false;
}
$streamContext = stream_context_create($connectionOptions);
// login
$loginResponse = file_get_contents($synologyUrl . '/webapi/auth.cgi?api=SYNO.API.Auth&method=login&version='.$apiVersion.'&account=' . $user . '&passwd=' . $pass . '&session=SurveillanceStation&format=sid', false, $streamContext);
$loginResponse = json_decode($loginResponse);
if ($loginResponse->success != "true") {
echo "error: " . $loginResponse->code;
exit();
}
$sid = $loginResponse->data->sid;
// respond jpeg directly to browser
header('Content-Type: image/jpeg');
readfile($synologyUrl . '/webapi/entry.cgi?camStm=' . $cameraStream . '&version=' . $apiVersion . '&cameraId=' . $cameraID . '&api=SYNO.SurveillanceStation.Camera&preview=true&method=GetSnapshot&_sid=' . $sid, false, $streamContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment