|  Developer
Updated on May 5, 2022

Cameras module API( require “cameras” )

Edit
  • Subscribe for Cameras events. After subscribing the script will be launched for each event happens on a Cameras addon and information about this event will be passed as a parameter.
Edit
Edit
params type description
script name string lua script name
Edit
  • subscriber_id (string).
Edit
  • Unsubscribe from Cameras events.
Edit
Edit
params type description
subscriber_id string subscriber id
Edit
  • none.
Edit
  • Creates Camera stream instance in Camera addon and saves it to database. Returns error in case of the camera stream already exists
Edit
Edit
params type description
streamId string stream id, must be unique
streamName string name for the camera
rtspUrl string rtsp link for reading stream from physical camera. Example
description string optional, describes the camera for user
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.add_camera_stream( "588b7eb528b12d03be86f36f", 
                           "Camera Name",
                           "rtsp://admin:719347a355d0031f4000153a0230b122702fd144@192.168.33.101:554/ISAPI/Streaming/channels/1",
                           "Hall camera"           
)				
			
Edit
  • Removes Camera stream instance from both Camera addon and database, stops all activities for the camera.
Edit
Edit
params type description
streamId string stream id
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.remove_camera_stream( "588b7eb528b12d03be86f36f" )				
			
Edit
  • Starts proxying stream from physical camera to new RTSP link. The RTSP link in sent with live_rtsp_stream_started event. This stream isn’t restored after hub reboot.
Edit
Edit
params type description
streamId string stream id
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.create_live_rtsp_stream( "588b7eb528b12d03be86f36f" )				
			
Edit
Edit
Edit
params type description
streamId string stream id
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.delete_live_rtsp_stream( "588b7eb528b12d03be86f36f" )				
			
Edit
  • Creates instance for saving video stream to cloud. This instance isn’t restored after hub reboot.
Edit
Edit
fields type description
streamId string stream id
segmentDuration int portion of stream to save in seconds. Returns error if duration less than 30 seconds
secondsBeforeStart int save video before start saving in seconds (optional, if not specified, then 0)
segmentsLimit int limit segments that will be recorded to specified amount (optional, if not specified or 0, no limit is set). When limit is set after start_stream_saving_to_cloud is called saving will stop after specified segments count finished or stop_stream_saving_to_cloud (what happens first)
format string Specify format of recorded file. Supported formats: , . Optional, if not specified or empty, format is used.
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.create_stream_saving_to_cloud( "588b7eb528b12d03be86f36f",
                                       30,
                                       5 
                                      )				
			
Edit
  • Deletes instance for saving video stream to cloud.
Edit
Edit
fields type description
streamId string stream id
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.delete_stream_saving_to_cloud( "588b7eb528b12d03be86f36f" )				
			
Edit
Edit
Edit
fields type description
streamId string stream id
metaData table [opt] custom user data
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.start_stream_saving_to_cloud( "588b7eb528b12d03be86f36f",
                                      { ["meta"] = "data" }
                                    )				
			
Edit
Edit
Edit
fields type description
streamId string stream id
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.stop_stream_saving_to_cloud( "588b7eb528b12d03be86f36f" )				
			
Edit
  • Makes one stream snapshot to jpeg file and this file to cloud storage. The id of file is returned in event stream_snapshot.
Edit
Edit
fields type description
streamId string stream id
snapshotId string snapshot id, must be unique
metaData table [opt] custom user data
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.make_stream_snapshot( "588b7eb528b12d03be86f36f",
                              "5fc4dedc00000028347b0323",
                              { ["meta"] = "data" }
                            )				
			
Edit
  • Creates and opens audio stream to camera. This stream will be available at URL: . If stream with specified streamId already exists, returns error.

Edit
Edit
Edit
fields type Required description
streamId string + Audio stream id
request object +
request.format enum Audio stream format. Possible values: hv, fc. Default: hv
request.* Depends on request.format
user_data any Any data which will be passed to stream event handlers. Can be of any valid type: string, number, boolean, array, object. If user_data is nil, the value will not be set.
Edit
Request fields for format:
fields type Required description
request.url string + HTTP URL
request.type string + HTTP request method. Possible values: , , ,
request.headers object
request.headers. string + Header name
request.headers. string + Header value
request.user string User for Basic HTTP Authentication
request.password string Password for Basic HTTP Authentication
Edit
Request fields for format:
fields type Required description
request.address string + Camera address
request.port int + Camera audio stream port
request.magic string + Magic token
request.user string + Camera user
request.password string + Camera password
Edit
  • none.
Edit
Edit
				
					local cameras = require("cameras")

cameras.create_audio_stream( "588b7eb528b12d03be86f36f", {
        type = "PUT",
        url = "http://192.168.42.55:3580/ISAPI/System/TwoWayAudio/channels/1/audioData",
        user = "admin",
        password = "password",
        headers = {
            ["Content-Type"] = "application/octet-stream",
            ["Content-Length"] = "0",
            Connection = "keep-alive"
        }
    }
)				
			
Edit
				
					local cameras = require("cameras")

cameras.create_audio_stream( "588b7eb528b12d03be86f36e", {
        format = "fc",
        address = "192.168.0.212",
        port = 49587,
        magic = "EZLO"
        user = "admin",
        password = "password",
    }
)				
			
Edit
  • Stops and deletes previously opened audio stream to camera. Does nothing if there are no streams with specified streamId.
Edit
fields type Required description
streamId string + Audio stream id
Edit
Edit
  • none.
Edit
				
					local cameras = require("cameras")

cameras.delete_audio_stream( "588b7eb528b12d03be86f36f" )				
			
Edit
  • Returns audio stream info by its streamId. If there are no streams with specified streamId a nil result is returned.
Edit
fields type Required description
streamId string + stream id
Edit
Edit
fields type Required description
streamId string + Audio stream id
request object +
request.format enum Audio stream format. Possible values: , . Default:
request.* Depends on request.format. Refer to create_audio_stream
user_data any User data which was passed to create_audio_stream
Edit
				
					local cameras = require("cameras")

local info = cameras.get_audio_stream_info( "588b7eb528b12d03be86f36f" )				
			
Edit
  • Sets the settings for video particle, used as a preview for a stream recording created by start_stream_saving_to_cloud. Video particle has a smaller resolution than the original stream.
  • The settings are applied per plugin, i.e. the specified settings will be applied to video particles created for all camera streams added by the calling plugin. The plugin’s name is determined automatically by the Firmware.
  • If the plugin didn’t specify the settings before calling the create_stream_saving_to_cloud, then the default settings will be used: preRecordDurationSec – 2, recordDurationSec – 3, resolutionDivisor – 4, format – “mp4”.
  • Calling this function after the create_stream_saving_to_cloud will not affect the particles created with the stream recording.
Edit
fields type description
preRecordDurationSec int The stream portion of this duration (in seconds) is recorded before an event triggers the recording.
recordDurationSec int The stream portion of this duration (in seconds) is recorded after an event triggers the recording.
resolutionDivisor int The divisor of the original stream resolution. The minimum value of the divisor is , if value of this param is smaller than the threshold, it will be automatically set to default. Optional, default divisor is .
format string Specify format of recorded file. Supported formats: , . Optional, if not specified or empty, format is used.
Edit
Edit
  • return: none
Edit
				
					local cameras = require("cameras")
cameras.set_video_particle_settings( 3, 3, 4, "mp4" )