Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ParameterValues availableDescription
Audio parameters
codec

opus

mpeg4-generic

speex

ulaw

Audio codec to use
bitrateDepends on quality required and bandwidth availableAudio bitrate, bps
rate

8000

11025

12000

16000

22050

24000

32000

44100

48000

Audio sample rate, kHz
channels

1

2

Audio channels number
Video parameters
codec

h264

mpv

vp8

Video codec to use
bitrateDepends on quality required and bandwidth availableVideo bitrate, kbps
widthDepends on quality required and bandwidth availablePicture width
heightDepends on quality required and bandwidth availablePicture height
codeImpl

FF

OPENH264

Video codec used, FF by default
gopDepends on quality required and bandwidth availableKey frames frequency (GOP)
fpsDepends on quality required and bandwidth availableFrames frequency per second
qualityDepends on quality required and bandwidth availableVideo quality
preset

ultrafast

superfast

veryfast

faster

fast

medium

slow

slower

veryslow

placebo

FF preset, ultrafast by default
profile

66 (Baseline)

77 (Main)

88 (Extended)

100 (High)

FF profile, 66 (Baseline) by default
levelDepends on required quality
FF level, 3.1 by default

...

The settings above should be applied to Transcoder nodes.

Transcoding profile management using REST API

The specific REST API is used to manage transcoding profiles on the fly, without server restart

REST query should be HTTP/HTTPS POST request as follows:

  • HTTP: http://test.flashphoner.com:8081/rest-api/cdn/profile/print
  • HTTPS: https://test.flashphoner.com:8444/rest-api/cdn/profile/print

Where:

  • test.flashphoner.com - WCS server address
  • 8081 - standard REST / HTTP port of WCS server
  • 8444 - standard HTTPS port
  • rest-api - URL mandatory part
  • /cdn/profile/print - REST query used

REST queries should be sent to Edge server. Any profile changes are stored in memory and applied immediately, also they are written to cdn_profiles.yml file to use after server restart.

REST queries and response states

...

REST query

...

REST query body example

...

Response body example

...

Response states

...

Description

...

/cdn/profile/add

Code Block
languagejs
themeRDark
{
"name": "-profile1",
"profile": {
        "audio": {
            "type": "audio",
            "bitrate": 0, 
            "codec": "opus", 
            "rate": 48000 
        }, 
        "video": {
            "type": "video", 
            "bitrate": 0, 
            "codec": "h264", 
            "codecImpl": "FF", 
            "fps": 30, 
            "gop": 90, 
            "height": 360, 
            "quality": 0, 
            "width": 640
        }
}
}

...

200 – OK

400 - Bad Request

409 - Conflict

500 – Internal Server Error

...

Add transcoding profile

...

Multi channels audio support

Since build 5.2.773, audio transcoding by profile with certain number of channels (1 - mono, 2 - stereo) is supported

Code Block
languageyml
themeRDark
profiles:
 -240p:
  audio:
    codec : mpeg4-generic
    rate : 48000
    channels: 1
  video:
    height : 240
    bitrate : 300
    gop : 50
    codec : h264

A channels number in a profile should be equal to channels number in original audio track for subscriber on Edge server to play stereo sound when stream with stereo sound is published, i.e.

Code Block
languageyml
themeRDark
profiles:
 -240p:
  audio:
    codec : mpeg4-generic
    rate : 48000
    channels: 2

If profile codec, samplerate and channels number are equal to original audio track parameters, the track will be passed to Edge server without transcoding

Transcoding profile management using REST API

The specific REST API is used to manage transcoding profiles on the fly, without server restart

REST query should be HTTP/HTTPS POST request as follows:

  • HTTP: http://test.flashphoner.com:8081/rest-api/cdn/profile/print
  • HTTPS: https://test.flashphoner.com:8444/rest-api/cdn/profile/print

Where:

  • test.flashphoner.com - WCS server address
  • 8081 - standard REST / HTTP port of WCS server
  • 8444 - standard HTTPS port
  • rest-api - URL mandatory part
  • /cdn/profile/print - REST query used

REST queries should be sent to Edge server. Any profile changes are stored in memory and applied immediately, also they are written to cdn_profiles.yml file to use after server restart.

REST queries and response states

