Flussonic Media Server documentation

Transcoder

Transcoding is necessary if you want to:

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

Flussonic Media Server has a built-in transcoder.

Content:

The following protocols are supported: RTMP, RTSP, MPEG-TS (over HTTP and UDP).

The HLS protocol is partially supported — some sources may fail to be transcoded. Please test manually for each individual HLS source whether this source is working after transcoding.

Important!

Transcoding is an extremely resource-intensive CPU-based process and it includes the following steps:

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

Depending on the configuration, the number of channels per server may vary between 5 and 20.

Installing the transcoder Anchor Anchor x2

Flussonic 19.04 or lower

Use the following command to install the transcoder package:

apt-get -y install flussonic-ffmpeg

Flussonic 19.05

If you use a GPU Nvidia NVENC to perform transcoding, no extra packages are needed.

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

apt-get -y install flussonic-transcoder

This package is installed from the same repository as the flussonic package.

Setting up transcoding options in the configuration file Anchor Anchor x2

You can specify transcoding options in stream settings in the Flussonic configuration file. Alternatively, you can use the web UI.

This section describes how to set transcoder parameters as a text string in the configuration file /etc/flussonic/flussonic.conf.

Important! To activate the transcoder it is important to follow the correct order of options. First, you must specify all video parameters, then global options, and then audio options. In the examples, we'll show details of how to specify the options manually in the file.

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 Process tab. You will be able to set transcoder settings only after you add output video track options (see the next step).
  3. Click the button Add video track and (optionally) select a bitrate and height:

    transcoding options After you added a video track, you'll be able to specify its characteristics.

  4. If you use hardware to speed up transcoding, specify it:

    transcoding options

    • Hardware acceleration — enables hardware transcoding. Using hardware transcoding allows to transcode significantly more streams on a single server.
    • Deinterlace mode (off|on) — activates deinterlacing. Deinterlacing is necessary for comfortable viewing of TV on desktop computers and mobile devices. For transcoding on Nvidia NVENC 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. To set up your own unique options for output video, fill in the form on the screen. Below is the description of the options.

    If a required option is missing on the screen, you can use the text representation of settings and add the option manually. This is described later on this page.

Video options:

  • Video bitrate — specifies the video bitrate of the 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 the quality of video 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:

Specify the path to the logo (after resize) in The path to track's alogo 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:

  • External — turns on the transcoder execution on the server in a separate process from Flussonic. This is the default behavior. It is more reliable in terms of the smooth operation of the Flussonic Media Server. When the option is turned off (external=false), the transcoder runs in the same process with Flussonic. Such a mode speeds up encoding, especially when encoding audio or when Nvidia is used. However, a transcoder error might cause Flussonic to stop working.

For encoding by using the CPU:

  • Decoder threads — the number of threads when decoding a stream. Appears for CPU transcoding. Use this option only after you consult with our support.

For encoding by using Nvidia NVENC hardware:

You can get a part of the area of an input image by cropping the image:

  • 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

For Nvidia NVENC, you can also drop second fields:

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

Editing the text representation of settings

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

Important. There is no complete match between the text representation and the UI fields. Use the text representation only if the UI fields do not provide options or values that you need.

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 correct order of transcoding options. Theexamples are illustrated with pictures where groups of settings are shown in different colors:

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

Example of settings one stream:

Transcoder parameters

vb=2048k preset=fast ab=128k

Examples of configuring multi-bitrate stream parameters:

Transcoder new

Example:

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

Transcoder price

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. 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. 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.

The MP2V codec is not supported with 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 TV 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. Specified separately for each video stream.

Example:

vb=2000k refs=6 ab=128k

bframes

bframes — 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. Specified separately for each video stream.

Example:

vb=2048k hw=nvenc ab=128k

crop

crop — crops video. Available only with hardware transcoding: hw=nvenc. 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. Specify this setting separately for each video stream.

Important! Aspect ratio modification is not compatible with the hw=qsv option.

Example:

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

force_original_aspect_ratio

force_original_aspect_ratio=true — keeps an original video aspect rate by adding black pads. 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 (by contrast to hardware transcoders) and it might help to reduce traffic a little bit.

Example:

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

Other options for video

For example -profile:v high -level 4.1 in Flussonic config would look as follows: profile=high level=4.1.

Audio options:

ab

ab — sets audio bitrate. Specify it 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 blinking 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 on the server by using a hardware transcoder.

Flussonic Media Server supports Nvidia NVENC and Intel Quick Sync Video.

Read more about hardware transcoder here.

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 by 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.

For transcoding by 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.

For transcoding by using GPU Nvidia NVENC the list of presets is as follows:

medium, veryfast, bd, zerolatency, llhq, ll, loseless, loselesshq, default.

For transcoding by 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 blinking that might sometimes occur when a stream's source was changed, especially if the size of the picture in the new source differs. For example, when an ad is inserted in a channel and this ad has different width and height, or when you transcode a server-side playlist consisting of various videos.

With this option, the transcoder seamlessly switches to another source format without dropping any frames. It is achieved by keeping the initial size of video in the resulting stream. All sources will be transcoded with the same size - this is the size specified in the option size. If the output size was not specified, the transcoder keeps 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;
}