vs-mlrt icon indicating copy to clipboard operation
vs-mlrt copied to clipboard

Feature Request: (RIFE) Please add support for rational frame rate changes (like vs-rife has)

Open Samhayne opened this issue 2 years ago • 55 comments

Unfortunately multi is an int.

vs-rife replaced multi with factor_num, factor_den with version 3.0.0 to support rational frame rate changes.

see: https://github.com/HolyWu/vs-rife/releases

Samhayne avatar Oct 01 '23 10:10 Samhayne

Unfortunately, the feature in https://github.com/AmusementClub/vs-mlrt/commit/2f6d5989a33833042a7a5f49ea0d22c0d30ec92d is not as safe as factor_num, factor_den in rife-ncnn-vk. If I tried with mpv, it would used up memory and make my program frozen.

hooke007 avatar Dec 05 '23 13:12 hooke007

How to reproduce it in vsedit/vs-preview?

WolframRhodium avatar Dec 05 '23 19:12 WolframRhodium

I cannot. I remembered holywu once pushed some commits too in his original repo to fix the similar issue. But the related issues are gone by deleting his repo.

hooke007 avatar Dec 06 '23 01:12 hooke007

Since we have used it successfully in encoding, without reliable reproduction we can not validate the claim.

This repository should contain the relevant commit. Do you mean this one?

WolframRhodium avatar Dec 06 '23 01:12 WolframRhodium

It is included i think.

hooke007 avatar Dec 06 '23 03:12 hooke007

Why do you think fps_num is better? It is equivalent to multi=target.fps / source.fps for CFR videos, and I don't think that implementation handles VFR videos.

WolframRhodium avatar Dec 06 '23 04:12 WolframRhodium

No, i never talked about fps_num... To make it clear, factor_num=5 factor_num_den=2 works fine in rife-ncnn-vk. multi=Fraction(5,2) makes the program frozen.

hooke007 avatar Dec 06 '23 05:12 hooke007

Then factor_num and factor_den, which is equivalent to multi=Fraction(factor_num, factor_den), isn't it?

multi=Fraction(5,2) makes the program frozen.

I can't reproduce that with vsedit or vs-preview.

WolframRhodium avatar Dec 06 '23 06:12 WolframRhodium

I can't reproduce that with vsedit or vs-preview.

I knew, that's why I said But the related issues are gone by deleting his repo. The more details explaination are only recorded in those deleted issue.

hooke007 avatar Dec 06 '23 06:12 hooke007

Then we can do nothing.

And we are using different implementation here compared to the original approach.

WolframRhodium avatar Dec 06 '23 06:12 WolframRhodium

multi=Fraction(5,2)

I can confirm this, I tried with MPV and MPC, and both froze. MPC sometimes froze for ~3 minutes and then ran successfully but it froze most of the time.

image

aloola18 avatar Dec 06 '23 06:12 aloola18

but it froze most of the time

Could you provide more information? For example, does the freezing occur at the same frame? Is it related to scene change, and what if you disable scene change detection?

WolframRhodium avatar Dec 06 '23 07:12 WolframRhodium

but it froze most of the time

Could you provide more information? For example, does the freezing occur at the same frame? Is it related to scene change, and what if you disable scene change detection?

It froze when opening any video file or when seeking(when it ran successfully). it's eating a lot of RAM while freezing

image image

I disabled scene change detection, still froze.

aloola18 avatar Dec 06 '23 07:12 aloola18

Are you using SVP with "Duplicate frames removal" enabled?

By "opening any video file", do you mean it does not return any frame at all?

WolframRhodium avatar Dec 06 '23 07:12 WolframRhodium

image yeah, just a black screen and froze.

no, I'm not using SVP.

aloola18 avatar Dec 06 '23 07:12 aloola18

Does the frozen time depends on the number of frames of the video?

WolframRhodium avatar Dec 06 '23 08:12 WolframRhodium

Does the frozen time depends on the number of frames of the video?

seems so, video > 20 minutes took forever to load.

aloola18 avatar Dec 06 '23 08:12 aloola18

That's a new information. What if you change your script to the following:

  • before:

    output = vsmlrt.RIFE(xxx)
    
  • after:

    output = vsmlrt.RIFE(xxx).std.BlankClip(color=[0.5] * 3)
    

