Flussonic Media Server documentation

Transcoder

Transcoding is necessary if you want to:

  • create a multi-bitrate stream
  • change parameters of video — the codec and the bitrate of the stream, the size of the image
  • overlay a logo on top of a video stream.

Flussonic Media Server has a built-in transcoder. It supports transcoding by using a GPU or the CPU.

Content:

The Flussonic transcoder module supports the RTMP, RTSP, and MPEG2-TS protocols (over HTTP and UDP).

The HLS protocol is partially supported — some sources may fail to be transcoded. It is recommended to test each HLS source manually to find out whether it works after transcoding.

For hardware-accelerated transcoding, Flussonic can use Intel and Nvidia solutions. When transcoding with Nvidia NVENC, streams with a 10-bit color depth are supported.

Important!

Transcoding is an extremely computationally-intensive process, and it includes the following steps:

  1. Decoding of the source stream into raw video data.
  2. Processing and encoding of the raw stream according to the specified parameters.

Depending on the configuration, a single server can process from 5 to 20 channels.

Installing the transcoder Anchor Anchor x2

If you use an NVENC-capable Nvidia GPU to perform transcoding in Flussonic 19.07, you do not need to install any extra packages to enable transcoding.

If you use the CPU to perform transcoding, you will need to install the package flussonic-transcoder:

apt-get -y install flussonic-transcoder

This package can be found in the same repository as the flussonic package.

Setting up transcoding options in the configuration file Anchor Anchor x2

Transcoding options can be specified in stream settings in the Flussonic configuration file. Alternatively, the web UI can be used.

This section describes how to configure transcoding options by editing the /etc/flussonic/flussonic.conf configuration file.

Important! When changing transcoder options, you must specify them in the correct order. The video options go first, then the global options, and then the audio options. Below, you will find several common examples detailing the use of the transcoder options.

Transcoder options

  1. Enable the transcoder for the incoming stream as follows:

    stream ort {
      url udp://239.0.0.1:5000;
      transcoder vb=2048k size=1280x720 preset=fast ab=128k;
    }
    
  2. Apply the new configuration with the command:

    /etc/init.d/flussonic reload
    

Setting up transcoding options in the web interface Anchor Anchor x2

To enable and set up the transcoder via the Flussonic web interface:

  1. In the Media menu, select the channel you want to transcode.
  2. Go to the Transcoder tab. You will be able to set transcoder settings only after you add an output video track (see the next step).
  3. Click the button Add video track and (optionally) select a bitrate and height:

    transcoding options After you have added a video track, you'll be able to edit its settings.

  4. If your server has transcoding hardware installed, enable hardware transcoding:

    transcoding options

    • Hardware acceleration — enables hardware transcoding. Hardware transcoding allows for significantly more streams to be transcoded on a single server.
    • Deinterlace mode (off|on) — activates deinterlacing. Deinterlacing is necessary for comfortable viewing of legacy TV video on desktop computers and mobile devices. When transcoding with an Nvidia NVENC-capable device, you can select modes bob|adaptive|weave.
    • Device ID — specifies the number of the NVENC graphics card.
    • Seamless source changeprevents blinking when a stream source is changed.
  5. To keep the input stream's video characteristics, select the check box Copy from origin:

    transcoding options

  6. If you want to alter the parameters of the input stream, use the form on the screen. Below is a description of the options.

    If the option you would like to change is missing on the screen, you can use the text representation of the settings to edit the option manually. This is described further down on this page.

Video options:

  • Video bitrate — specifies the bitrate of the video track.
  • Video width — the picture width in pixels.
  • Video height — the picture height in pixels.
  • Video codecs (H.264|H.265|MP2V) — sets the video codec. The default value is H.264.
  • Preset — affects video quality and download speed. Read more about presets in Preset on this page.

To get the same output video characteristics as in the input stream, select Copy from origin.

Advanced video options:

  • Profile (baseline|main|high) — limits the output to a specific H.264 profile.
  • Level — used for compatibility with old devices.
  • Frames per second — frame rate.
  • Reference frames — used in inter-frame compression to refer to frames that follow. For better quality, use more reference frames.
  • B-frames — the values 0|1|2|3 correspond to these sequences of frames: IP|IBP|IBBP|IBBBP.
  • Frames in GOP — sets the number of frames in a GOP. The encoder will create all GOPs of an exactly identical size — as specified in this option.
  • Disable CGOP — allows an open GOP, meaning that the transcoder will divide an output stream into GOPs with slightly different number of frames, but close to the number specified in Frames in GOP. This option applies only to encoding on CPU and it might help to reduce traffic a little bit.

Logo options:

If you would like to burn a logo into your video stream, you should use specify the path to the logo file (resized with respect to the output video) in Track alogo path, and then select where the logo will appear on the video. Learn more about alogo in options

transcoding options

Audio settings:

  • Audio bitrate — sets the audio bitrate.
  • Sample rate (bypass|0|8000|16000|32000|44100|48000)
  • Codec (aac|opus|mp2a) — audio codec (the AAC codec is used by default).
  • Channels — sets the number of audio channels in an output stream.

