Versions Compared

Key

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

Table of Contents

Codecs supported

Video:

Audio:

  • Opus
  • AAC
  • G711 (PCMA, PCMU)
  • G722

The cases when transcoding is enabled

...

In this case stream will be transcoded to picture width and height that are requested by subscriber. If subscriber does not set picture height, it wiil be set to 120.  If If subscriber does not set picture width, it wiil will be set to 160.

Transcoder output stream audio and video synchronization

...

Picture width alignment while preserving a picture aspect ratio

Since build 5.2.1842 it is possible to set a picture width alignment when aspect ratio preserving is enabled. By default, a picture width will be rounded down:

Code Block
themeRDark
avvideo_pacedtranscoder_round_senderratio=true

...

0

For example, if 1280x720 stream is transcoded to 480p resolution, the picture resolution will be 852x480 by default. The parameter

Code Block
themeRDark
avvideo_pacedtranscoder_sender_max_buffer_size=5000

By default pacer buffer size is 5000 frames.

The statistics information received by the following query is uused to control pacer buffer usage

Code Block
languagebash
themeRDark
curl -s 'http://localhost:8081/?action=stat&format=json&groups=buffer_stats'

A certain stream watermarking

Since build 5.2.693 it is possible to add watermark to transcoded stream when creating transcoder using REST API, for example

Code Block
languagejs
themeRDark
{
 "uri": "transcoder://tcode1",
 "remoteStreamName": "test",
 "localStreamName": "testT",
 "encoder": {
  "width": 640,
  "height": 480,
  "keyFrameInterval": 30,
  "fps": 30,
  "watermark": "Test.png"
 }
}

By default, if file name only is passed, watermark picture file should be placed to /usr/local/FlashphonerWebCallServer/conf folder. The full path to the file can also be passed, for example

