Working with objects

IP-cameras, channels, templates, inputs, outputs, servers, SIMT areas and many other objects are packed together in a tree. Object tree can be seen in operator's interface displaying Objects tree (CMS)in the pattern or add to script by pressing the button Insert -> Objects in scripts editor.

All the objects are combined into classes:

  • Folder - class of parental objects ("Channels", "IP Devices", "Templates") which own all the other classes;
  • Server - connected servers class;
  • IP Device - connected IP-devices class;
  • Channel - connected channels class;
  • GPIO Input - alarm inputs class;
  • GPIO Output - alarm outputs class;
  • OperatorGUI - operator's interface class;
  • Template - class of templates.

In order to poll class objects list, one shall call function objects_list().

 alert(objects_list("Channel")) 

Message will show massive consisting of "Channel" class objects.

[
	('AC-D1050 1', 'Qmez0La2', 'Channel', 'p0aDXZdXC'), 
	('DVS Full 8', 'nBSAqWT1', 'Channel', 'p0aDXZdXC'), 
	('DVS Full 1', 'xeLzkjpd', 'Channel', 'p0aDXZdXC')
] 

In the given example the answer contains:

  • 'AC-D1050 1' - object name;
  • 'Qmez0La2' - unique guid of the object;
  • 'Channel' - object class;
  • 'p0aDXZdXC' - parental guid of the object which given object belongs to.

In addition, each object has status and methods, that is functions which can be called.

Finding an object in a script is easy:

 obj = object("Camera 1") 

Call the state()function to find out an object's state. Each object has several states (a state vector). For example, a channel has states for "motion", "signal", "recording", and "recording_on_device".

 m = obj.state("motion")
	if m=="No Motion":
		alert("No motion") 

To find out what states an object has, call state() with a random string. When the statement is executed, the error text will contain the names of the elements in the state vector.

To learn about state changes, use activation based on changed state:

 cam1 = object("Camera 1")
	def f():
		message("Motion: %s" % cam1.state["motion"])
	cam1.activate_on_state_changes(f) 

In addition to its state, you can learn an object's name, identifier, and class.

 alert(obj.name)
	alert(obj.guid)
	alert(obj.class_name) 

List of methods can be also received using dir()function which outputs the contents of any structure in Python.

alert(dir(obj)) 
"Channel" class object methods
cam1 = object("Camera 1")
  • Start channel archive record

    obj.manual_record_start()
  • Stop channel archive record

    obj.manual_record_stop()
  • Receive PTZ camera position

    obj.ptz_position_query()

    Values are saved in camera settings:

    settings("channels/[GUID_channel]/ptz/current_pan")
    	settings("channels/[GUID_channel]/ptz/current_tilt")
    	settings("channels/[GUID_channel]/ptz/current_zoom")
  • Move PTZ camera for presetting [preset]

    obj.ptz_preset([preset])
  • Start record

    obj.record(True or False)
  • Stop archive manual record

    obj.record_off()
  • Start channel archive manual record

    obj.record_on()
  • Save screenshot

    obj.screenshot()
  • Save screenshot from archive

    obj.screenshot_ex("[timestamp]", "[directory]")

    [timestamp] - time of the frame from archive;

    [directory] - directory on the server where screenshot is saved.

  • Save screenshot from archive

    obj.screenshot_v2("[time]", "[filename]", "[directory]", [make_thumb])

    [time] - time of the frame from archive;

    [filename] - name of the screenshot being saved;

    [directory] - directory on server where screenshot is saved;

    [make_thumb] - create thumbnail (0 - no).

  • Add text to video

    obj.set_watermark("[text]", [text_pos], [time_pos])

    [text] - user-defined text;

    [text_pos] and [time_pos] - text and time location angle: 1-upper left, 2-upper right, 3-lower left, 4-lower right.

  • Main/additional stream export from the channel archive

    obj.export_archive("[start_time]", "[end_time]", "[filename]", "[options]")

    [start_time] and [end_time] -start and end time of the exported fragment of the archive in the format YYYYMMDD_HHMMSS;

    [filename] - name of the saved file;

    [options] - additional options transmitted in the format "name" : value:

    • "is_hardware" - export archive from the device (0 - no)
    • "want_ss" - export additional stream (0 - no)
    • "video_codec" - recode video in codec ("MPEG4" or "WMV")
    • "video_bitrate" - recode using bitrate (value in Kbit/s)
    • "video_resolution" - resample video ("2560x1920", "2048x1536", "1920x1080", "1600x1200", "1280x1024", "1280x960", "1280x720", "1024x768", "800x600", "720x576", "704x576", "640x480", "352x288", "320x240", "176x144")
    • "audio_codec" - codec for audio ("PCM")
    • "audio_bitrate" - bitrate for audio (64, 128) Kbit/s
    • "need_channel_name_watermark" - enter channel name to video (0 - no)
    • "need_timestamp_watermark" - insert to video shooting time (0 - no)
    • "need_fliprotate" - use image angling settings from the channel (0 - no)
    • "watermark_need_figures" - add figures (0 -no)
    • "watermark_align" - inserted text location (1 - at the upper left, 2 - at the upper right, 3 - at the lower left, 4 - at the lower right)

