User Tools

Site Tools


http_api_lua |

HTTP API for HE4K-01 / HE4K-R4 / MVE-150 / MVE-100R / SME-01 / DME-02/03/04 / SBE264-DVR-23 / BLE264-S4 / BLE264-H4

For Camera/Sensor based products (Z3Cam/FXXX) and the HE1080/DME-10 use Z3-Camera_Solutions-http_api

Configuration API Syntax

Setting Configuration

To set a configuration variable, simply perform an HTTP POST to the URL
http:/server_address/cgi-bin/control.cgi


with the body

variable=value

For per-channel configuration items, the varname is written as with Cn_varname,
where n is the channel number.
The response contains a return code in JSON format.

After setting the configuration, you must start or stop the channel
for the settings to take effect.

Python example code for setting configuration:

import requests

server_url='http://192.168.0.120/cgi-bin/control.cgi'

r = requests.post(server_url, 'C1_enc_port=22222')
print r
print r.json()

Reading Configuration

To read configuration variable, simply perform an HTTP POST to the URL

http://server_address/cgi-bin/control.cgi

with the body as given below.

The reponse will be in JSON format, giving the value of each variable.
To read global configuration variables, POST with this body:

ctrl=sys&chn=null

To read encoder channel configuration variables for channel 1, POST with this body:

ctrl=enc&chn=1

To read decoder channel configuration variables for channel 1, POST with this body:

ctrl=dec&chn=1

Python example code for reading configuration:

import requests, json, sys

server_url='http://192.168.0.120/cgi-bin/control.cgi'

global_cfg = requests.get(server_url, params='ctrl=sys&chn=null')
print global_cfg.json()

enc_cfg = requests.get(server_url, params='ctrl=enc&chn=1' )
print enc_cfg.json()

Persistent Configuration

If you want the current configuration to be saved for future startups, you must explicitly perform the “SaveUser” action.

Python example code for saving configuration to persistent storage:

#! /usr/bin/env python

import requests, json, sys
from time import sleep

server_url='http://192.168.81.7/cgi-bin/control.cgi'

payload='action=SaveUser'
r = requests.post(server_url, payload)
print r
print r.json()

Global Configuration

sysdevicename=HE4K-01
syspassword=
enc_channels=C1
dec_channels=C1
opmode=enc_ultrahd
opstate=Idle
use_dhcp=on

Encoder Common Configuration

Encoder Channel Configuration

C1_enc_enable

Description: Global enable for this a/v encoder channel

Possible values: yes, no

C1_enc_vidin

Description: Video input from which encoder will source its video

Possible values: Board-dependent

C1_enc_vbitrate

Description: Video bitrate in bits per second.

Possible values: A “K” suffix indicates kilobits (thousands of bits/second).

A “M” suffix indicates megabits (millions of bits/second).

Note: In UDP transport stream case, the C1_enc_tsrate should be set

higher than the C1_enc_vbitrate, with at least 15% margin.

C1_enc_frameratediv

Description: Divide video input frame rate by this number to get encode frame rate.
The encoder will discard (frameratediv-1) out of (frameratediv) frames.

Possible values: 1, 2, 3, 4, 5, 6

C1_enc_gopsize

Description: Distance between I frames (key frames) in GOP sequence

Possible values: 1 through 240

C1_enc_vprofile

Description: H.264 profile (see https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles​ for full description)

Possible values: baseline, main, high

C1_enc_maxdelayms

Description: Video maximum burst size in milliseconds.

Possible values: 100 to 2000

C1_enc_interframeinterval

Description: Number of B frames in GOP sequence

Possible values: 0, 1, 2

0 means GOP sequence IPPPPPP…
1 means GOP sequence IPBPBPBPBPB…
1 means GOP sequence IPBBPBBPBBPBBPBB…

Note: In 2160p mode, the interframeinterval must be set to 1
to achieve 30fps performance.

C1_enc_audonoff

Description: Enable or disable audio encoding.

Possible values: on, off

C1_enc_transport

Description: Protocol used to transport the encoded bitstream.

Possible values: rtp, rtmp, udp, asi, tsfile, mts, tsrtp

C1_enc_ip

Description: Destination IP address for encoded bitstream.

Possible values: Unicast or multicast IPv4 address

C1_enc_port

Description: Destination Layer 3 port (UDP for most transports, TCP for rtmp)

Possible values: 1-65535

The following parameters only apply to transport stream encoding
(transport is set to udp, asi, tsfile, mts, or tsrtp).

C1_enc_vpid

Description: Video PID for transport stream.

Possible values: 32 to 8191 – must not conflict
with other PID assignments

C1_enc_apid

Description: Audio PID for transport stream.

Possible values: 32 to 8191 – must not conflict
with other PID assignments

C1_enc_pcrpid

Description: PCR PID for transport stream.

