This is an old revision of the document!
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()
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()
sysdevicename=HE4K-01
syspassword=
enc_channels=C1
dec_channels=C1
opmode=enc_ultrahd
opstate=Idle
use_dhcp=on
Description: Global enable for this a/v encoder channel
Possible values: yes, no
Description: Video input from which encoder will source its video
Possible values: Board-dependent
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.
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
Description: Distance between I frames (key frames) in GOP sequence
Possible values: 1 through 240
Description: H.264 profile (see https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles for full description)
Possible values: baseline, main, high
Description: Video maximum burst size in milliseconds.
Possible values: 100 to 2000
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.
Description: Enable or disable audio encoding.
Possible values: on, off
Description: Protocol used to transport the encoded bitstream.
Possible values: rtp, rtmp, udp, asi, tsfile, mts, tsrtp
Description: Destination IP address for encoded bitstream.
Possible values: Unicast or multicast IPv4 address
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
Description: Enable audio channel
Possible values: yes, no
Description: Audio encoder algorithm selection
Possible values: dsp_aaclc
Description: Audio encode bitrate
Possible values: Depends on codec
Description: Audio sample rate
Possible values: 48000, 44100
Description: Audio channel configuration
Possible values: stereo, mono
Description: Select audio input
Possible values: Board dependent
Description: Audio PID for transport stream.
Possible values: 32 to 8191 - must not conflict with other PID assignments.
Description: Destination UDP port for RTP audio
Description: For transport stream modes only – intial PTS to PCR offset for audio, in milliseconds
Possible values: 100 to 2000
Description: Audio data encapsulation
Possible values: adts
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
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.
Transition the encoder or decoder channel into the stopped state.
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'}
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.
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.
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.
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.
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'}