godot-videodecoder icon indicating copy to clipboard operation
godot-videodecoder copied to clipboard

set_stream_position setting the position right after setting the stream results in a black screen

Open arsen-ch opened this issue 5 years ago • 8 comments

Hi, Is set_stream_position method supported? It seems that nothing happens when the method is called from Godot.

arsen-ch avatar Feb 11 '20 16:02 arsen-ch

It's not supported. At least yet. I had troubles working with seek.

zombietype avatar Apr 21 '20 11:04 zombietype

Should work now

jamie-pate avatar Apr 21 '20 17:04 jamie-pate

@jamie-pate setting stream position seems to not be working for me, it reverts it to the first second, also setting the position right after setting the stream results in a black screen for me (running godot 3.2.1 stable on linux).

Interestingly, until I set the stream position manually the playback has terrible performance.

EIREXE avatar Jun 02 '20 01:06 EIREXE

It seems like it only happens to certain webms, this webm for example presents the issue, in case you need something for testing:

https://files.catbox.moe/f1l26s.webm

EIREXE avatar Jun 02 '20 01:06 EIREXE

It seems to work fine for me: https://streamable.com/ofjpau There is some special handling required to make it work though: https://github.com/kidrigger/godot-videodecoder/blob/master/src/gdnative_videodecoder.c#L841

FIG1: how to seek while paused...
var _paused_seeking = 0
func seek_player(value):
	var was_playing = _playing
	if _playing:
		stop()
	_player.stream_position = value
	if was_playing:
		play(value)
		if _player.paused || _paused_seeking > 0:
			_player.paused = false
			_paused_seeking = _paused_seeking + 1
			# yes, it seems like 5 idle frames _is_ the magic number.
			# VideoPlayer gets notified to do NOTIFICATION_INTERNAL_PROCESS on idle frames
			# so this should always work?
			for i in range(5):
				yield(get_tree(), 'idle_frame')
			# WARNING: -= double decrements here somehow?
			_paused_seeking = _paused_seeking - 1
			assert(_paused_seeking >= 0)
			if _paused_seeking == 0:
				_player.paused = true

Basically you need to let it play for a frame because the VideoStreamGDNative class won't ask for any frames unless it's playing. This is something that will have to be fixed in godot itself.

jamie-pate avatar Jun 02 '20 16:06 jamie-pate

Not sure on the performance bit, one day I'll add this workaround and a proper benchmark into the test project...

jamie-pate avatar Jun 02 '20 16:06 jamie-pate

Not sure on the performance bit, one day I'll add this workaround and a proper benchmark into the test project...

I cannot replicate the performance bit anymore, but doing the seek fixed it, thanks for the code, i'll test it!

EIREXE avatar Jun 02 '20 16:06 EIREXE

Interestingly, the issue seems to happen regardless if I don't set the stream_position to -1 and then to 0 before initialization. All I get is a black screen, this is my code (using the demo):

imagen

EIREXE avatar Jun 02 '20 16:06 EIREXE