Encoders are used to define formats into which raw sources should be encoded by an output. Syntax for encoder is:
%encoder(parameters...) or, if you use default parameters,
Formats determine the stream content
In most liquidsoap scripts, the encoding format determines what kind of data is streamed.
The type of an encoding format depends on its parameter. For example,
%mp3 has type
%mp3(mono) has type
The type of an output like
output.file is something like
(...,format('a),...,source('a))->source('a). This means that your source will have to have the same type as your format.
For example if you write
then the playlist source will have to stream stereo audio. Thus it will reject mono and video files.
Liquidsoap provides operators that can be used to convert sources into a format acceptable for a given encoder. For instance, the
mean operator transforms any audio source into a mono source and the
audio_to_stereo operator transforms any audio source into a stereo source.
Format variables (or lack of, rather..)
You can store an atomic format in a variable, it is a value like another:
fmt = %mp3. However, an atomic format is an atomic constant despite its appearance. You cannot use a variable for one of its parameters: for example
is not allowed, you must write
If you really need to use variables in encoder, for instance if bitrate is given by a user’s configuration, you may alleviate that by generating a pre-defined list of possible encoders and include it on top of your script using the
List of formats and their syntax
All parameters are optional, and the parenthesis are not needed when no parameter is passed. In the following default values are shown. As a special case, the keywords
stereo can be used to indicate the number of channels (whether is is passed as an integer or a boolean).
Mp3 encoder comes in 3 flavors:
%mp3.cbr: Constant bitrate encoding
%mp3.vbr: Variable bitrate, quality-based encoding.
%mp3.abr: Average bitrate based encoding.
Parameters common to each flavor are:
mono=true/false: Encode stereo or mono data (default:
stereo_mode: One of:
samplerate=44100: Encoded data samplerate (default:
internal_quality=2: Lame algorithms internal quality. A value between
0being highest quality and
9the worst (default:
id3v2=true: Add an
id3v2tag to encoded data (default:
false). This option is only valid if liquidsoap has been compiled with taglib support.
bitrate: Encoded data fixed bitrate
quality: Quality of encoded data; ranges from
0(highest quality) to
bitrate: Average bitrate
min_bitrate: Minimun bitrate
max_bitrate: Maximun bitrate
hard_min: Enforce minimal bitrate
128kbps bitrate encoding:
- Variable bitrate with quality
6and samplerate of
- Average bitrate with mean of
128kbps, maximun bitrate
Optionally, liquidsoap can insert a message within mp3 data. You can set its value using the
msg parameter. Setting it to
"" disables this feature. This is its default value.
Shine is the fixed-point mp3 encoder. It is useful on architectures without a FPU, such as ARM. It is named
%mp3.fxp and its parameters are:
false, the encoder outputs raw PCM.
duration is optional and is used to set the WAV length header.
Because Liquidsoap encodes a possibly infinite stream, there is no way to know in advance the duration of encoded data. Since WAV header has to be written first, by default its length is set to the maximun possible value. If you know the expected duration of the encoded data and you actually care about the WAV length header then you should use this parameter.
%ffmpeg encoder is the latest addition to our collection, starting with version
1.4.0. It is only for audio encoding for now. You need to have ocaml-ffmpeg installed and up-to date to enable the encoder during liquidsoap’s build.
The encoder should support all the options for
ffmpeg’s muxers and encoders, including private configuration options. Configuration value are passed as key/values, with values being of types:
float. If a configuration is not recognized (or: unused), it will raise an error during the instantiation of the encoder. Here are some configuration examples:
- AAC encoding at
- Mp3 encoding using
%ffmpeg encoder is the prime encoder for HLS output as it is the only one of our collection of encoder which can produce Mpeg-ts muxed data, which is required by most HLS clients.
The following formats can be put together in an Ogg container. The syntax for doing so is
%ogg(x,y,z) but it is also possible to just write
%vorbis(...), for example, instead of
All ogg encoders have a
bytes_per_page parameter, which can be used to try to limit ogg logical pages size. For instance:
Quality ranges from -0.2 to 1, but quality -0.2 is only available with the aotuv implementation of libvorbis.
Opus is a lossy audio compression made especially suitable for interactive real-time applications over the Internet. Liquidsoap supports Opus data encapsulated into Ogg streams.
The encoder is named
%opus and its parameters are as follows. Please refer to the Opus documentation for information about their meanings and values.
vbr: one of
application: One of
complexity: Integer value between
max_bandwidth: One of
samplerate: input samplerate. Must be one of:
frame_size: encoding frame size, in milliseconds. Must be one of:
bitrate: encoding bitrate, in
kbps. Must be a value between
512. You can also set it to
channels: currently, only
2channels are allowed.
stereo: equivalent to
signal: one of
You can also pass
bitrate=x explicitly instead of a quality. The default dimensions are liquidsoap’s default, from the settings
You can also control quality using
The flac encoding format comes in two flavors:
%flacis the native flac format, useful for file output but not for streaming purpose
%ogg(%flac,...)is the ogg/flac format, which can be used to broadcast data with icecast
The parameters are:
compression ranges from 0 to 8 and
bits_per_sample should be one of:
This encoder can do both AAC and AAC+.
Its syntax is:
aot is one of:
bandwidth is one of:
"auto", any supported integer value.
transmux is one of:
Bitrate can be either constant by passing:
bitrate=64 or variable:
You can consult the Hydrogenaudio knowledge base for more details on configuration values and meanings.
%gstreamer encoder can be used to encode streams using the
gstreamer multimedia framework. This encoder extends liquidsoap with all available GStreamer formats which includes most, if not all, formats available to your operating system.
The encoder’s parameters are as follows:
Please refer to the Gstreamer encoder page for a detailed explanation of this encoder.
For a detailed presentation of external encoders, see this page.
Only one of
restart_after_delay should be passed. The delay is specified in seconds. The encoding process is mandatory, and can also be passed directly as a string, without