Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change x text position dinamically when speed>0 #2622

Closed
kessenza opened this issue Sep 15, 2022 · 2 comments
Closed

change x text position dinamically when speed>0 #2622

kessenza opened this issue Sep 15, 2022 · 2 comments
Assignees

Comments

@kessenza
Copy link

kessenza commented Sep 15, 2022

Using method video.add_text and speed > 0 (and in particular when cycle=false) x is used only as initial value but then an internal x is used to scroll text from right to the left. But when the text goes out and we, for instance, want to change it (to show a different info text) then the internal x stays out of the screen and there is no way to bring it back to the right

@smimram
Copy link
Member

smimram commented Sep 16, 2022

For this one, let's first discuss this here. I fear that if I add this the code will become clumsy and moreover, we will never be able to cover all possible cases of needs with video.add_text.

However, I have good news: you can achieve what you want in Liquidsoap, by programming your own advanced x parameter. The x function is called at every frame, you can then simply return the value of a reference, updated in a way which suits your needs. You can draw inspiration from the implementation of video.add_text itself: https://github.com/savonet/liquidsoap/blob/main/src/libs/video.liq#L301

Typically for a scrolling you would do something like:

fps = video.frame.rate()
r = ref(0)
speed = 100 # scrolling speed

def x()
  x := !x + speed / fps
  !x
end
video.add_text(x, "text", main_source)

and you can easily add more logic in order to detect when the boundary is reached etc.

@kessenza
Copy link
Author

kessenza commented Sep 16, 2022

Just to be sure (because I am little weak on ls scripting language). Do you mean ? :

fps = video.frame.rate()
r = ref(0)
speed = 100 # scrolling speed

def x()
  r := !r + speed / fps
  !r
end

Yes this solves all the possible cases together wtih #2621
The only little thing is that in this way (in particular when) cycling on the opposite way ( r := !r - speed / fps), it's not easy to detect when text goes out of the screen because you have to compute string.length(text) * pixel_by_char

Anyway it works. Thanks!

@savonet savonet locked and limited conversation to collaborators Sep 16, 2022
@smimram smimram converted this issue into discussion #2626 Sep 16, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants