savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 130 forks source link

Trouble with transitions #1929

Closed FlorianReiterer closed 3 years ago

FlorianReiterer commented 3 years ago

Having trouble with transitions, feeding flac files. If written like this:

settings.frame.audio.channels.set(2)
settings.frame.audio.samplerate.set(96000)

music = playlist(reload_mode="watch","/Musik")

live = input.harbor("live", port=18888, password="hackme")

def to_show(a, b) 
  add(normalize=false, [
    fade.out(a),
    sequence([blank(duration=2.), (b.source)]),
  ])
end
radio=fallback(track_sensitive=false, transition_length=5., transitions=[to_show],[live, music])

output.icecast(%mp3(bitrate=256,samplerate=44100), fallible=true, mount="source.mp3", radio)

it crashes with

2021/09/14 22:14:38 [switch_0:3] Switch to playlist_0.
2021/09/14 22:14:54 [input.harbor_0:3] Decoding...
2021/09/14 22:14:54 [input.harbor_0:3] New metadata chunk Mother Earth Radio -- Musikvorstellung.
2021/09/14 22:14:56 [switch_0:3] Switch to input.harbor_0 with transition.
2021/09/14 22:14:56 [clock.main:2] Source source.mp3 failed while streaming: Lang_values.Internal_error at at bug.liq, line 13, char 9-17, at bug.liq, line 11 char 0 - line 16 char 3: invoked method source not found!
2021/09/14 22:14:56 [source.mp3:3] Closing connection...

written like this

def to_show(a, b) 
add(normalize=false, [
sequence([fade.out(a), blank(duration=2.), (b)]),
])
end

it doesn't do any fading. Lastly

def to_show(a, b) 
crossfade(b)
end

gives

2021/09/14 22:20:49 [switch_0:3] Switch to input.harbor_0 with transition.
2021/09/14 22:20:49 [clock.main:2] Source source.mp3 failed while streaming: Clock_conflict: At position: unknown position, a source cannot belong to two clocks (cross_0.child[], main[])!

obviously that is just done wrong, looking at the clocks message. I try to have a transition at the switch to live show that fades out the regular stream inserts blank and starts the source with no fading.

Its a raspbian buster, RPI4, installed via opam, ffmpeg pinned from github

