CrendKing / avisynth_filter

DirectShow filters that put AviSynth and VapourSynth into video playing
MIT License
107 stars 8 forks source link

Video freezing while switching subtitles #76

Closed chainikdn closed 1 year ago

chainikdn commented 2 years ago

Regression in ver. 1.4.1. Switch between subtitles -- notice video freezing from several seconds to forever. Environment: MPC-HC, madVR, AVSF, no script, no SVP. For me this only happens with MPC-HC+madVR, doesn't happen with other renderers (EVR, MPC) or other players (MPC-BE, PotPlayer). However another user said "it also freezes on other renderers".

CrendKing commented 2 years ago

I tried all combinations below on latest version and can't repro

When you say "Regression in ver. 1.4.1." do you mean it only happens in 1.4.1 and not 1.4.2 and 1.4.3, or since 1.4.1?

Also, I probably need a video to help repro.

chainikdn commented 2 years ago

or since 1.4.1?

this

I probably need a video to help repro.

https://www.svp-team.com/forum/viewtopic.php?pid=80667 https://www.youtube.com/watch?v=leq8ov-iaD0

CrendKing commented 2 years ago

Tried so many times, and only managed to "freeze" for 1 second, twice. Seems extremely rare, and only happens for the remote injection scenario. Never happens with fixed script.

Probably need a more reliable way to repro to handle this issue.

chainikdn commented 2 years ago

only happens for the remote injection scenario. Never happens with fixed script.

no script, no SVP

external AviSynth Filter disabled -> runs normally; SVP not running, external AviSynth Filter enabled -> freeze on subtitle change; SVP running, external AviSynth Filter enabled -> runs normally.

Skaitliuk commented 2 years ago

Hello, i'm the user, who posted this on SVP forum, I recorded another video with more info on screen, maybe it will help. basically, I'm cycling through the subtitles with a hotkey, and freezes happen. I reverted avisynth filter to version v1.3.1, and the freezes are gone. https://www.youtube.com/watch?v=cAPgSQknBPs

CrendKing commented 2 years ago

I tried the exact same setup and can't reproduce. There is always slight freeze when switching tracks, because that's basically equivalent to re-opening the video file. However, there shouldn't be a difference between remote injection vs fixed script. They go through the same process. Would you please upload log of the those two scenarios?

Skaitliuk commented 2 years ago

Would you please upload log of the those two scenarios?

I don't really understand how this works and what scenarios you need. I uploaded log with filter version 1.4.3 and no SVP running (when freezes happen), 1.4.3 with SVP running and 1.3.1 no SVP. Is this what you wanted? each time I start the same video and cycle through subtitles ~8 times.

1.3.1 no svp running.log 1.4.3 no SVP running.log 1.4.3 SVP running.log

CrendKing commented 1 year ago

The second log shows lots of message about "Rejecting source sample due to start time going backward". I'm theorizing that you are facing a race condition that I can reproduce locally, which is the usual nature of race condition.

That race condition exists because I deliberately chose to not lock most of AddInputSample() exclusively for performance concern. However, if it is the case of this bug, we may have to sacrifice that bit of performance for correctness.

Please test https://github.com/CrendKing/avisynth_filter/actions/runs/2768521271. If it indeed fixes your problem, we can discuss about performance.

Skaitliuk commented 1 year ago

The freezes are gone for me. Logs attached just in case. avisynth_filter.log

CrendKing commented 1 year ago

Thanks. I optimized the logic a bit. Could you please test this?

https://github.com/CrendKing/avisynth_filter/actions/runs/2831024679

Skaitliuk commented 1 year ago

Freezes are back again when switching subtitles. avisynth_filter.log

CrendKing commented 1 year ago

I think I found the root cause. Hope https://github.com/CrendKing/avisynth_filter/actions/runs/2845275349 fix for real.

Also reverted all the "performance-hitting" change above.

Technical detail for the record:

Switching subtitle basically stops the filter chain for a brief moment, and restart the chain. This means the input pin's Inactive() is called then Active().

The current input pin's Inactive() calls BeginFlush() followed by a EndFlush(). This sets _isFlushing to true then back to false, which leaves a small window for the filter to receive input samples before Active(). If upstream indeed sends an excessive sample with bad start sample time in that window, we are screwed from there.

This change moves the EndFlush() to the end of Active(), guaranteeing all new samples are post-flush, with correct start time.

Skaitliuk commented 1 year ago

yes, subtitles freezes are gone, but now MPC-HC freezes(not responding) on video seek. With MPC renderer, MPC-HC freezes on the first video time seek; With MadVR, freezes when I seek a paused video.... avisynth_filter.log

CrendKing commented 1 year ago

Sorry, I forgot to test the change on some video renderers, such as EVR and MPC. Fix: https://github.com/CrendKing/avisynth_filter/actions/runs/2851210801

Skaitliuk commented 1 year ago

No more issues from me, everything works, thank you

ssssssbbb commented 1 year ago

Potplayer with madVR renderer freezes on immediate seek after start playing, EVR(CP) is OK, and MPC-HC is OK with both renderers.

1.log

This version is good, https://github.com/CrendKing/avisynth_filter/actions/runs/2831024679, later ones are not.

CrendKing commented 1 year ago

I can't reproduce the issue, and I can't find anything extraordinary from your log. Again, even if I can repro, most of the time there is not much I can do, as both PotPlayer and madVR are closed source.

If you really want to use PotPlayer, and you don't experience this issue, feel free to use previous working version. v1.4.4 does not introduce any new feature or performance improvement.