Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active October 1, 2025 19:48
Show Gist options
  • Select an option

  • Save ZiTAL/b306c09e098e2ad7003af6c77b3328a0 to your computer and use it in GitHub Desktop.

Select an option

Save ZiTAL/b306c09e098e2ad7003af6c77b3328a0 to your computer and use it in GitHub Desktop.
icecast / liquidsoap / ffmpeg: switch between pulseaudio / alsa devices vorbis/mp3/opus/aac
host = "127.0.0.1"
port = 8000
name = "Name"
desc = "Description"
url = "https://example.com"
# free opus config
free_passwd = "test"
free_mount = "/test.opus"
# acc config
private_passwd = "test"
private_mount = "/test.aac"
# telnet
settings.server.telnet.set(true)
settings.server.telnet.bind_addr.set("0.0.0.0")
settings.server.telnet.port.set(1234)
# inputs
input0 = input.pulseaudio(device="alsa_output.usb-PreSonus_AudioBox_USB_96_000000000000-00.stereo-fallback.monitor")
input1 = input.pulseaudio(device="alsa_input.usb-BEHRINGER_UMC202HD_192k-00.Direct__Direct__source")
# default input
current_input = ref(0)
# switch input based on ref()
sel =
switch(track_sensitive=false, [
(fun () -> current_input() == 0, input0),
(fun () -> current_input() == 1, input1)
])
# safe fallback
s = fallback(track_sensitive=false, [sel, blank()])
# server select input
server.register("select", fun (arg) ->
if arg == "0" then
current_input := 0; "Switched to: INPUT 0"
elsif arg == "1" then
current_input := 1; "Switched to: INPUT 1"
else
"Usage: input_select <0|1>"
end)
# server status
server.register("status", fun (_) ->
"current=" ^ string(current_input())
^ "\ninput0_ready=" ^ string(source.is_ready(input0))
^ "\ninput1_ready=" ^ string(source.is_ready(input1)))
# server get current input
server.register("current", fun (_) ->
if current_input() == 0 then "INPUT 0" else "INPUT 1" end)
# free opus audio
output.icecast(
%opus(vbr="unconstrained", application="audio", samplerate=48000, channels=2, bitrate=160),
host=host,
port=port,
password=free_passwd,
mount=free_mount,
name=name,
description=desc,
url=url,
s
)
# private aac audio
output.icecast(
%ffmpeg(
format="adts",
%audio(codec="aac", b="256k", ar=48000, ac=2)
),
host=host,
port=port,
password=private_passwd,
mount=private_mount,
name=name,
description=desc,
url=url,
s
)
host = "127.0.0.1"
port = 8000
name = "Name"
desc = "Desc"
url = "https://example.com"
# vorbis config
vorbis_passwd = "test"
vorbis_mount = "/test.ogg"
# mp3 config
mp3_passwd = "test"
mp3_mount = "/test.mp3"
# telnet
settings.server.telnet.set(true)
settings.server.telnet.bind_addr.set("0.0.0.0")
settings.server.telnet.port.set(1234)
# inputs
# pactl list short sources
input0 = input.pulseaudio(device="alsa_output.usb-PreSonus_AudioBox_USB_96_000000000000-00.stereo-fallback.monitor")
input1 = input.pulseaudio(device="alsa_input.usb-BEHRINGER_UMC202HD_192k-00.Direct__Direct__source")
# default input
current_input = ref(0)
# switch input based on ref()
sel =
switch(track_sensitive=false, [
(fun () -> current_input() == 0, input0),
(fun () -> current_input() == 1, input1)
])
# safe fallback
s = fallback(track_sensitive=false, [sel, blank()])
# server select input
server.register("select", fun (arg) ->
if arg == "0" then
current_input := 0; "Switched to: INPUT 0"
elsif arg == "1" then
current_input := 1; "Switched to: INPUT 1"
else
"Usage: input_select <0|1>"
end)
# server status
server.register("status", fun (_) ->
"current=" ^ string(current_input())
^ "\ninput0_ready=" ^ string(source.is_ready(input0))
^ "\ninput1_ready=" ^ string(source.is_ready(input1)))
# server get current input
server.register("current", fun (_) ->
if current_input() == 0 then "INPUT 0" else "INPUT 1" end)
# ogg/vorbis audio
output.icecast(
%vorbis.cbr(samplerate=48000, channels=2, bitrate=256),
host=host,
port=port,
password=vorbis_passwd,
mount=vorbis_mount,
name=name,
description=desc,
url=url,
s
)
# mpeg/mp3 audio
output.icecast(
%mp3.cbr(samplerate=48000, bitrate=320, stereo=true),
host=host,
port=port,
password=mp3_passwd,
mount=mp3_mount,
name=name,
description=desc,
url=url,
s
)
@ZiTAL
Copy link
Author

ZiTAL commented Oct 1, 2025

Change source:

printf "select 0\n" | nc -N 127.0.0.1 1234
printf "select 1\n" | nc -N 127.0.0.1 1234

Get current source:

printf "current\n" | nc -N 127.0.0.1 1234

status:

printf "status\n" | nc -N 127.0.0.1 1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment