Welcome to Python Amcrest’s documentation!

A Python 2.7/3.x module for Amcrest Cameras using the SDK HTTP API.

Installation

PyPI

$ pip install amcrest --upgrade
$ eval "$(register-python-argcomplete amcrest-cli)"

# To enable amcrest-cli autocomplete in the system:
$ echo 'eval "$(register-python-argcomplete amcrest-cli)"' >  /etc/profile.d/amcrest-cli-autocomplete.sh

RPM

$ git clone git@github.com:tchellomello/python-amcrest.git
$ ./autogen.sh
$ make rpm
$ dnf/yum install amcrest-cli-NVR.rpm pythonX-amcrest-NVR.rpm

Usage

from amcrest import AmcrestCamera
camera = AmcrestCamera('192.168.0.1', 80, 'admin', 'password').camera

#Check software information
camera.software_information
'version=2.420.AC00.15.R\r\nBuildDate=2016-09-08'

#Capture snapshot
camera.snapshot(0, "/home/user/Desktop/snapshot00.jpeg")
<requests.packages.urllib3.response.HTTPResponse object at 0x7f84945083c8>

#Capture audio
camera.audio_stream_capture(httptype="singlepart", channel=1, path_file="/home/user/Desktop/audio.aac")
CTRL-C to stop the continuous audio flow or use a timer

#Move camera down
camera.ptz_control_command(action="start", code="Down", arg1=0, arg2=0, arg3=0)))

#Record realtime stream into a file
camera.realtime_stream(path_file="/home/user/Desktop/myvideo")
CTRL-C to stop the continuous video flow or use a timer

Command Line

$ man amcrest-cli
or
$ amcrest-cli --help

# Saving credentials to file.
$ vim ~/.config/amcrest.conf
[patio]
hostname: 192.168.0.20
username: admin
password: 123456
port: 80

[living_room]
hostname: 192.168.0.21
username: admin
password: secret
port: 80

$ amcrest-cli --camera living_room --version-http-api
version=1.40

Text User Interface (TUI)

Configure amcrest.conf and trigger amcrest-tui, make sure the user triggering amcrest-tui have access to framebuffer device or use sudo.

NOTE: Execute it from console logins, like /dev/ttyX (Non X Window). Pseudo-terminals like xterm, ssh, screen and others WONT WORK.

$ vim ~/.config/amcrest.conf
[patio]
hostname: 192.168.0.20
username: admin
password: 123456
port: 80

[living_room]
hostname: 192.168.0.21
username: admin
password: secret
port: 80

$ amcrest-tui

Supportability Matrix

Model Tested Status Results/Issues
IPM-721S Yes working  
IP2M-841B/841W/842W Yes working  
IP3M-956B Yes working  
IP3M-956E Yes working  
IPM-HX1B Yes working  

If you have different model, feel fee to contribute and report your results.

Help

If you need any help, please join our community on the Gitter channels available at Gitter.

Developing

class amcrest.AmcrestCamera(host, port, user, password, verbose=True, protocol='http', retries_connection=None, timeout_protocol=None)

Bases: object

Amcrest camera object implementation.

class amcrest.audio.Audio

Bases: object

audio_input_channels_numbers
audio_output_channels_numbers
audio_send_stream(httptype=None, channel=None, path_file=None, encode=None)

Params:

path_file - path to audio file channel: - integer httptype - type string (singlepart or multipart)

singlepart: HTTP content is a continuos flow of audio packets multipart: HTTP content type is multipart/x-mixed-replace, and

each audio packet ends with a boundary string
Supported audio encode type according with documentation:
PCM ADPCM G.711A G.711.Mu G.726 G.729 MPEG2 AMR AAC
audio_stream_capture(httptype=None, channel=None, path_file=None)

Params:

path_file - path to output file channel: - integer httptype - type string (singlepart or multipart)

singlepart: HTTP content is a continuos flow of audio packets multipart: HTTP content type is multipart/x-mixed-replace, and

each audio packet ends with a boundary string
play_wav(httptype=None, channel=None, path_file=None)
class amcrest.event.Event

Bases: object

alarm_config
alarm_input_channels
alarm_out_config
alarm_output_channels
alarm_states_input_channels
alarm_states_output_channels
event_channels_happened(eventcode)

Params:

VideoMotion: motion detection event VideoLoss: video loss detection event VideoBlind: video blind detection event AlarmLocal: alarm detection event StorageNotExist: storage not exist event StorageFailure: storage failure event StorageLowSpace: storage low space event AlarmOutput: alarm output event

event_handler_config(handlername)
event_ip_conflict
event_login_failure
event_management
event_net_abort
event_storage_access_failure
event_storage_low_space
event_storage_not_exist
is_motion_detected
video_blind_detect_config
video_loss_detect_config
class amcrest.log.Log

Bases: object

log_clear_all
log_show(start_time, end_time)
class amcrest.motion_detection.MotionDetection

Bases: object

is_motion_detector_on()
is_record_on_motion_detection()
motion_detection
motion_recording
class amcrest.nas.Nas

Bases: object

Amcrest methods to handle NAS.

nas_information

Return NAS information.

class amcrest.network.Network

Bases: object

amcrest_ips = []
network_config
network_interfaces
ntp_config
scan_devices(subnet, timeout=None)

Scan cameras in a range of ips

Params: subnet - subnet, i.e: 192.168.1.0/24

if mask not used, assuming mask 24

timeout_sec - timeout in sec

Returns:

telnet_config
upnp_config
upnp_status
wlan_config
class amcrest.ptz.Ptz

Bases: object

focus_far(action=None, channel=0)
Params:
action - start or stop channel - channel number
focus_near(action=None, channel=0)
Params:
action - start or stop channel - channel number
go_to_preset(action=None, channel=0, preset_point_number=1)
Params:
action - start or stop channel - channel number preset_point_number - preset point number
iris_large(action=None, channel=0)