Does the playback still froze?

WolframRhodium avatar Dec 06 '23 08:12 WolframRhodium

cut2 = RIFE(cut1, multi=Fraction(5,2), model=46, backend=BackendV2.TRT(force_fp16=True, num_streams=2, output_format=1, static_shape=True)).std.BlankClip(color=[0.5] * 3)

video still froze

aloola18 avatar Dec 06 '23 09:12 aloola18

Do you know Python? I want to know which line of code in the RIFE() function of vsmlrt.py blocks.

This can be checked by inserting a line return clip before each function calls (i.e. line 1147, 1164-1167, 1169, 1176-1179). With this change the original video is returned, but some insertions may not have immediate display.

WolframRhodium avatar Dec 06 '23 09:12 WolframRhodium

I inserted return clip into: line 1146: video play normal w/o interpolation line 1163: froze about 5 seconds then started playing normally w/o interpolation line 1168: video froze

so these lines cause issues?

left_clip = core.akarin.PickFrames(clip, left_indices)
right_clip = core.akarin.PickFrames(clip, right_indices)
tp_clip = core.std.BlankClip(clip, format=gray_format, length=len(timepoints))
tp_clip = tp_clip.akarin.PropExpr(lambda: dict(_tp=timepoints)).akarin.Expr('x._tp')

aloola18 avatar Dec 06 '23 09:12 aloola18

line 1163: froze about 5 seconds then started playing normally w/o interpolation

This is alarming because it should not froze.

In the original program, what if you repeat line 1142-1162 https://github.com/AmusementClub/vs-mlrt/blob/2f6d5989a33833042a7a5f49ea0d22c0d30ec92d/scripts/vsmlrt.py#L1142-L1162 several times? Will each repetition increase the frozen time by 5 seconds?

WolframRhodium avatar Dec 06 '23 09:12 WolframRhodium

Will each repetition increase the frozen time by 5 seconds?

yes, it freeze for a very long time. around 30~40 seconds

image

aloola18 avatar Dec 06 '23 10:12 aloola18

That's a very useful information.

What if you simply call len(timepoints) multiple times in the loop without assignment, does it affect performance?

Alternatively, insert the following piece of code

with open("num_frames.txt", "w") as f:
    f.write(str(clip.num_frames))

This will create a file. What's the value in it?

WolframRhodium avatar Dec 06 '23 10:12 WolframRhodium

called len(timepoints) 5 times took 10 seconds to play a 90 seconds video 25s for 20 minutes video image

What's the value in it?

10810800

aloola18 avatar Dec 06 '23 10:12 aloola18

10810800

Thanks, now I fully understand what happens.

Video playback is different from encoding in that the player will create a clip with a large number of frame, while for encoding the value is at most hundreds of thousands. This make the initialization much more demanding for vudeo playback.

I will start to fix the issue now.

WolframRhodium avatar Dec 06 '23 11:12 WolframRhodium

input = VpsFilterSource.std.Trim(length=500000) #mpc input = video_in.std.Trim(length=500000) #mpv

this prevents the freezing forever, but still slow

the value 10000 is fast at least, still don't know about the side effects thought.

aloola18 avatar Dec 06 '23 11:12 aloola18

The effect of 10000 may be the player closed after playing 10000 frames?

Another side effect with frame interpolation in video players is that, when it jumps to another frame and returns to the previous frame, the player may renders differently.

How is the variable video_in defined?

WolframRhodium avatar Dec 06 '23 11:12 WolframRhodium

How is the variable video_in defined?

https://github.com/mpv-player/mpv/blob/master/video/filter/vf_vapoursynth.c

the value 10000 is fast at least, still don't know about the side effects thought. The effect of 10000 may be the player closed after playing 10000 frames?

The player would destroy the vf_vapoursytn filter after 10000 frames. User have to re-enable the filter again to make it actually work.

when it jumps to another frame and returns to the previous frame, the player may renders differently.

When users are seeking, mpv would destroy the filter and re-activate it again automatically.

hooke007 avatar Dec 06 '23 11:12 hooke007

Thanks for the support.

Please try this initial implementation with RIFE(video_player=True).

This code may change later.

WolframRhodium avatar Dec 06 '23 12:12 WolframRhodium