A utility module for outputting KMP tracks.
Used by: nginx-rtmp-kmp-module, nginx-mpegts-kmp-module, nginx-kmp-cc-module.
Dependencies: nginx-common.
- Support for dynamic destinations, via the
publish
HTTP request - Notification on input end / upstream error (
unpublish
HTTP request) - Support for publishing a single track to multiple upstreams (replication)
- Reconnect on upstream error, via the
republish
HTTP request - Configurable resume offset - in case of
republish
, can start sending frames from one of the following offsets -- The frame after the last frame that was explicitly acked
- The frame after the last frame was sent successfully (can be used with upstreams that do not support sending KMP acks)
- Memory usage enforcement
- Protection against upstreams that do not return acks in a timely manner - free buffers when the memory usage percent exceeds a configured value
- Management API
{
"event_type": "publish",
"input_id": "rtmp://testserver:1935/live?arg=value/streamname_1/video",
"input_type": "rtmp",
"rtmp": {
"app": "live",
"flashver": "FMLE/3.0 (compatible; FMSc/1.0)",
"swf_url": "rtmp://testserver:1935/live?arg=value",
"tc_url": "rtmp://testserver:1935/live?arg=value",
"page_url": "",
"addr": "5.6.7.8",
"connection": 983,
"name": "streamname_1",
"type": "live",
"args": "videoKeyframeFrequency=5&totalDatarate=200",
},
"media_info": {
"media_type": "video",
"bitrate": 82000,
"codec_id": 7,
"extra_data": "0164000bffe100196764000bacd942847e5c0440000003004000000783c50a658001000468efbcb0",
"width": 160,
"height": 120,
"frame_rate": 15.00
}
}
Note: the exact structure may change depending on which module uses nginx-kmp-out-module.
For example, when used with nginx-mpegts-kmp-module, the rtmp
block is replaced with an mpegts
block, and contains different fields.
{
"code": "ok",
"channel_id": "somechannel",
"track_id": "sometrack",
"upstreams": [{
"url": "kmp://127.0.0.1:6543"
}]
}
code
- required, string, the status code of the publish request, if set to a value other thanok
, the publish request is retried.message
- optional, string, the error message, printed to log whencode
is not set took
.channel_id
- required, string, the channel id sent on the KMP connect packettrack_id
- required, string, the track id sent on the KMP connect packetupstreams
- required, array of objects, each object can contain the following fields:url
- required, string, must include ip address and port (hostname is not supported), can optionally be prefixed withkmp://
id
- optional, string, used for identifying the upstream inrepublish
requests and in the management APIrequired
- optional, boolean, when set totrue
, an error in the upstream frees the output track, and the input connection associated with it. When set tofalse
, an error in the upstream is ignored, unless the upstream is the last upstream on the output track. The default value istrue
.resume_from
- optional, string, sets the offset from which the module starts sending frames, if the upstream connection is re-established. The following values are defined:last_acked
- the frame after the last frame that was explicitly acked (this is the default)last_sent
- the frame after the last frame that was successfully sentlast_written
- the frame after the last frame that was written to the output buffer
connect_data
- optional, string, base64 encoded, sent as the data of the KMP connect packet
{
"event_type": "unpublish",
"input_id": "rtmp://testserver:1935/live?arg=value/streamname_1/video"
"reason": "rtmp_close"
}
The reason
field in the request can have the following values:
alloc_failed
- memory limit reached / out of memoryappend_failed
- failed to append data to an upstream (out of memory)create_publish_failed
- failed to create publish request (out of memory)create_upstream_failed
- failed to create upstream object (invalid url or out of memory)parse_publish_failed
- got invalid response to 'publish' event (error http status, unknown content type etc.)upstream_error
- error on a KMP upstream connection
{
"event_type": "republish",
"id": "upstream_id",
"input_id": "rtmp://testserver:1935/live?arg=value/streamname_1/video"
"channel_id": "somechannel",
"track_id": "sometrack"
"input_type": "rtmp",
"rtmp": {
"app": "live",
"flashver": "FMLE/3.0 (compatible; FMSc/1.0)",
"swf_url": "",
"tc_url": "rtmp://testserver:1935/live?arg=value",
"page_url": "",
"addr": "5.6.7.8",
"connection": 983,
"name": "streamname_1",
"type": "live",
"args": "videoKeyframeFrequency=5&totalDatarate=200",
},
"media_info": {
"media_type": "video",
"bitrate": 82000,
"codec_id": 7,
"extra_data": "0164000bffe100196764000bacd942847e5c0440000003004000000783c50a658001000468efbcb0",
"width": 160,
"height": 120,
"frame_rate": 15.00
}
}
{
"code": "ok",
"url": "kmp://127.0.0.1:6543"
}
code
- required, string, the status code of the republish request, if set to a value other thanok
, the republish request is retried.message
- optional, string, the error message, printed to log whencode
is not set took
.url
- required, string, must include ip address and port (hostname is not supported), can optionally be prefixed withkmp://
connect_data
- optional, string, base64 encoded, sent as the data of the KMP connect packet
- syntax:
kmp_out_api [write=on];
- default:
none
- context:
location
Enables the API interface of this module in the surrounding location block. Access to this location should be limited.
The optional write
parameter determines whether the API is read-only or read-write. By default, the API is read-only.
The sections below list the possible fields in each type of API object.
version
- string, nginx-kmp-out-module versionnginx_version
- string, nginx versioncompiler
- string, the compiler used to build nginx-kmp-out-modulebuilt
- string, the time nginx-kmp-out-module was builtpid
- integer, the nginx process iduptime
- integer, the time since the nginx worker was started, in secondstracks
- object, the keys hold the kmp-out track id, while the values are Track Objects
kmp_out_id
- string, the kmp-out track id. This field is omitted when the track is returned as part of thetracks
object, since the kmp-out ids are already returned as the keysinput_id
- string, identifies the input that is feeding the output track. Different "schemes" are used by different input modules - rtmp-kmp usesrtmp://
, mpegts-kmp usesmpegts://
etc.channel_id
- string, the channel id that is sent in the KMPconnect
packettrack_id
- string, the track id that is sent in the KMPconnect
packetmem_left
- integer, number of memory bytes left out of themem_limit
quotamem_limit
- integer, maximum number of memory bytes the output track is allowed to consumelast_timestamp
- integer, the timestamp of the last frame that was written, uses the units of the input (rtmp - milliseconds, mpegts - 90kHz)last_created
- integer, the KMPcreated
value of the last frame that was written to the tracksent_frames
- integer, the number of frames that were written to the output tracksent_key_frames
- integer, the number of keyframes that were written to the output trackwritten
- integer, the number of bytes that were written to the output trackbitrate
- integer, the average bitrate of the frames that were written in the last 10 seconds, in bits per secondframe_rate
- float, the average frame rate of the frames that were written in the last 10 seconds, in frames per secondmedia_info
- object, the latest media info that was set on the track, see Media Info Object for more detailsupstreams
- array of objects, the upstreams to which this track is currently publishing, each element is an Upstream Object
id
- string, the id of the upstreamremote_addr
- string, the ip + port of the remote peerlocal_addr
- string, the local ip + port of the connectionconnection
- integer, the nginx connection identifier, unique per nginx worker processrequired
- boolean, therequired
setting that was configured when the upstream was createdresume_from
- string, theresume_from
setting that was configured when the upstream was createdsent_bytes
- integer, the number of bytes that were sent since the connection was established (gets reset if the connection is dropped)position
- integer, the position of the upstream in the send queue of the track. Can be used, for example, to compare different upstreams on the same track, in order to detect upstreams that are laggingacked_frames
- integer, the total number of frames that were acked, either explicitly or implicitlyacked_bytes
- integer, the total size of KMP packets that were ackedauto_acked_frames
- integer, the total number of frames that were implicitly acked, either becauseresume_from
is not set tolast_acked
, or because memory usage became too high
media_type
- string, the media type of the track -video
/audio
/subtitle
bitrate
- integer, the bitrate in bits per second, as reported in the KMP Media info packetcodec_id
- integer, the KMP codec identifier, see the KMP_CODEC_XXX constants in ngx_live_kmp.hextra_data
- hex string, the private / extra data of the codec
width
- integer, the video width in pixelsheight
- integer, the video height in pixelsframe_rate
- float, the video frame rate in frames per secondcea_captions
- boolean, returnstrue
when EIA-608 / CTA-708 captions were detected in the video stream
channels
- integer, the number of audio channelschannel_layout
- hex string, a bit mask of the audio channels, see the KMP_CH_XXX constants in ngx_live_kmp.hbits_per_sample
- integer, the number of bits in each audio samplesample_rate
- integer, the sampling rate of the audio in Hz
Get the full status JSON.
Possible status codes:
- 200 - Success, returns a JSON object
Get the status of the active output tracks.
Possible status codes:
- 200 - Success, returns a JSON object
Get the ids of the active output tracks.
Possible status codes:
- 200 - Success, returns a JSON array of strings
Get the status of the specified output track.
Possible status codes:
- 200 - Success, returns a JSON object
- 404 - Track not found
Get the status of the upstreams of the specified output track.
Possible status codes:
- 200 - Success, returns a JSON array of objects
- 404 - Track not found
Get the ids of the upstreams of the specified output track.
Possible status codes:
- 200 - Success, returns a JSON array of strings
- 404 - Track not found
Add an upstream to the specified output track.
The request body must be a JSON object, with the following fields:
url
- required, string, must include ip address and port (hostname is not supported), can optionally be prefixed withkmp://
id
- optional, string, used for identifying the upstream inrepublish
requests and in the APIsrc_id
- optional, string, if supplied, must contain the id of an existing upstream on the track to copy fromrequired
- optional, boolean, when set totrue
, an error in the upstream frees the output track, and the input connection associated with it. When set tofalse
, an error in the upstream is ignored, unless the upstream is the last upstream on the output track. The default value istrue
.resume_from
- optional, string, sets the offset from which the module starts sending frames, if the upstream connection is re-established. The following values are defined:last_acked
- the frame after the last frame that was explicitly acked (this is the default)last_sent
- the frame after the last frame that was successfully sentlast_written
- the frame after the last frame that was written to the output buffer
connect_data
- optional, string, base64 encoded, sent as the data of the KMP connect packet
Possible status codes:
- 201 - Success, upstream was created
- 404 - Track not found / track has no upstreams / source upstream not found
- 415 - Request body is not a valid JSON object / missing
url
property / invalidurl
Remove the specified upstream from the specified track.
Possible status codes:
- 204 - Success, upstream was removed
- 404 - Track not found / upstream not found