videobitrate400 quality25} } }-240p{"audio":{ "bitrate":0 channels0, codecopusrate48000typeaudio}, video:{bitrate0codec"h264"codecImpl"FF"fps25gop50, "height": 240,

REST query

REST query body example

Response body example

Response states

Description

/cdn/profile/add

Code Block
languagejs
themeRDark
{
"name": "-profile1",
"profile": {
        "
audio": {
            "
type": 
"audio",

            "
bitrate": 
0, 
        

200 – OK

400 - Bad Request

404 - Not Found

500 – Internal Server Error

Change transcoding profile/cdn/profile/print
Code Block
languagejs
themeRDark
    "
codec": "opus", 

        
 
   "rate": 48000 
       
 
}, 
        
"
video": 
{
            "
type": "
video", 
            "
bitrate": 
0, 
            "
codec": "
h264", 
        
 
   
"codecImpl": "
FF"
, 

            "
fps": 
30, 
            "
gop": 
90, 
            "
height": 
360, 
            "
quality": 
0, 
            "
width": 
640
        
}
}
}





200 – OK

400 - Bad Request

409 - Conflict

500 – Internal Server Error

Add transcoding profile

/cdn/profile/modify
Code Block
languagejs
themeRDark
{
"name": "-profile1",
"profile": {
        "presetvideo": "veryfast", {
            "qualitybitrate": 0400, 
            "typequality": "video", 25
            "width": 0
        }
    }, 
    "-480p}
}
}




200 – OK

400 - Bad Request

404 - Not Found

500 – Internal Server Error

Change transcoding profile
/cdn/profile/print
Code Block
languagejs
themeRDark
    "-240p": {
        "audio": {
            "bitrate": 0, 
            "channels": 0, 
            "codec": "opus", 
            "rate": 48000, 
            "type": "audio"
        }, 
        "video": {
            "bitrate": 0, 
            "codec": "h264", 
            "codecImpl": "FF", 
            "fps": 25, 
            "gop": 50, 
            "height": 480240, 
            "preset": "veryfast", 
            "quality": 0, 
            "type": "video", 
            "width": 0
        }
    }

200 – OK

404 - Not Found

500 – Internal Server Error

Get the transcoding profiles list/cdn/profile/remove
Code Block
languagejs
themeRDark
{
"name": "-profile1"
}

200 – OK

404 - Not Found

500 – Internal Server Error

Remove transcoding profile

Parameters

{
"audio": {
"type": "audio"


"codec": "

},
"video{
type":,


"codecImpl": "FF",
30
90,
360
"quality0,
"width": 640
}

Parameter name

Description

Example

name

Profile name

-profile1

profile

Profile parameters

, 
    "-480p": {
        "audio": {
            "bitrate": 0,
 
            "channels": 0,
 
            "codec": "opus", 

            "rate": 48000,
 
            "type": 
"
audio"
        }, 
        "video"
: {
            "bitrate": 0,
 
            "codec": "h264",
 
            "codecImpl": "FF", 
            "fps": 
25,
 
            "gop": 
50, 
            "height": 
480, 

            "preset": 

cdn_group_origin_to_transcoder_relation=true

Profile parameters should contain audio or video sections.

The mandatory profile parameters are:

  • audio:
    • bitrate
    • codec
    • rate
  • video:
    • bitrate
    • codec
    • width
    • height
    • quality

If some of those parameters are omitted in profile creation query, they will be added to profile with 0 value for digital parameters and "" for string parameters, in this case default values will be applied.

The remaining parameters are optional and may be omitted in the profile:

  • video:
    • codecImpl
    • fps
    • gop
    • level
    • preset
    • profile

When modifying a profile, only parameters passed in REST query will be changed. To drop some of mandatory parameters to default value, or to remove optional parameter from profile, -1 should be passed, fro example:

Code Block
languagejs
themeRDark
{
"name": "-profile1",
"profile": {
        "video": {
            "bitrate": -1, 
            "codecImpl": -1
        }
}
}

Used profiles modification

If stream is played by the profile, this profile can be modified after stream playback finishes and publishing agent stops, i.e. near 1 minute after last stream subscriber disconnects.

When stream is transcoded on Edge server

Stream will be transcoded on Edge in the following cases:

1. If there is no audio codec or sample rate from profile in subscriber's SDP, audio track will be transcoded to one of formats supported by subscriber.

2. If constraints are set for the subscriber: e.g., if video height or bitrate are specified. Therefore, when transcoding by profile, desired constraints should be specified in the profile and not set for subscribers.

Profile applied for a subscriber should correspond to the technology used by the subscriber for playing the stream. For example, for a subscriber using WSPlayer, apply profile with codecs ulaw and mpv, and for RTMP - mpeg4-generic and h264.

Picture aspect ratio preserving while stream transcoding by profile

If picture aspect ratio preserving is enabled for all CDN nodes (by default), then stream aspect ratio as published to Origin node will be preserved while transcoding the stream on Transcoder node. For example, if the following profile (16:9) is applied  to 640x480 (4:3) stream

Code Block
languageyml
themeRDark
 profile1:
  audio:
    codec : opus
    rate : 48000
  video:
    width : 320
    height : 180
    gop : 90
    fps : 30
    codec : h264

the stream will be transcoded to 320x240 (4:3).

In this case, picture width may be omitted in transcoding profile, because width will be chosen according to picture aspect ratio. For example, the following profile is allowed

...

languageyml
themeRDark

...

"veryfast", 
            "quality": 0, 
            "type": "video", 
            "width": 0
        }
    }

