Stream and download device recordings

Use this sample application to stream and download device recordings.

Video from trip recordings can be streamed and downloaded from the SD cards of your devices. Devices continuously record trips of more than 100 meters. They start recording once movement is detected by the built-in accelerometer. Audio is not played in these recordings.

By default, Surfsight devices come with a 128 GB SD card, which holds about 100 hours of video recordings. The oldest recorded file is cyclically replaced with a new recorded file once the SD card is full. Any of the recordings currently on the SD card can be streamed and donwloaded.

Note

Audio is available with event videos.

Important

The device must be in "status": "standby" or "status": "online" to stream and download recordings from the SD card.

One recording file may be uploaded at a time from the device.

Becoming familiar with this workflow

We have built a sample application to simplify the process of streaming and downloading recordings. Click here to download the sample application source code.

The following sections tell you more about the sample application and explain how to implement this from your platform:

Preparing to run the sample application

Before running the sample application, get a media server address and media token. Additionally, it's worth checking that a recording exists for the time you enter in the application.

1. Authenticate yourself

Authenticate yourself before making any calls with the Surfsight API. For more details on authentication, see our authentication overview.

2. Connect media

Receive the authentication token and media server address to retrieve a recording or live video with the POST /devices/{imei}/connect-media request.

Copy
Copied
    curl --request POST https://api-prod.surfsight.net/v2/devices/{imei}/connect-media
    --header 'Content-Type: application/json'
    --header 'Authorization: Bearer {token}'

Returned response:

Copy
Copied
{
    "data": {
        "address": "prodmedia-us-05.surfsolutions.com",
        "mediaToken": "0e5d4dfb-56fe-4271-b9c8-86e4d7f214d5"
    }
 }
Note

The token is valid for thirty minutes.

3. Select a recording

Receive a list of available recordings from every camera of your device in the desired time range with the GET /devices/{imei}/recording-ranges request.

curl --request GET https://api-prod.surfsight.net/v2/devices/{imei}/recording-ranges?start={start}&end={end}
--header 'Content-Type: application/json'
--header 'Authorization: Bearer {token}'
Component Description Example
imei The IMEI number of the device from which you are uploading recordings. 357660101000198
start Filter by a start date and time, in ISO 8601 format. start=2020-01-01T14:48:00.000Z
end Filter by an end date and time, in ISO 8601 format. end=2020-01-01T15:48:00.000Z

Returned response:

Copy
Copied
{
    "data": [
        {
            "cameraId": 1,
            "intervals": [
                {
                    "start": "2021-10-15T15:06:35.000Z",
                    "end": "2021-10-15T15:34:38.000Z"
                },
                {
                    "start": "2021-10-16T08:19:46.000Z",
                    "end": "2021-10-16T09:13:56.000Z"
                },
                {
                    "start": "2021-10-16T10:17:32.000Z",
                    "end": "2021-10-16T12:19:52.000Z"
                }
            ]
            },
        {
            "cameraId": 2,
            "intervals": [
                {
                    "start": "2021-10-15T15:06:35.000Z",
                    "end": "2021-10-15T15:34:38.000Z"
                },
                {
                    "start": "2021-10-16T08:19:46.000Z",
                    "end": "2021-10-16T09:13:56.000Z"
                },
                {
                    "start": "2021-10-16T10:17:32.000Z",
                    "end": "2021-10-16T12:19:52.000Z"
                }
            ]
        }
    ]
}
Note

Enter the time range in ISO 8601 format.

Note

If "data": [] is returned empty, this indicates that there are no recordings on the SD card for the selected time range.

Running the sample application

This process describes how to run the sample application as is; for this, you only need to work with the static.js and index.html files.

  1. Download the sample application and unzip the file.
  2. In the static.js file, modify the parameters with your own.

The following table explains these parameters in detail and provides examples of the changed parameters for illustrative purposes only:

Component Description Example
mediaServerAddress The server received in step 2. prodmedia-us-05.surfsolutions.com
mediaToken The media token received in step 2. 0e5d4dfb-56fe-4271-b9c8-86e4d7f214d5
imei The IMEI number of the device from which you are uploading recordings. 357660101000198
cameraId The ID of the camera from which you want a recording (1 - road-facing camera, 2 - in-cabin-facing camera, 51 to 54 - auxiliary cameras). 2
startTime The start time of the recording you want to receive, in UNIX. Convert the time received in Step 3 from ISO 8601 to UNIX. 1634091790
videoDuration The length of time of the recording you want to receive, in seconds. 60
quality Select one of the following recording quality options when uploading the video:
  • high quality (hq) - recordings play in the frames per second configured in your data profile.
  • low quality (lq) - recordings play in 1 frame per second
.
lq
  1. Click the index.html file.
  2. In the window that pops up, click play. The video streams.
  3. After streaming the video, download it from the cloud using the following url below: https:///download/{imei}/{mediaToken}/{imei}{cameraId}{startTime}{videoDuration}{qualityLevel}.mp4

    When creating the URL to download the recordings, use the strings that were aquired from the steps above.

    Note

    The recording is available to download for one hour after it was streamed.