godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 79 forks source link

VideoPlayer node: add looping option in the GUI of it in editor as well as a looping in reverse option. #3949

Open Captainkittyca2 opened 2 years ago

Captainkittyca2 commented 2 years ago

Describe the project you are working on

A 2D platformer with videos as backgrounds.

Describe the problem or limitation you are having in your project

I want to make a video loop in VideoPlayer node as well as to make it loop backwards/in reverse.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add the option to allow the video to loop in the godot editor/GUI as well as an option to make it loop in reverse/backwards. This will allow to make it loop by just enabling it in editor instead of having to code it in script as well as allow it to loop in reverse which, from what i read, isn't possible when coding it at the moment.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Normal looping option: When the video ends, it resets from the beginning of the video and plays it again. Reverse looping option: When the video ends, it plays in reverse from the end of the video to the beginning, then once it reaches the beginning again, it loops.

If this enhancement will not be used often, can it be worked around with a few lines of script?

For making the video loop, it's possible to code it in gdscript but it isn't always convenient, especially for amateurs, and from what I heard, it isn't possible to code it to make the video loop in reverse/backwards.

Is there a reason why this should be core and not an add-on in the asset library?

Yes, to improve the overall VideoPlayer node since at least the normal looping is a fairly important feature, and the looping backwards/reverse can be used to help people make background effects.

Mickeon commented 2 years ago

Reverse looping option: When the video ends, it plays in reverse from the end of the video to the beginning, then once it reaches the beginning again, it loops.

This is totally personal preference, but this exact looping mode can be used in Aseprite's animation tagging system and it is called "Ping-Pong", which I find to be a pretty self-explanatory name, too.

Calinou commented 2 years ago
Calinou commented 1 year ago

Looping in VideoPlayer was implemented in https://github.com/godotengine/godot/pull/77857.

As far as I know, ping-ping looping or reverse playback isn't technically possible without preprocessing the video to contain a reversed version at the end. This means you need to store a second copy of the video in the project files – there's no way around this.

This is because video codecs work in a progressive manner, where they build upon the output of the previous frame to decode the next frame. If you wanted to play a video backwards, you would need to decode the i-frame and decode all progressive frames after that every time a new frame is played. This is extremely slow (try holding down the negative frame-advance key in a video player, compared to holding down the positive frame-advance key).