200 – OK

404 - Not Found

500 – Internal Server Error

Get the transcoding profiles list
/cdn/profile/remove
Code Block
languagejs
themeRDark
{
"name": "-profile1"
}




200 – OK

404 - Not Found

500 – Internal Server Error

Remove transcoding profile

Parameters

Parameter name

Description

Example

name

Profile name

-profile1

profile

Profile parameters

{
"audio": {
"type": "audio"
"bitrate": 0,
"channels": 0,
"codec": "opus",
"rate": 48000,
},
"video": {
"type": "video",
"bitrate": 0,
"codec": "h264",
"codecImpl": "FF",
"fps": 30,
"gop": 90,
"height": 360,
"quality": 0,
"width": 640
}

cdn_group_origin_to_transcoder_relation=true

Profile parameters should contain audio or video sections.

The mandatory profile parameters are:

  • audio:
    • bitrate
    • codec
    • rate
  • video:
    • bitrate
    • codec
    • width
    • height
    • quality

If some of those parameters are omitted in profile creation query, they will be added to profile with 0 value for digital parameters and "" for string parameters, in this case default values will be applied.

The remaining parameters are optional and may be omitted in the profile:

  • video:
    • codecImpl
    • fps
    • gop
    • level
    • preset
    • profile

When modifying a profile, only parameters passed in REST query will be changed. To drop some of mandatory parameters to default value, or to remove optional parameter from profile, -1 should be passed, fro example:

Code Block
languagejs
themeRDark
{
"name": "-profile1",
"profile": {
        "video": {
            "bitrate": -1, 
            "codecImpl": -1
        }
}
}

Used profiles modification

If stream is played by the profile, this profile can be modified after stream playback finishes and publishing agent stops, i.e. near 1 minute after last stream subscriber disconnects.

When stream is transcoded on Edge server

Stream will be transcoded on Edge in the following cases:

1. If there is no audio codec or sample rate from profile in subscriber's SDP, audio track will be transcoded to one of formats supported by subscriber.

2. If constraints are set for the subscriber: e.g., if video height or bitrate are specified. Therefore, when transcoding by profile, desired constraints should be specified in the profile and not set for subscribers.

Profile applied for a subscriber should correspond to the technology used by the subscriber for playing the stream. For example, for a subscriber using WSPlayer, apply profile with codecs ulaw and mpv, and for RTMP - mpeg4-generic and h264.

Picture aspect ratio preserving while stream transcoding by profile

If picture aspect ratio preserving is enabled for all CDN nodes (by default), then stream aspect ratio as published to Origin node will be preserved while transcoding the stream on Transcoder node. For example, if the following profile (16:9) is applied  to 640x480 (4:3) stream

Code Block
languageyml
themeRDark
 profile1:
  audio:
    codec : opus
    rate : 48000
  video:
    width : 320
    height : 180

...


    gop : 90
    fps : 30
    codec : h264

the stream will be transcoded to 320x240 (4:3).

In this case, picture width may be omitted in transcoding profile, because width will be chosen according to picture aspect ratio. For example, the following profile is allowed

Code Block
languageyml
themeRDark
 profile3:
  audio:
    codec : opus
    rate : 48000
  video:
    height : 180

Transcoder node tuning to work under high load

The server CPU load increases while a large number of streams are transcoded. If the server CPU does not manage to process all the streams frames, frame encoding queues take a much of server RAM (not JVM heap!). As a result, memory leak may occur and, therefore, server can stop working depending on memory allocation libraries used by server operating system.

...

Code Block
languageyml
themeRDark
  -240p-HLS:
    audio:
      codec: mpeg4-generic
    video:
      height: 240
      bitrate: 300
      codec: h264
  -240p-WebRTC:
    audio:
      codec: opus
    video:
      height: 240
      bitrate: 300
      codec: h264

...

 300
      codec: h264

In this case, if the stream is transcoded at the same Transcoder node by those two profiles, only one video encoder and two audio encoders will be used.

Transcoding to higher resolutions prevention

Since build 5.2.607, stream transcoding to higher resolutions can be escaped. The feature can be enabled with the following parameter

Code Block
themeRDark
cdn_strict_transcoding_boundaries=true

In this case, if a stream is published to Origin with resolution 640x480, and Edge server tries to request playback by 720p profile, Edge will receive an original stream directly from Origin without transcoding. Resolutions are compared by height.

Stream requesting by higher resolution profiles can be strictly forbidden with the following parameter

Code Block
themeRDark
cdn_strict_transcoding_throws_exception=true

When, if a stream is published to Origin with resolution 640x480, and Edge server tries to request playback by 720p profile, Edge can not choose stream playback route and will return error to a client.

These parameters should be set on Edge server.

Known limits

1. If stream transcoding to higher resolutions is disabled, a stream height must be set for every profile.

Choosing a route for stream playback

...

This parameter should be set on Transcoder nodes.

Degraded streams percent limiting

Since build 5.2.594, a degrading streams percent can be limited. For example, to stop new streams transcoding when 10% of streams is degraded, the following parameter should be set

...

Parameter name

Description

Example

globalState

Node state: ACTIVE or PASSIVE

ACTIVE

id

Node address

192.168.1.64
processingState, state

If this node participates in stream playback route elections:

NEW_STREAMS_ALLOWED - participates

CONNECTION_ALLOWED - participatesallows to pull already decoded streams by new profiles

GROUP_CONNECTION_ALLOWED - not participates

NEW_STREAMS_ALLOWED
roleNode role: ORIGIN, TRANSCODER or EDGE
ORIGIN

...

Current CDN node state is defined as follows in priority order:
1. If there is a value enforced by /cdn/cdn/enforce_state REST query, state will be set to this value.
2. If CPU load threshold is reached, state will be set to GROUP_CONNECTIONS_ALLOWED.
3. If video encoders threshold is reached, state will be set to GROUP_CONNECTIONS_ALLOWED.
4. If no limits are reached, state will be set to NEW_STREAMS_ALLOWED.CDN node broadcasts its state to another nodes periodically, using the interval set in milliseconds with the folowing parameterenforce_state REST query, state will be set to this value.
2. If CPU load threshold is reached, state will be set to GROUP_CONNECTIONS_ALLOWED.
3. If video encoders threshold is reached, state will be set to GROUP_CONNECTIONS_ALLOWED.
4. If no limits are reached, state will be set to NEW_STREAMS_ALLOWED.

CDN node broadcasts its state to another nodes periodically, using the interval set in milliseconds with the folowing parameter

Code Block
themeRDark
cdn_nodes_state_refresh_interval=60000

By default, this interval is 60 seconds. It is recommended to reduce this parameter to 1 second for Transcoder nodes to distribute the streams to another nodes.

Transcoder threshold reached state setup

Since build 5.2.640 Transcoder node threshold reached state can be set with the following parameter, GROUP_CONNECTIONS_ALLOWED by default

Code Block
themeRDark
cdn_transcoder_threshold_state=GROUP_CONNECTIONS_ALLOWED

To prevent stream spreading over CDN, Transcoder node can be switched to CONNECTIONS_ALLOWED state if necessary

Code Block
themeRDark
cdn_transcoder_nodesthreshold_state_refresh_interval=60000

...

=CONNECTIONS_ALLOWED

In this state, Transcoder node allows to pull streams which are already decoded on, including new encoding profiles. For example, if some Transcoder node decodes test stream by 360p profile, and som of Edge servers requests test240p stream, playback route will be built via the same Transcoder node.

This parameter should be set on Transcoder nodes.

CDN nodes authentication

...

In these cases transcoding works according to codecs and SDP setup as defined for CDN 2.0.

Known limits

1. It is strongly not recommended to publish streams with same name to two Origin servers in the same CDN.

...

Code Block
languageyml
themeRDark
profiles:
 -240p:
  audio:
    codec : opus
    rate : 48000
  video:
    height : 240
    bitrate : 400
    gop : 50
    fps : 25
    codec : h264
    codecImpl : OPENH264

2. Encoding quality settings cannot be applied if OpenH264 is used

Symptoms: picture quality is not changing when using different quality values in transcoding profile

Solution: do not use OpenH264 encoder because it does not support CRF

Code Block
languageyml
themeRDark
profiles:
 -240p:
  audio:
    ...
  video:
    ...
    quality: 10
    codecImpl : FF