"Operator's interface" class object methods
obj = object("Operator's interface maskaev-pc")
  • Main/additional stream export from the channel archive

    obj.archive_export("[channel]", "[start_time]", "[end_time]", "[filename]", [on_device])
    	obj.archive_export_ss("[channel]", "[start_time]", "[end_time]", "[filename]", [on_device])

    [channel] - channel name or its GUID;

    [start_time] and [end_time] -beginning and end time of the exported archive segment;

    [filename] - name of the saved file;

    [on_device] - archive export from the device (not 0).

  • Open channel archive

    obj.archive_open_inplace("[channel]", "[start_time]")

    [channel] - channel name or its GUID;

    [start_time] - positioning time.

  • Add channels to monitor

    obj.assign_channels("[csv_channels]", [monitor_n])

    [csv_channels] - list pf channels separated by commas;

    [monitor_n] - monitor number.

  • Change settings of the camera window view same way as in the view settings window.

    obj.change_view_settings("[name]", "[value]")

    [name] - settings name:

    "opts_[GUID_channel]_use_common"
    	"opts_[GUID_channel]_figures_on"
    	"opts_[GUID_channel]_figures_mode"
    	"opts_[GUID_channel]_border_mode"
    	"opts_[GUID_channel]_keep_ratio"
    	"opts_[GUID_channel]_show_osd"
    	"opts_[GUID_channel]_show_channel_name"
    	"opts_[GUID_channel]_show_channel_bold"
    	"opts_[GUID_channel]_switch_to_ss_pixels"
    	"opts_[GUID_channel]_turtle_enable"

    Tip

    In case you need to change the view settings of all the cameras, then, instead of [GUID_channel] use common.

    For example:

    obj = object("Operator's interface maskaev-pc")
    	obj.change_view_settings("opts_common_figures_on", "1")
    	obj.change_view_settings("opts_common_figures_mode", "3")
    	obj.change_view_settings("opts_syQURNtf_show_osd", "1")
    	obj.change_view_settings("opts_syQURNtf_show_channel_name", "0")

    [value] - setting value.

  • Switch economy mode on/off

    obj.eco_start("[channel]", [monitor_n])
    	obj.eco_stop("[channel]", [monitor_n])

    [channel] - channel name or its GUID;

    [monitor_n] - monitor number.

  • Activate/deactivate PTZ-camera control

    obj.ptz_start("[channel]", [monitor_n])
    	obj.ptz_stop("[channel]", [monitor_n])

    [channel] - channel name or its GUID;

    [monitor_n] - number of monitor to control PTZ-camera.

  • Control PTZ-camera

     obj.ptz_focus_auto("[channel]", [monitor_n])
    	obj.ptz_iris_auto("[channel]", [monitor_n])
    	obj.ptz_set_coordinates("[channel]", [monitor_n], [pan], [tilt], [zoom])
    	obj.ptz_set_focus("[channel]", [monitor_n], [speed])
    	obj.ptz_set_iris("[channel]", [monitor_n], [speed])
    	obj.ptz_set_zoom("[channel]", [monitor_n], [speed])
    	obj.ptz_start("[channel]", [monitor_n])
    	obj.ptz_stop("[channel]", [monitor_n])
    	obj.ptz_turn_x("[channel]", [monitor_n], [speed_pan])
    	obj.ptz_turn_y("[channel]", [monitor_n], [speed_tilt]

    [channel] - channel name or its GUID;

    [monitor_n] - number of the monitor to control PTZ-camera;

    [pan], [tilt], [zoom] - tilt coordinates (fractional);

    [speed], [speed_pan], [speed_tilt] - tilt rate (integral).

  • Show monitor on top of all windows

    obj.raise_monitor([monitor_n])

    [monitor_n] - monitor number.

  • Save screenshot from archive

    obj.screenshot("[channel]", "[time]", "[filename]")
    	obj.screenshot_ex("[channel]", "[time]", "[filename]", "[directory]", [make_thumb])

    [channel] - channel name or its GUID;

    [time] - time of the frame from archive;

    [filename] - name of the screenshot being saved;

    [directory] - directory on server where screenshot is saved;

    [make_thumb] - create thumbnail (0 - no).

  • Show channel or template on display

    obj.show("[name]", [monitor_n])
    	obj.show_channel("[name]", [monitor_n])
    	obj.show_template("[name]", [monitor_n])
    	obj.show_template_by_guid("[name]", [monitor_n])

    [name] - name of channel or template;

    [monitor_n] - monitor number.

  • Show channel archive on monitor or in the template

    obj.show_archive("[name]", [monitor_n], "[start_time]", "[end_time]")

    [name] - name of channel or template;

    [monitor_n] - monitor number;

    [start_time] and [end_time] - archive fragment start and end time.

  • Show html-page on the monitor or in the template

    obj.show_html("[source]", "[url]")
    	obj.show_html_on_monitor([monitor_n], "[source]", "[url]")
    	obj.show_html_on_templete([monitor_n], "[name]", "[source]", "[url]")

    [monitor_n] - monitor number;

    [name] - template name;

    [source] - minibrowser's identifier;

    [url] - displayed HTML-page address.

  • Update current screen

    obj.update_active_monitor([csv_channels])

    [csv_channels] - list of channels separated by comma.