To get the same audio characteristics as in the input stream, select Copy from origin.

transcoding options

Other settings:

  • Speed up the transcoder by running it as part of Flussonic (use with caution) (19.06). By default, the transcoder runs in a separate process from Flussonic. This is the more reliable option. If you select the option Speed up the transcoder by running it as part of Flussonic (or specify external=false in the configuration file), the transcoder will run in the same process as Flussonic Media Server. This mode speeds up encoding, especially when encoding audio or when using an Nvidia device. However, a transcoder error may cause Flussonic to crash.

When encoding with the CPU:

  • Decoder threads — the number of threads when decoding a stream. This option appears when using the CPU to transcode. Use this option only after you consult with our technical support team.

When encoding with Nvidia NVENC hardware:

You can crop the transcoded stream:

  • Crop-X and Crop-Y — the coordinates of the upper left corner of the output video image, as compared to the input image (That is, (0,0) is the upper left corner of the input video image).
  • Crop-Width — the width of the output image.
  • Crop-Height — the height of the output image.

transcoding options

When encoding with Nvidia NVENC, you can remove duplicate frames:

  • Drop second (field) — removes duplicate frames that were produced after deinterlacing, prevent increased bitrate. Is off by default.

Editing the text representation of the settings

If you cannot set some of the transcoder options via the UI (for example, when an option is missing), then you can manually edit the text representation of the options. To do so, click Switch to transcoder string. The text representation of the settings is saved in the Flussonic configuration file.

Important. The text representation is not a one-to-one translation of the options in the Web UI. Use the text representation only if the UI fields do not provide the options or values that you need to edit.

transcoding options

Saving or discarding your settings

To save the new values, click Save.

To delete all specified settings and turn off the transcoder for this stream, click Disable transcoder.

Examples of stream transcoding parameters Anchor Anchor x2

The following examples show the correct order of transcoding options. Different kinds of options are shown in different colors:

  • blue – required parameters of video encoding
  • yellow – required parameters of audio encoding
  • white – optional parameters.

Configuring a single stream:

Transcoder parameters

vb=2048k preset=fast ab=128k

Configuring multi-bitrate streams:

Transcoder new

Example:

vb=2048k preset=fast vb=700k size=720x576 preset=fast vb=300k size=320x240 preset=fast ab=128k

Transcoder options

Example:

vb=copy vb=1600k size=1280x720 preset=fast vb=400k size=640x480 preset=fast ab=copy

Options Anchor Anchor x2

Video options:

vb

vb (video bitrate) — specifies the video bitrate of the track. It is specified as a numerical value (1000k, 1500k, 2000k, etc). The value must always end with k. Each vb option creates a new video track in the output stream.

Example:

vb=2048k ab=128k

The option vb=copy saves the parameters of the original stream, that is, it is simply copied to the outgoing stream.

preset

preset — the same as the encoder preset in ffmpeg. Affects the quality and download speed. This option should be specified separately for each video stream. The default value is medium.

Example:

vb=2048k preset=fast ab=128k

Read more about presets below.

size

size — video size. This option should be specified separately for each video stream.

Example:

vb=2048k size=1280x720 ab=128k

logo

logo — allows you to overlay a logo. The transcoder adds the logo before the video was resized with the size option.

Example:

vb=2048k size=1280x720 logo=/path/to/file.png@10:10 ab=128k;

Learn more about the logo overlay settings below.

alogo

alogo — allows you to overlay a logo. The transcoder adds the logo after the video was resized with the size option. This prevents the logo picture from stretching that might occur when the logo option is used. You will need to prepare a separate file with a logo for each size of resulting video.

Example:

vb=2048k size=1280x720 alogo=/path/to/file.png@10:10 ab=128k;

Learn more about the logo overlay settings below.

vcodec

vcodec — allows you to set the video codec. The default value is H.264. Flussonic Media Server allows you to encode in H.265 (HEVC) or MP2V (MPEG -2 Video File). Specify this setting separately for each video stream.

It is not possible to use the MP2V when hardware transcoding.

Example:

vb=2014k vcodec=mp2v ab=128k

fps

fps — frame rate. Specified separately for each video stream.

Example:

vb=2048k fps=25 ab=128k

deinterlace

deinterlace — activates deinterlacing. Deinterlacing is necessary for comfortable viewing of legacy TV video on PC / mobile devices. It is specified once and acts immediately on all video streams.

Example:

vb=2000k deinterlace=1 ab=128k

refs

refs — the number of reference frames. This option should be specified separately for each video stream.

Example:

vb=2000k refs=6 ab=128k

bframes

bframes — specifies the number of B-frames. When set to 0, this option disables b-frames. This may be necessary, for example, when broadcasting to RTSP. Specified separately for each video stream.

Example:

vb=2000k bframes=0 ab=128k

hw

hw — enables hardware transcoding. This option should be specified separately for each video stream.

Example:

vb=2048k hw=nvenc ab=128k

crop

crop — crops video. Available only when hardware transcoding using NVENC: hw=nvenc. This option should be specified separately for each video stream.

