I want to create a audio-video stream using Liquidsoap. And display the progess and total time of current track in the video. I wonder what is the best practice to achieve this. I am current using the following methods, in which:
- Current progress is acquired with
source.remaining
function. - Total length is a global variable
track_length
, which is modified inon_track
callback.
However, the current method has the following problems:
- The return value of
source.remaining
does not change in a constant speed, as in the document metioned "estimation remaining time". In can be 19min, and suddenly jump to 19min20s, and then jump to 18min50. However, as the remaining time is less and less, the estimation becomes more accurate. - The
track_length
variable does get modified after the current track begins. However, the text drawing function which fetches the variable always get the initial value and never changed.
Thanks for your help!
Here is the relavant part of my script:
# Define the global variable to store the length of current track
track_length = 0
# Define the on_track callback which updates track_length
def process_metadata(metadata)
file_name = metadata["filename"]
track_length = file.duration(file_name)
end
# Define the audio source and hook on_track callback
audio = fallback([sequence([
single("/etc/liquidsoap/lssj1.mp3")
])])
audio = on_track(process_metadata, audio)
# Define the function which returns the text to render
def get_time()
"$(cur)/$(total)" % [("cur", string_of(source.remaining(audio))), ("total", string_of(track_length))]
end
# Create the video frame
video = fallback([blank()])
video = video.add_text.sdl(x=0, y=300, size=40, get_time, video)