{"id":13017,"date":"2017-02-22T15:25:17","date_gmt":"2017-02-22T21:25:17","guid":{"rendered":"http:\/\/www.eagleeyenetworks.com\/?p=13017"},"modified":"2020-08-11T13:50:14","modified_gmt":"2020-08-11T18:50:14","slug":"authentication-live-camera-preview-stream","status":"publish","type":"post","link":"https:\/\/www.een.com\/fr\/blog\/authentication-live-camera-preview-stream\/","title":{"rendered":"Live Camera Preview Stream"},"content":{"rendered":"<p>There have been many questions on how to use our API. One of the most frequent questions we get from our customers is, \u201cHow can we play a live preview stream for a camera on our public website?\u201d For those that do not know what a live preview stream is, it is simply a series of JPEG images from a particular camera. Normally the system generates one preview image per second within the stream, however it is possible to set the camera to generate four previews per second (we will not cover how to do so in this blog post).<\/p>\n<p>For security purposes, our ecosystem does not support unauthenticated cameras, therefore authentication is required to view the live camera preview stream. If you want to show the live preview stream publicly on your website, you will need to create a web service to use our Authentication API and Camera Preview API. This way the web service will have authentication privileges to grab the image and any visitor on your website will be able to view the live preview stream. In technical speak, the web service acts as an authenticated user proxy for public requests.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-13019\" src=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server.jpg\" alt=\"API Your Server\" width=\"695\" height=\"235\" srcset=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server.jpg 695w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server-300x101.jpg 300w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server-100x34.jpg 100w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server-200x68.jpg 200w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server-400x135.jpg 400w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Your-Server-600x203.jpg 600w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/p>\n<p>In this example, we will use Python\/Flask, but we will also provide a Golang example at the end of this blog.<\/p>\n<p>What we will cover in this blog:<br \/>\n\u25cf Identify the camera ESN you want to publicly preview stream<br \/>\n\u25cf Create a user in your account with ONLY preview stream privileges (remember the username and password)<br \/>\n\u25cf Create the authentication code in the web service<br \/>\n\u25cf Create the image grabbing code in the web service<br \/>\n\u25cf Optimize the code for performance<br \/>\n\u25cf Create the javascript code to call your web service<\/p>\n<p>Prerequisites:<br \/>\n\u25cf Understand web service programming<br \/>\n\u25cf Must have an account with Eagle Eye Networks<br \/>\n\u25cf Must have admin access in the account to create users<br \/>\n\u25cf Must have a bridge and camera attached and properly streaming in the account<\/p>\n<p>Identify ESN of the Camera:<br \/>\nThe first step is to identify the ESN of the camera you want to use for the preview stream. You will want to log into our service (<a href=\"https:\/\/login.eagleeyenetworks.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/login.eagleeyenetworks.com\/<\/a>) using your username and password. All devices within the EEN (Eagle Eye Networks) ecosystem contain an Electronic Serial Number (ESN). This ESN is an eight digit hexadecimal string. You can easily identify the ESN of the camera you want to stream by opening the settings of the camera. From the dashboard, click the gear box of the camera you want to live preview stream.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-13018\" src=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication.png\" alt=\"API Authentication\" width=\"1892\" height=\"202\" srcset=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication.png 1892w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-300x32.png 300w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-1024x109.png 1024w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-100x11.png 100w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-200x21.png 200w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-400x43.png 400w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-600x64.png 600w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-800x85.png 800w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/API-Authentication-1200x128.png 1200w\" sizes=\"(max-width: 1892px) 100vw, 1892px\" \/><br \/>\n<img decoding=\"async\" class=\"aligncenter size-full wp-image-13020\" src=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera.png\" alt=\"Camera Setting Test Camera\" width=\"791\" height=\"667\" srcset=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera.png 791w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-300x253.png 300w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-100x84.png 100w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-154x130.png 154w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-200x169.png 200w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-400x337.png 400w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/Camera-Setting-Test-Camera-600x506.png 600w\" sizes=\"(max-width: 791px) 100vw, 791px\" \/><\/p>\n<p>In our example, we will use the ESN 1006073b.<\/p>\n<p>User Setup:<br \/>\nIt is now time to create a user for our web service to use. We will limit the user\u2019s permission to only be able to live preview stream the 1006073b camera. Open the Users section and add a user. Remember that a user requires an email address. After a user has been added, an email is sent to the email address specified asking the user to activate his\/her credentials. You must activate the user prior to using it for your web service! The below image shows you how to only set permissions to view the live preview stream:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13021\" src=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings.png\" alt=\"User Settings\" width=\"690\" height=\"736\" srcset=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings.png 690w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-281x300.png 281w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-94x100.png 94w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-122x130.png 122w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-200x213.png 200w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-400x427.png 400w, https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/User-Settings-600x640.png 600w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/p>\n<p>Backend Server:<br \/>\nThe next step is to code! For our examples we will be using Python and Flask. We assume you know how to set the framework and will not cover that portion. Let\u2019s jump right into it!<\/p>\n<p>Authenticating:<br \/>\nThe first thing we have to do is authenticate with the user you have created (see <a href=\"https:\/\/apidocs.eagleeyenetworks.com\/apidocs\/#step-1:-authenticate\" target=\"_blank\" rel=\"noopener noreferrer\">Authentication<\/a>). There are two steps to the authentication process. Authenticate, which we send the username (email) and password. A successful response will return a token. This token is then passed to a second call: Authorize. Once you have been authorized, you will be issued a auth_key cookie. Retain this cookie for any future calls!<\/p>\n<p>Authenitcate and Authorize:<\/p>\n<p>Once you have your auth_key cookie, it is time to get preview images!<\/p>\n<p>Preview image code:<br \/>\nRetrieving preview images is a breeze. There are several api calls to get an image from the preview stream.<br \/>\n\u25cf <a href=\"https:\/\/apidocs.eagleeyenetworks.com\/apidocs\/#get-image\" target=\"_blank\" rel=\"noopener noreferrer\">Previous Image<\/a> \u2013 This endpoint allows you to specify a time and get a previous image in history from the time stamp as the anchor point.<br \/>\n\u25cf <a href=\"https:\/\/apidocs.eagleeyenetworks.com\/apidocs\/#get-image\" target=\"_blank\" rel=\"noopener noreferrer\">Current Image<\/a> \u2013 This endpoint allows you to specify a time and get the image at that specific endpoint. You cannot just willy nilly choose a timestamp and fetch an image. Images are created by our Bridge system. In order to figure out which timestamp you want you will need to do a List call (not covered in this blog post). See <a href=\"https:\/\/apidocs.eagleeyenetworks.com\/apidocs\/#get-list-of-images\" target=\"_blank\" rel=\"noopener noreferrer\">Get List Of Images<\/a>.<br \/>\n\u25cf <a href=\"https:\/\/apidocs.eagleeyenetworks.com\/apidocs\/#get-image\" target=\"_blank\" rel=\"noopener noreferrer\">Next Image<\/a> \u2013 This endpoint allows you to get the next image from a timestamp. You can specify the current time and the system will wait until the cloud receives the image or immediately return if the image already exists in the cloud.<\/p>\n<p>We will use the Next Image api call.<\/p>\n<p>Background Preview Image Code (Optimized Process):<br \/>\nThere is a slight problem of inefficiency. You do not want to call this logic every time there is a request from a client. If there are 100 clients, there will be 100 image calls. And these image calls might return the same image! Therefore it is suggested to have a background task that retrieves the image and pushes it into shared memory. From there, any request will always get the latest image. We use GEvent as a co-processing mechanism. We create a greenlet for our background image fetcher and fetch images every second. We then write the results to a shared memory location for any requester to view.<\/p>\n<p>Javascript\/HTML Code<br \/>\nAnd now the easy part. We will call a one second timer to continuously fetch the images.<\/p>\n<p>Conclusion:<br \/>\nGrabbing images in the EEN ecosystem is fairly straightforward. The only barrier of entry is authenticating as a user in order to fetch the image. Eventually we will make cameras public accessible which would eliminate the need for the Backend Web Proxy.<\/p>\n<p>You can download the python app and golang app <a href=\"https:\/\/www.een.com\/wp-content\/uploads\/2017\/02\/blog.zip\">blog<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There have been many questions on how to use our API. One of the most frequent questions we get from our customers is, \u201cHow can we play a live preview &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.een.com\/fr\/blog\/authentication-live-camera-preview-stream\/\"> <span class=\"screen-reader-text\">Live Camera Preview Stream<\/span> Lire la suite\u00a0\u00bb<\/a><\/p>\n","protected":false},"author":3155,"featured_media":13231,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","footnotes":""},"categories":[232],"tags":[1275,1273,1272],"class_list":["post-13017","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-cloud-computing","tag-cloud-video-surveillance","tag-video-management-software"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/posts\/13017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/users\/3155"}],"replies":[{"embeddable":true,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/comments?post=13017"}],"version-history":[{"count":0,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/posts\/13017\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/media\/13231"}],"wp:attachment":[{"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/media?parent=13017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/categories?post=13017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.een.com\/fr\/wp-json\/wp\/v2\/tags?post=13017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}