Usage: crop = x: y: width: height:

  • x:y — the coordinates of the upper-left corner of the output video within the input video.
  • width — the width of the output video.
  • height — the height of the output video.

Example:

vb=2048k hw=nvenc crop=0:0:100:100 ab=128k

aspect

aspect — modifies video aspect ratio. This option should be specified separately for each video stream.

Important! Aspect ratio modification is not supported with hardware transcoding with Intel QuickSync (the hw=qsv option).

Example:

vb=2048k hw=nvenc aspect=12:5 ab=128k

force_original_aspect_ratio

force_original_aspect_ratio=true — keeps the original aspect ratio by adding black bars. (Letterboxing and pillarboxing.) This option is useful when you want to keep output resolution while switching between sources with different parameters.

Example:

vb=2048k size=1280x720 force_original_aspect_ratio=true

g

g=150 — sets the number of frames in a GOP. The encoder will create all GOPs of an exactly identical size — as specified in this option.

Example:

vb=2048k fps=25 size=1280x720 g=150

If you use encoding on CPU, you can use the disable_cgop option in addition to this option. It allows the transcoder to vary the GOP size slightly.

disable_cgop

disable_cgop=1 — allows an open GOP, meaning that the transcoder will divide an output stream into GOPs with slightly different number of frames, but close to the number specified in g. This option applies only to encoding on CPU (it is not available on hardware transcoders) and it might help reduce traffic a little bit.

Example:

vb=2048k fps=25 size=1280x720 g=150 disable_cgop=1

Audio options:

ab

ab — sets the audio bitrate. This option should be specified only once, even if there are several audio tracks. The value must always end with k.

Example:

vb=2048k ab=128k

acodec

acodec — sets an audio codec. Accepts the following values: ac3, mp2a. By default all audio tracks are encoded with AAC.

Example:

vb=2014k vcodec=mp2v ab=128k acodec=mp2a

ar

ar — sample rate.

Example:

vb=2014k ab=128k ar=44100

ac

ac — the number of audio channels.

Example:

vb=2014k ab=128k ac=1

Other options

immutable=true

immutable=true — prevents flashing that can occur when a stream's source was changed, especially if the size of the picture in a new source is different than in the previous source. Details

Example:

transcoder vb=3000k size=1280x720 ab=copy immutable=true

Hardware transcoding Anchor Anchor x2

You can significantly increase the number of transcoded streams that the server can support by using a hardware transcoder.

Flussonic Media Server supports the Nvidia NVENC and Intel Quick Sync transcoding technologies.

Read more about hardware transcoding in Hardware Transcoding with Nvidia NVENC and Intel Quick Sync Video.

Adding a logo Anchor Anchor x2

Flussonic Media Server can add a logo to your video:

Transcoder

Example:

vb=2048k preset=fast logo=/path/to/file.png@10:10 ab=128k

10:10 are the coordinates of the top left corner of the screen.

To place the logo in another part of the screen a slightly more complex formula should be written.

To place the logo in the center:

vb=2048k preset=fast logo=/path/to/file.png@(main_w-overlay_w-10)/2:(main_h-overlay_h-10)/2 ab=128k

To place the logo in the bottom left corner:

vb=2048k preset=fast logo=/path/to/file.png@10:(main_h-overlay_h-10) ab=128k

To place logo in the top right corner:

vb=2048k preset=fast logo=/path/to/file.png@(main_w-overlay_w-10):10 ab=128k

To place the logo in the bottom right corner:

vb=2048k preset=fast logo=/path/to/file.png@(main_w-overlay_w-10):(main_h-overlay_h-10) ab=128k

Important! Flussonic Media Server supports adding a logo only when using the CPU and NVENC encoders.

The preset option Anchor Anchor x2

Preset is a collection of options that will provide a certain encoding speed/compression ratio. A slower preset will provide better compression (compression is quality per file size).

This means that, for example, if you target a certain file size or constant bitrate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.

When transcoding using the CPU, the following presets are supported:

ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. The default value is medium. The value placebo is not very helpful, do not use it.

When transcoding using an NVENC-capable Nvidia GPU, the list of presets is as follows:

default, slow, medium, fast, hp, hq, bd, ll, llhq, llhp, lossless, losslesshp.

When transcoding using Intel QuickSync, the following values are supported:

veryfast, faster, fast, medium, slow, slower, veryslow.

Smooth source switching Anchor Anchor x2

The immutable=true option improves transcoded output streams. It prevents flashing that might sometimes occur when a stream's source has been changed, especially if the size of the picture in the new source differs. For example, when an ad of a different width and height is inserted into a stream, or when transcoding a server-side playlist consisting of files and streams of various resolutions.

With this option, the transcoder seamlessly switches to another source format without dropping any frames. This is achieved by keeping the initial size of video in the resulting stream. All sources will be transcoded to be the same size - this is the size specified in the option size. If the output size was not specified, the transcoder will transcode to the size of the source that goes first in the input stream.

Example:

stream STREAM_NAME {
  udp://239.0.0.1:5000;
  transcoder vb=3000k size=320x200 ab=copy hw=nvenc immutable=true;
}