2021/09/14 22:24:13 >>> LOG START
2021/09/14 22:24:11 [main:3] Liquidsoap 2.0.0-rc1
2021/09/14 22:24:11 [main:3] Using: graphics=[distributed with Ocaml] bytes=[distributed with OCaml 4.02 or above] pcre=7.4.6 sedlex=2.4 menhirLib=20210419 curl=0.9.1 dtools=0.4.4 duppy=0.9.2 cry=0.6.5 mm=0.7.1 ogg=0.7.0 ogg.decoder=0.7.0 mad=0.5.0 flac=0.3.0 flac.ogg=0.3.0 flac.decoder=0.3.0 dynlink=[distributed with Ocaml] lame=0.3.4 ffmpeg-avutil=7d8a3b1 ffmpeg-avcodec=7d8a3b1 ffmpeg-avdevice=7d8a3b1 ffmpeg-av=7d8a3b1 ffmpeg-avfilter=7d8a3b1 ffmpeg-swresample=7d8a3b1 ffmpeg-swscale=7d8a3b1 samplerate=0.1.6 taglib=0.3.6 ssl=0.5.9 camomile=1.0.2 tsdl=v0.9.8 camlimages=4.2.6
2021/09/14 22:24:11 [dynamic.loader:3] Could not find dynamic module for fdkaac encoder.
2021/09/14 22:24:11 [clock:3] Using builtin (low-precision) implementation for latency control
2021/09/14 22:24:13 [frame:3] Using 96000Hz audio, 25Hz video, 96000Hz main.
2021/09/14 22:24:13 [frame:3] Video frame size set to: 1280x720
2021/09/14 22:24:13 [frame:3] Frame size must be a multiple of 3840 ticks = 3840 audio samples = 1 video samples.
2021/09/14 22:24:13 [frame:3] Targeting 'frame.duration': 0.04s = 3840 audio samples = 3840 ticks.
2021/09/14 22:24:13 [frame:3] Frames last 0.04s = 3840 audio samples = 1 video samples = 3840 ticks.
2021/09/14 22:24:13 [sandbox:3] Sandboxing disabled
2021/09/14 22:24:13 [video.converter:3] Using preferred video converter: ffmpeg.
2021/09/14 22:24:13 [audio.converter:3] Using samplerate converter: ffmpeg.
2021/09/14 22:24:13 [harbor:3] Adding mountpoint '/live' on port 18888
2021/09/14 22:24:13 [source.mp3:3] Connecting mount source.mp3 for source@localhost...
2021/09/14 22:24:13 [source.mp3:3] Connection setup was successful.
2021/09/14 22:24:13 [clock.main:3] Streaming loop starts in auto-sync mode
2021/09/14 22:24:13 [clock.main:3] Delegating synchronisation to CPU clock
2021/09/14 22:24:13 [source.mp3:3] Source failed (no more tracks) stopping output...
2021/09/14 22:24:13 [source.mp3:3] Closing connection...
2021/09/14 22:24:14 [playlist_0:3] Prepared "/media/pi/Elements 4TB/FTP Mother Earth/Musik/Feist/09 Undiscovered First.flac" (RID 0).
2021/09/14 22:24:14 [source.mp3:3] Connecting mount source.mp3 for source@localhost...
2021/09/14 22:24:14 [source.mp3:3] Connection setup was successful.
2021/09/14 22:24:14 [switch_0:3] Switch to playlist_0.
2021/09/14 22:25:01 [input.harbor_0:3] Decoding...
2021/09/14 22:25:01 [input.harbor_0:3] New metadata chunk Mother Earth Radio -- Musikvorstellung.
2021/09/14 22:25:03 [switch_0:3] Switch to input.harbor_0 with transition.
2021/09/14 22:25:03 [clock.main:2] Source source.mp3 failed while streaming: Lang_values.Internal_error at at bug.liq, line 14, char 31-39, at bug.liq, line 11 char 0 - line 16 char 3: invoked method source not found!
2021/09/14 22:25:03 [source.mp3:3] Closing connection...
2021/09/14 22:25:03 [harbor:3] Removing mountpoint '/live' on port 18888
2021/09/14 22:25:03 [harbor:3] Nothing more on port 18888: closing sockets.
2021/09/14 22:25:03 [clock:2] Error when leaving output source.mp3: File "sources/request_source.ml", line 339, characters 10-16: Assertion failed!
2021/09/14 22:25:03 [clock.main:3] Streaming loop stopped.
2021/09/14 22:25:03 [main:3] Shutdown started!
2021/09/14 22:25:03 [main:3] Waiting for main threads to terminate...
2021/09/14 22:25:04 [input.harbor_0:2] Error while reading from client: Bad file descriptor in select()
Invalid return value 0 for stream protocol
2021/09/14 22:25:04 [input.harbor_0:2] Feeding stopped: Failure("relaying stopped").
2021/09/14 22:25:04 [main:3] Main threads terminated.
2021/09/14 22:25:04 [threads:3] Shutting down scheduler...
2021/09/14 22:25:04 [threads:3] Scheduler shut down.
2021/09/14 22:25:04 [main:3] Cleaning downloaded files...
2021/09/14 22:25:04 [main:3] Freeing memory...
toots commented 3 years ago

Ok, couple of issues here:

  1. Looks like you found a bug! See: https://github.com/savonet/liquidsoap/issues/1930

  2. This is the way to do it. However, remember that when the switch goes from live to music, this means the live has ended and there is no more data to do a fade out. There maybe ways to mitigate but it can get complicated so I'd recommend trying first with the expectation that live->music transitions cannot do fade out.

  3. You cannot use input.harbor and other live sources with crossfade as crossfade needs to accelerate the source. That's what this cryptic error message is trying to tell you..