164 CHAPTER 6. FULL WORKFLO W OF A RADIO STATION
but it should be a subtype of
source(audio=ffmpeg.audio.copy(_),...)
which says that
amplify
is only able to manipulate audio data in in-
ternal format (
audio=pcm(_)
) whereas we have here encoded data
(audio=ffmpeg.audio.copy(_)).
Now, suppose that, in addition to transmitting the mp3 les through Icecast, we
also want to provide another version of the stream in Opus. In this, case we need
to decode the stream provided by the source, which is encoded in mp3, before
being able to convert it in Opus. This can be achieved with
ffmpeg.decode.audio
,
which will decode any encoded stream into Liquidsoap internal format, after
which we can handle it as usual:
radio = playlist("~/Music")
output.icecast(fallible=true, format="audio/mpeg", mount="radio",
%ffmpeg(format="mp3", %audio.copy), radio)
radio = ffmpeg.decode.audio(radio)
# From there the radio source is decoded
output.icecast(fallible=true, format="audio/mpeg", mount="radio-opus",
%opus, radio)
Incidentally, the functions
ffmpeg.decode.video
and
ffmpeg.decode.audio_video
are also provided to decode streams with video and both audio and video
respectively.
Encode once, output multiple times. It sometimes happens that we want to have
the same source, encoded in the same format, by multiple outputs. For instance,
in the following script, we have a
radio
source that we want to encode in mp3
and output in Icecast, in hls and in a le:
output.icecast(%mp3, mount="radio", radio)
output.file.hls("hls", [("mp3", %mp3)], radio)
output.file(%mp3, "radio.mp3", radio)
Because there are three outputs with
%mp3
format, Liquidsoap will encode the
stream three times in the same format, which is useless and can be costly
if you have many streams or, worse, video streams. We would thus like to
encode in mp3 once, and send the result to Icecast, hls and the le. This can be
achieved by using the
ffmpeg.encode.audio
operator which will turn our source
in Liquidsoap’s internal format into one with encoded audio (using FFmpeg).
This encoded audio can then be passed to the various outputs using the
%ffmpeg
encoder with
%audio.copy
to specify that we want to simply pass on the encoded
audio. Concretely, the following script will encode the
radio
source once in mp3,
and then broadcast it using Icecast, hls and le outputs:
radio = ffmpeg.encode.audio(%ffmpeg(%audio(codec="libmp3lame")), radio)
# From there the radio source is in mp3 format