How to display a specific frame from a video as an image?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FrazzleTime

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.

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.

estebanmolca | 2020-01-21 12:13

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

FrazzleTime | 2020-01-21 19:02

:bust_in_silhouette: Reply From: FrazzleTime

I asked on github and got the solution from here:

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.get_video_texture().get_data()
var texture = ImageTexture.new()
texture.create_from_image(image)
$TextureButton.set_normal_texture(texture)

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.

estebanmolca | 2020-01-23 06:50

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.

FrazzleTime | 2020-01-23 20:18