Code Block
languagebash
themeRDark
{
 "uri": "transcoder://tcode1",
 "remoteStreamName": "test",
 "localStreamName": "testT",
 "encoder": {
  "round_ratio=1

enables the picture width rounding up: in this case the resolution will be 854x480.

Vertical video aspect ratio calculation

Since build 5.2.1911, WCS detects a stream published orientation by picture width and height and keeps aspect ratio as follows:

1. For horizontal (landscape) video (a picture width is greater than or equal to height) the height value of transcoding profile will be applied to picture height, a picture width to transcode will be calculated by picture height. For example, a source stream with 1920x1080 (16:9) resolution will be transcoded to 640x360 resolution by profile with height: 360 .

2. For vertical (portrait) video (a picture width is less than height) the height value of transcoding profile will be applied to picture width, a picture heignht to transcode will be calculated by picture width. For example, a source stream with 1080x1920 (9:16) resolution will be transcoded to 360x640 resolution by profile with height: 360 .

Transcoder output stream audio and video synchronization

By default transcoder does not synchronize output stream audio and video, leaving sinchronization value as is. This can lead to out of audio and video sync in stream transcoded. To prevent this, the pacer buffer is added in build 5.2.543 which can be enabled with the following parameter

Code Block
themeRDark
av_paced_sender=true

Pacer buffer maximum size is set in frames by the following parameter

Code Block
themeRDark
av_paced_sender_max_buffer_size=5000

By default pacer buffer size is 5000 frames.

The statistics information received by the following query is uused to control pacer buffer usage

Code Block
languagebash
themeRDark
curl -s 'http://localhost:8081/?action=stat&format=json&groups=buffer_stats'

A certain stream watermarking

Since build 5.2.693 it is possible to add watermark to transcoded stream when creating transcoder using REST API, for example

Code Block
languagejs
themeRDark
{
 "uri": "transcoder://tcode1",
 "remoteStreamName": "test",
 "localStreamName": "testT",
 "encoder": {
  "width": 640,
  "height": 480,
  "keyFrameInterval": 30,
  "fps": 30,
  "watermark": "/opt/media/Test.png"
 }
}

Adding and changin stream watermark dynamically

Since build 5.2.1349 in is possible to dynamically add or change stream watermark without stopping the transcoder. A watermark can be added, changed or moved to another picture location according to coordinates defined using REST API query /transcoder2/set_watermark 

Code Block
languagejs
themeRDark
{
 "uri":"transcoder2://tcode1",
 "watermark":"/opt/media/logo.png",
 "x":10,
 "y":10,
 "marginTop":5,
 "marginLeft":5,
 "marginBottom":5,
 "marginRight":5
}

Where

  • watermark - watermark file name
  • x, y - top left watermark corner coordinates on the stream picture
  • marginTop, marginLeft, marginBottom, marginRignt - watermark margins from stream picture borders

If watermark coordinates are out of stream picture bounds, the watermark will be scaled to the bounds using margins.

To move watermark to another location on the stream picture, send the query with the same file name and a new coordinates. To remove watermark from the stream picture, send the query with empty watermark field

Code Block
languagejs
themeRDark
{
 "uri":"transcoder2://tcode1",
 "watermark":""
}

Multithreaded encoding

Since build 5.2.816 multithreaded strems encoding is supported using OpenH264 encoder. Encoder threads count can be set with the following parameter

Code Block
themeRDark
video_encoder_max_threads=2

By default, streams will be encoded in 2 threads.

Multi threaded encoding is enabled depending on transcoder output stream resolution. The threshold can be set with the following parameter

Code Block
themeRDark
video_encoder_second_thread_threshold=777000

The threshold value is the product of the picture width multiplication to the height. Therefore, 720p and higher resolutions wiil be encoded in multiple threads. This threshold can be lowered if necessary. For example, to encode 480p pictures in multiple threads, set the following value

Code Block
themeRDark
video_encoder_second_thread_threshold=408950

Known issues

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

СSymptoms: picture quality is not changing when using different constraints.video.quality values, for example

Code Block
themeRDark
constraints.video.quality=5

does not differ from 

Code Block
themeRDark
constraints.video.quality=20

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

...

themeRDark

...

By default, if file name only is passed, watermark picture file should be placed to /usr/local/FlashphonerWebCallServer/conf folder. The full path to the file can also be passed, for example

Code Block
languagebash
themeRDark
{
 "uri": "transcoder://tcode1",
 "remoteStreamName": "test",
 "localStreamName": "testT",
 "encoder": {
  "width": 640,
  "height": 480,
  "keyFrameInterval": 30,
  "fps": 30,
  "watermark": "/opt/media/Test.png"
 }
}

Adding and changing stream watermark dynamically

Since build 5.2.1349 in is possible to dynamically add or change stream watermark without stopping the transcoder. A watermark can be added, changed or moved to another picture location according to coordinates defined using REST API query /transcoder2/set_watermark 

Code Block
languagejs
themeRDark
{
 "uri":"transcoder2://tcode1",
 "watermark":"/opt/media/logo.png",
 "x":10,
 "y":10,
 "marginTop":5,
 "marginLeft":5,
 "marginBottom":5,
 "marginRight":5
}

Where

  • watermark - watermark file name
  • x, y - top left watermark corner coordinates on the stream picture
  • marginTop, marginLeft, marginBottom, marginRignt - watermark margins from stream picture borders

If watermark coordinates are out of stream picture bounds, the watermark will be scaled to the bounds using margins.

To move watermark to another location on the stream picture, send the query with the same file name and a new coordinates. To remove watermark from the stream picture, send the query with empty watermark field

Code Block
languagejs
themeRDark
{
 "uri":"transcoder2://tcode1",
 "watermark":""
}

Multithreaded encoding

Since build 5.2.816 multithreaded strems encoding is supported using OpenH264 encoder. Encoder threads count can be set with the following parameter

Code Block
themeRDark
video_encoder_max_threads=2

By default, streams will be encoded in 2 threads.

Multi threaded encoding is enabled depending on transcoder output stream resolution. The threshold can be set with the following parameter

Code Block
themeRDark
video_encoder_second_thread_threshold=777000

The threshold value is the product of the picture width multiplication to the height. Therefore, 720p and higher resolutions wiil be encoded in multiple threads. This threshold can be lowered if necessary. For example, to encode 480p pictures in multiple threads, set the following value

Code Block
themeRDark
video_encoder_second_thread_threshold=408950

H264 profile-level-id detection

Since build 5.2.1644 a command line tool is available to detect H264 encoder profile-level-id according to encoding parameters:

Code Block
languagebash
themeRDark
sudo bash /usr/local/FlashphonerWebCallServer/tools/h264_profile_tool.sh --config=codec,resolution,profile,level[,preset]

Where

  • codec  - encoder name: OPENH264  or FF 
  • resolution - resolution
  • profile - encoding profile
  • level  - encoding level
  • preset - encoding preset

For example, with the following encoding parameters

Code Block
languagebash
themeRDark
sudo bash /usr/local/FlashphonerWebCallServer/tools/h264_profile_tool.sh --config="OPENH264,1280x720,66,31,ultrafast"

the tool will display the following profile-level-id 

Code Block
languagebash
themeRDark
42c01f <= "OPENH264,66,31,ultrafast,1280x720"

The tool also may generate a full supported profiles list for all encoders

Code Block
languagebash
themeRDark
sudo bash /usr/local/FlashphonerWebCallServer/tools/h264_profile_tool.sh --catalog --output=catalog.csv

or for certain encoder

Code Block
languagebash
themeRDark
sudo bash /usr/local/FlashphonerWebCallServer/tools/h264_profile_tool.sh --catalog --encoders=OPENH264 --output=openH264.csv

The list is generated as CSV file in the form

Code Block
themeRDark
codec,profile,level,preset,resolution,profile-level-id

for example

Code Block
themeRDark
FF,0,0,fast,320x180,42c01e
...

If there is no encoder library in the server distribution, the tool will display the following error while requesting a profile-level-id

Code Block
themeRDark
Unable to create instance of encoder: FF

and the following error will be displayed while requesting a full supported profiles list

Code Block
themeRDark
Unsupported encoder: FF

and CSV file of zero length will be created.

Known issues

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

СSymptoms: picture quality is not changing when using different constraints.video.quality values, for example

Code Block
themeRDark
constraints.video.quality=5

does not differ from 

Code Block
themeRDark
constraints.video.quality=20

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

Code Block
themeRDark
encoder_priority=FF

2. Default watermark (black picture) will be used if watermark file is damaged or absent

Symptoms: black picture in output stream when watermark is added, there is a message in server log 

Code Block
themeRDark
Wrong watermark file format. Should be PNG.

Solution: use only correct PNG file to add watermark