Aperture larger

Params:
action - start or stop channel - channel number
iris_small(action=None, channel=0)

Aperture smaller

Params:
action - start or stop channel - channel number
move_directly(channel=1, startpoint_x=None, startpoint_y=None, endpoint_x=None, endpoint_y=None)

Three-dimensional orientation. Move to the rectangle with screen coordinate [startX, startY], [endX, endY]

Params:
action - start or stop channel - channel index, start with 1 startX, startY, endX and endY - range is 0-8192
move_down(action=None, channel=0, vertical_speed=1)

The magic of move down 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.2 sec

move_left(action=None, channel=0, vertical_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range 1-8

The magic of move left 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.5 sec

move_left_down(action=None, channel=0, vertical_speed=1, horizontal_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range is 1-8 horizontal_speed - range is 1-8
move_left_up(action=None, channel=0, vertical_speed=1, horizontal_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range is 1-8 horizontal_speed - range is 1-8
move_right(action=None, channel=0, vertical_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range 1-8

The magic of move right 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.5 sec

move_right_down(action=None, channel=0, vertical_speed=1, horizontal_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range is 1-8 horizontal_speed - range is 1-8
move_right_up(action=None, channel=0, vertical_speed=1, horizontal_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range is 1-8 horizontal_speed - range is 1-8
move_up(action=None, channel=0, vertical_speed=1)
Params:
action - start or stop channel - channel number vertical_speed - range 1-8

The magic of move up 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.2 sec

ptz_auto_movement
ptz_config
ptz_control_command(channel=0, action=None, code=None, arg1=None, arg2=None, arg3=None)
ptz_presets_count
ptz_presets_list(channel=0)
ptz_status(channel=0)
ptz_tour_routines_list(channel=0)
zoom_in(action=None, channel=0)
Params:
action - start or stop channel - channel number

The magic of zoom in 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.5 sec

zoom_out(action=None, channel=0)
Params:
action - start or stop channel - channel number

The magic of zoom out 1x, 2x etc. is the timer between the cmd ‘start’ and cmd ‘stop’. My suggestion for start/stop cmd is 0.5 sec

class amcrest.record.Record

Bases: object

factory_create
media_global_config
record_capability
record_config
record_mode
class amcrest.snapshot.Snapshot

Bases: object

snapshot(channel=0, path_file=None, timeout=None)

Args:

channel:

Values according with Amcrest API: 0 - regular snapshot 1 - motion detection snapshot 2 - alarm snapshot

If no channel param is used, default is 0

path_file:
If path_file is provided, save the snapshot in the path
Return:
raw from http request
snapshot_config
class amcrest.special.Special

Bases: object

mjpeg_url(channelno=None, typeno=None)

Return MJPEG streaming url

Params:
channelno: integer, the video channel index which starts from 1,
default 1 if not specified.
typeno: the stream type, default 0 if not specified. It can be

the following value:

0-Main Stream 1-Extra Stream 1 (Sub Stream) 2-Extra Stream 2 (Sub Stream)

mjpg_stream(channelno=None, typeno=None, path_file=None)
Params:
channelno: integer, the video channel index which starts from 1,
default 1 if not specified.
typeno: the stream type, default 0 if not specified. It can be

the following value:

0-Main Stream 1-Extra Stream 1 (Sub Stream) 2-Extra Stream 2 (Sub Stream)

realtime_stream(channel=1, typeno=0, path_file=None)

If the stream is redirect to a file, use mplayer tool to visualize the video record

camera.realtime_stream(path_file=”/home/user/Desktop/myvideo) $ mplayer /home/user/Desktop/myvideo

rtsp_url(channelno=None, typeno=None)

Return RTSP streaming url

Params:
channelno: integer, the video channel index which starts from 1,
default 1 if not specified.
typeno: the stream type, default 0 if not specified. It can be

the following value:

0-Main Stream 1-Extra Stream 1 (Sub Stream) 2-Extra Stream 2 (Sub Stream)

class amcrest.storage.Storage

Bases: object

storage_device_info
storage_device_names
storage_total
storage_used
storage_used_percent
class amcrest.system.System

Bases: object

Amcrest system class.

config_backup(filename=None)
current_time
device_class

During the development, device IP2M-841B didn’t responde for this call, adding it anyway.

device_type
general_config
hardware_version
machine_name
onvif_information
reboot(delay=None)
serial_number
shutdown()

From the testings, shutdown acts like “reboot now”

software_information
system_information
vendor_information
version_http_api
class amcrest.user_management.UserManagement

Bases: object

add_user(username, password, group, sharable=True, reserved=False, memo=None)
Params:

username - username for user password - password for user group - string the range is “admin” and “user”. In different group,

the user has different authorities.

sharable - bool, true means allow multi-point login

reserved - bool, true means this user can’t be deleted

memo - memo to user

delete_user(username)
info_all_active_users
info_all_groups
info_all_users
info_group(group)
info_user(username)
modify_password(username, newpwd, oldpwd)
Params:
username - user name newpwd - new password oldpwd - old password
modify_user(username, attribute, value)
Params:

username - username for user attribute - the attribute name that will change:

group, sharable, reserved, memo

value - the new value for attribute

class amcrest.video.Video

Bases: object

encode_capability
encode_config_capability(channel)
encode_media
encode_region_interested
video_channel_title
video_color_config
video_coordinates_current_window(channel)
video_in_options
video_input_capability(channel)
video_input_channels_device_supported
video_max_extra_stream
video_max_remote_input_channels
video_out_options
video_output_channels_device_supported
video_standard
video_widget_config

Indices and tables