Skip to end of metadata
Go to start of metadata

Overview

Since WCS build 5.2.1504 a stream can be played from server via WebRTC in a number of video qualities like HLS ABR. A browser will play a first available quality track, then playing client can switch between qualities if necessary.

Since builds WCS 5.2.1663 and SFU SDK 2.0.231 player may switch between available ABR qualities automatically when playback channel state is changing. Automatic quality switching is based on WebRTC playback statistics data.

Supported platforms and browsers


Chrome

Firefox

Safari

Chromium Edge

Windows

+

+


+
Linux++
+

Mac OS

+

+

+

+

Android

+

+


+

iOS

+ (iOS 14.4)

+ (iOS 14.4)

+


Supported publishing technologies

A streams published by all of the available ways can be played via WebRTC ABR:

  • WebRTC
  • RTMP
  • RTSP
  • MPEG-TS via UDP or SRT
  • Stream mixer

Supported codecs

Any stream will be transcoded to H264+Opus to be played as WebRTC ABR.

Implementation basics

SFU functions with Simulcast are used to implement WebRTC ABR support. A stream published video track is transcoded to a number of H264 video tracks with a different parameters, and the tracks are sent to client as SFU qualities. Audio track is transcoded to Opus and is also sent to client as SFU track. An SFU room named as stream published is created on server because room is a main SFU object.

Configuration

SFU subsystem setup

The following should be done to play a stream published on WCS using SFU Simulcast:

  • codecs used by SFU should be limited to H264 + Opus
  • H264 encoding profiles should be set
  • a bridge from WCS core engine to SFU subsystem should be enabled
codecs_exclude_sfu=alaw,ulaw,g729,speex16,g722,mpeg4-generic,telephone-event,flv,mpv,vp8,h265
profiles=42e01f,640028
wcs_sfu_bridge_enabled=true

WCS must be restarted to apply the settings.

Quality profiles setup

WebRTC ABR quality profiles are set in /usr/local/FlashphonerWebCallServer/conf/wcs_sfu_bridge_profiles.yml file. By default, the following profiles are used:

profiles:
 s :
  width : 320
  height : 240
  bitrate : 500
  gop : 60
  fps : 30
 m :
  width : 640
  height : 480
  bitrate : 800
  gop : 60
  fps : 30
 h :
  width : 960
  height : 720
  bitrate : 1300
  gop : 60
  fps : 30

The following profile parameters are supported:

  • height - picture height (mandatory)
  • width - picture width
  • bitrate - encoding bitrate in kbps
  • gop - group of frames size
  • fps - frames number per second

The gop parameter actually sets key frames encoding period. In the example above, for 30 frames per second a key frame will be formed every 2 seconds.

Quality profiles may be arbitrary named, they are used to choose a quality at client side. In the example above, the profiles may be named as 240p , 480p и 720p respectively.

WCS must be restarted to apply the quality profiles settings.

Using the same video quality profiles for HLS ABR and WebRTC ABR

Since build 5.2.1665, if video quality profiles are equal for HLS ABR and WebRTC ABR configurations, the same encoders will be used. For example, with WebRTC ABR setup

profiles:
  240p:
    height: 240
    bitrate: 500
    codec: h264
    gop: 60
    fps: 30

  480p:
    height: 480
    bitrate: 1000
    codec: h264
    gop: 60
    fps: 30

  720p:
    height: 720
    bitrate: 1500
    codec: h264
    gop: 60
    fps: 30

and HLS ABR setup

profiles:
  -240p:
    audio:
      codec: mpeg4-generic
      rate: 48000
      channels: 2
      groupId: audio
    video:
      height: 240
      bitrate: 500
      codec: h264
      gop: 60
      fps: 30
      audioGroupId: audio

  -480p:
    audio:
      codec: mpeg4-generic
      rate: 48000
      channels: 2
      groupId: audio
    video:
      width: 0
      height: 480
      bitrate: 1000
      codec: h264
      gop: 60
      fps: 30
      audioGroupId: audio

  -720p:
    audio:
      codec: mpeg4-generic
      rate: 48000
      channels: 2
      groupId: audio
    video:
      width: 0
      height: 720
      bitrate: 1500
      codec: h264
      gop: 60
      fps: 30
      audioGroupId: audio

only 3 video encoders will be created

The following video profile parameters should be equal if they are set:

  • height
  • width (if set and not equal to 0)
  • codec
  • bitrate
  • fps
  • gop
  • profile
  • level
  • codecImpl

Video quality profiles sorting

Since build 5.2.1663, video quality profiles will be sorted in the order set in /usr/local/FlashphonerWebCallServer/conf/wcs_sfu_bridge_profiles.yml file. For example, if the profiles described like this

profiles:
  240:
    height: 240
    bitrate: 500
    codec: h264
    gop: 60
    fps: 30

  480:
    height: 480
    bitrate: 1000
    codec: h264
    gop: 60
    fps: 30

  720:
    height: 720
    bitrate: 1500
    codec: h264
    gop: 60
    fps: 30

  1080:
    height: 1080
    bitrate: 3000
    codec: h264
    gop: 60
    fps: 30

a client will receive a profiles list ordered like

240, 480, 720, 1080

If there are two profiles with the same name in the setup, an undefined behavior occurs. To resolve it, server will use only the last profile with the same name.

Force transcoding of a maximum ABR quality only if there are B-frames in a source stream

To reduce a server load while video encoding, since WCS build 5.2.1840 it is possible to transcode a maximum ABR quality (which is usually the original stream resolution and bitrate) only if there are B-frames in a source stream. The feature may be enabled by the following parameter

h264_b_frames_force_transcoding=true

In this case the server will detect B-frames in a stream analizing a certain frames count (10 by default)

frame_cnt_to_determine_their_type=10

If there are B-frames in the stream, the maximum ABR quality will be transcoded and will be available for playback.

If there are no B-frames in the stream, the maximum ABR quality will not be transcoded. The original quality should be requested separately from a playing client.

Quick manual on testing

1. For test we use:

  • WCS server with WebRTC ABR settings
  • OBS to publish a stream
  • WebRTC ABR Player example https://test1.flashphoner.com:8444/client2/sfu/webrtc-abr-player/player.html to play the stream

2. Publish RTMP stream test  720p 30 fps with 2000 kbps bitrate

3. Open WebRTC ABR Player example page, set Stream name to test , and click Play . Stream playback will start

Known issues

1. Not all the qualities may be available to a client depending on channel bandwidth. In this case, unavailable quality buttons in WebRTC ABR Player will be displayed in red.

2. WebRTC ABR increases server CPU load because a number of video encoders are created per every published stream depending on quality profiles count.

3. In iOS Safari audio is muted by default in WebRTC ABR Player example, and unmute button is dispalyed on audio tag because iOS Safari requires a user action to enable sound


  • No labels