0 votes

Hello,

I am having trouble getting one frame from a video and display it as a Texture on a button.

1) I can't seem to set the videoplayer to a certain position. The video just keeps playing and using print() indicates its play position hasn't moved.

2) In the docs it sais get_video_texture() returns the current frame as a Texture. When I try it though, the function returns the whole video as a Texture. So my button ends up as a video playing. I tested this with .ogv and .webm format.

I am using this code:

func _on_Button_pressed():
  print($VideoPlayer.stream_position)
  $VideoPlayer.stream_position = 5.502
  print($VideoPlayer.stream_position)

 $TextureButton.set_normal_texture ($VideoPlayer.get_video_texture())

Unless there is another way to solve this, I don't know how to continue.

in Engine by (32 points)

Sounds like a bug or the documentation is poor. Check the video player in the github of godot and it has few commits, it seems that almost nobody uses it ... if you dare you can report it in the github.

Ok thank you . I will submit the issue to github.

1 Answer

0 votes
Best answer

I asked on github and got the solution from here:
https://github.com/godotengine/godot/issues/35410

It's returning the texture, but the texture will be updated by the
video player when playing. The texture button's texture updates because it is referencing the same object as the video player's.

You may want something like this:
var image = player.getvideotexture().getdata()
var texture = ImageTexture.new()
texture.create
fromimage(image)
$TextureButton.set
normal_texture(texture)

by (32 points)
selected by

Thanks for coming back and I'm glad you found the answer, something similar is used when you want to take a capture of the viewport and use that texture somewhere else. The documentation of godot can be very little or nil in several parts.

No problem. Hopefully it can help other people with the same problem.
It's true that the documentation could use some work but at least there is the community as well to rely on.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.