Possible values: 32 to 8191 – must not conflict
with other PID assignments

C1_enc_pmtpid

Description: PMT PID for transport stream.

Possible values: 16 to 31 – must not conflict
with other PID assignments

C1_enc_tsrate

Description: Transport stream total transport rate in bits per second.

Possible values: The 'K' suffix indicates kilobits (thousands of bits/second).
The 'M' suffix indicates megabits (millions of bits/second).

Note: In UDP transport stream case, the C1_enc_tsrate should be set
higher than the C1_enc_vbitrate, with at least 15% margin.

C1_enc_lowlat

Description: Low latency transport stream mode (VBR).

Possible values: off, on

C1_enc_pcrinterval

Description: Interval between PCR packets in milliseconds.

Possible values: 30 - 100

==== C1_enc_auxonoff ====

Describe: Enable AUXillary file recording in UDP mode – allows simultaneous UDP streaming and TS file recording on the same channel. Only valid if transport is UDP and tslowlat is off

The path to storage is set by the “storage” parameter.

The filename is set by the “fprefix” parameter. The default value is “MOV1_%F_%T”. The ”%F” specifier inserts a date stamp, and the ”%T” specifier inserts a time stamp.

The recording file size is set by the “filesize” parameter. When the file reaches this size, a new file will be created.

==== C1_enc_fprefix ====

Description: Relative filename for TSFILE or AUX file recording. Note that “fprefix” does NOT include the absolute media path – the “storage” parameter is the proper place to specify the absolute media path.

==== C1_enc_storage ====

Absolute path to mounted media device (e.g. /media/sda1/)

Encoder Audio Configuration

C1_enc_audchan1_enable

Description: Enable audio channel

Possible values: yes, no

C1_enc_audchan1_codec

Description: Audio encoder algorithm selection

Possible values: dsp_aaclc

C1_enc_audchan1_brate

Description: Audio encode bitrate

Possible values: Depends on codec

C1_enc_audchan1_srate

Description: Audio sample rate

Possible values: 48000, 44100

C1_enc_audchan1_mode

Description: Audio channel configuration

Possible values: stereo, mono

C1_enc_audchan1_source

Description: Select audio input

Possible values: Board dependent

\

C1_enc_audchan1_pid

Description: Audio PID for transport stream.

Possible values: 32 to 8191 - must not conflict with other PID assignments.

\

C1_enc_audchan1_rtpport

Description: Destination UDP port for RTP audio

\

C1_enc_audchan1_ptspcr

Description: For transport stream modes only – intial PTS to PCR offset for audio, in milliseconds

Possible values: 100 to 2000

\

C1_enc_audchan1_format

Description: Audio data encapsulation

Possible values: adts

Encoder Text Overlay Configuration (only for DME-02/03/04, SBE264-01, SBE264-DVR-23, BLE264-S4, BLE264-H4)

C1_enc_ovlglobalalpha

Description: Global alpha blending setting

Possible values: 0 (totally transparent) to 100 (totally opaque)

C1_enc_ovltext

Description: ASCII Text to draw

C1_enc_ovltextenable

Description: Enable or disable text overlay

Possible values: on, off

C1_enc_ovltextlocation

Description: Set position of overlay text onscreen

Possible values: top_left, top_right, top_center, bottom_left, bottom_right, bottom_center

Actions

Python example code for starting/stopping all channels:

import requests, json
import sys, getopt

actionname='StartChannel'

server_url='http://192.168.0.120'

control_cgi_url = server_url + '/cgi-bin/control.cgi'

payload = 'ctrl=sys&chn=null'
sysctrl = requests.get(control_cgi_url, params=payload)

j = sysctrl.json()
print j

dec_channels_string = j['dec_channels']
enc_channels_string = j['enc_channels']
opmode       = j['opmode']

dec_channels = dec_channels_string.split( ',' )
enc_channels = enc_channels_string.split( ',' )

print 'dec_channels', dec_channels, 'enc_channels', enc_channels, 'opmode', opmode

if opmode[0:3] == 'enc':
    channel_list = enc_channels
elif opmode[0:3] == 'dec':
    channel_list  = dec_channels
else:
    print 'Bad opmode [', opmode, ']'
    sys.exit(1)

for channel in channel_list :
    # Remove leading C
    channel = channel[1:]
    print actionname, ' ', opmode, 'channel', channel
    payload = 'action='+actionname+'&'+ 'chn=' +channel+'&' + 'loadfromdb=true';
    headers={'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}

    r = requests.post(control_cgi_url, payload)
    print r.text

StartChannel


Transition the encoder or decoder channel into the running state.

Once you start the channel, it will not transmit data until the
video input is detected.

StopChannel

Transition the encoder or decoder channel into the stopped state.

GetStorage

Reads the device files and mount points of available storage. The following example shows an SD card device /dev/mmcblk0p1 mounted at the directory /media/mmcblk0p1 and a USB device /dev/sda1 mounted at the directory /media/sda1

import requests, json, sys

payload='action=GetStorage'
r = requests.post(server_url, payload)
print r
print r.json()

Output: <Response [200]> {u'mounts': u'/dev/mmcblk0p1 /media/mmcblk0p1/,/dev/sda1 /media/sda1/,', u'ret': u'0'}

Dynamic

Set a dynamic parameter after encoding has already started

chn='1'
variable='auxfile'
value='off'
payload='action=Dynamic&chn=' + chn + '&var=' + variable + '&val=' + value

r = requests.post(server_url, payload)
print r
print r.json()
vratediv    Set video frame rate divider
 vrate       Set bitrate
 auxfile     Dynamically start/stop auxfile recording (value is either on or off)

The auxfile command will return a status from the table below.

Auxfile status Number
VCAP_VENC_ERR_NO_SPACE -26
VCAP_VENC_ERR_THREAD_ERR -25
VCAP_VENC_ERR_BAD_MOUNTPOINT -24
VCAP_VENC_ERR_STOPPING_AUDIO -23
VCAP_VENC_ERR_MTS_INVALID_DEST -22
VCAP_VENC_ERR_MTS_BAD_UDP_DEST -21
VCAP_VENC_ERR_INSUFFICIENT_TS_RATE -20
VCAP_VENC_ERR_NO_SPARE_MTS_BW -19
VCAP_VENC_ERR_MTS_START_FAILURE -18
VCAP_VENC_ERR_MTS_DUPLICATE_DEST -17
VCAP_VENC_ERR_MTS_DUPLICATE_NAME -16
VCAP_VENC_ERR_MTS_TEARDOWN_FAILURE -15
VCAP_VENC_ERR_MTS_NAME_NOT_FOUND -14
VCAP_VENC_ERR_MTS_CREATE_FAILURE -13
VCAP_VENC_ERR_MTS_RATE_MISMATCH -12
VCAP_VENC_ERR_MTS_NO_FREE_INFO -11
VCAP_VENC_ERR_NOT_IMPLEMENTED -10
VCAP_VENC_ERR_AUDIO_CAPTURE_SINK -8
VCAP_VENC_ERR_NO_FREE_AUDIO_STREAM -7
VCAP_VENC_ERR_VIDEO_FILE_NAME_PARSE -6
VCAP_VENC_ERR_STREAM_NOT_RUNNING -5
VCAP_VENC_ERR_STREAM_HAS_CHILDREN -4
VCAP_VENC_ERR_AUDIO_CAPTURE_SOURCE -3
VCAP_VENC_ERR_STARTING_AUDIO -2
VCAP_VENC_ERR_BAD_DESTINATION -1
VCAP_VENC_SUCCESS 0
VCAP_VENC_WARN_ALREADY_STARTED 1

EncoderStatus

Requests an update to encoder_status_str variable.

To read the result, you need to POST the “stats” control as shown
in the Python example code below.

StreamStatus

Requests an update to stream_status_str variable.

To read the result, you need to POST the “stats” control as shown
in the Python example code below.

AStreamStatus

Requests an update to astream_status_str variable.

To read the result, you need to POST the “stats” control as shown
in the Python example code below.

SourceStatus

Requests an update to source_status_str variable.

To read the result, you need to POST the “stats” control as shown
in the Python example code below.

Reading Statistics

Python example of updating and reading encoder statistics:

import requests, json, sys
server_url='http://192.168.0.120/cgi-bin/control.cgi'

requests.post(server_url, 'action=EncoderStatus&chn=1')
requests.post(server_url, 'action=StreamStatus&chn=1')
requests.post(server_url, 'action=AStreamStatus&chn=1')
requests.post(server_url, 'action=SourceStatus&chn=1')

print requests.get(server_url, params='ctrl=stats&chn=null').json()

Example output:

{u'astream_status_str': u'Channel 1 Subchannel 1 Codec dsp_aaclc +OK', 
 u'ret': u'0', 
 u'decoder_status_str': u'', 
 u'session': u'---', 
 u'encoder_status_str': u'### Encode Bitstream Received Statistics ### Elased time = 4.4 secs 
                          CH | Bitrate (Kbps) | Actual Bitrate | FPS | Actual FPS | Key-frame FPS | Width | Height 
                          ------------------------------------------------------------------------------------------------------------ 
                          1 | 15000.00 | 7713.63 | 60.0 | 41.4 | 0.9 | 1920 | 1080 | +OK', 
 u'source_status_str': u'+HDMI1 1920x1080p 60.00 fps', 
 u'stream_status_str': u'Channel 1 URL rtp://192.168.0.6:5004 Frames 140 +OK'}


http_api_lua.txt · Last modified: 2020/02/18 16:08 by johnw