New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Player hangs after seeking backwards with multiple Prefetchers. #21
Comments
I don't know why, but for me, it started consistently hanging after updating the filter and then working normally when switching back, but the behavior i observed initially was that after updating, it consistently took only one seek backwards to trigger; with the simplified script it takes more tries. Could be that i was unknowingly triggering some other hang condition and while troubleshooting ended up locating this one.
Neo builds (and derivatives) allow for the creation of OnCPU & OnCUDA pipelines, which usually speed up processing even when not strictly necessary and can be used in conjunction with it's enhanced Prefetch-function. There is very little documentation and most of what i know is from Google-translated Japanese from here and my own experimentation. Main differences between OnCPU & Prefetch as i understand them are:
I guess it could even be an AviSynth+ bug. I remember noticing some latency degradation before when first testing the performance of multiple prefetchers. The latency degradation wasn't there with OnCPU, which is why i started using it with Prefetch in the first place. In other words:
I'm fairly sure the documentation predates OnCPU and likely Prefetch(threads , frames) as well.
Done. |
Try AviSynthFilter.zip, should no longer hang. Here is the process of reaching the fix for documentation purpose. First, I tested I tried the combination on a 4K video + SVP, which pressures CPU to 50%. I can't tell any difference with and without Then I went to try ffdshow. It does not hang. And the reason is ffdshow does not reload script when seeking, which is why you see those ghost frames after seek. I can comment out two lines in our code to achieve the same, but obviously that's wrong decision. Then I went to investigate the call stack at hang. It looks like because the new I first tried to prove the theory by hacking a version that destroy and recreate avs environment during seek, and as expected it no longer hangs. Finally I changed the flush logic to fix this: 1) break flush into two steps; 2) cache drain frame during reload instead of during flush (the latter would cause another dead lock). The change is in 16ee618 |
Ideally there should be no need for having "drain frame". AviSynth+ should provide client API to individually flush their internal cache and stop prefetecher. Then we could simply stop the prefetcher during seek. Unfortunately there is no response for that request AviSynth/AviSynthPlus#180 |
Seeking is now much faster and smoother than it has ever been. However, after adding another prefetcher at the end i can still eventually cause a hang by holding the seek button down for several seconds.
I can even comment out OnCPU() as above and seek backwards and forwards in quick succession for the same result.
Yes, that is the expected behavior since as the (Google-translated) documentation states:
In other words, if i'm interpreting this right, the intended usage is basically: SourceFilter -> Prefetch() -> Filtering -> OnCPU() -> Prefetch() -> return last.
That's unsurprising, given i generally only start noticing a difference at over 85% CPU usage with fluctuating loads. PS. Now also seem to be getting a hanging issue with high CPU usage when switching subtitle-tracks with MPC-HC or PotPlayer. |
This works fine for me in AviSynth+ 3.6. In 3.5.1 it doesn't work due to single prefetcher limitation. What's the benefit of having multiple prefetchers instead of just increasing the thread count? |
This i only tested with AviSynth+ v3.6.2 (r3325) & MPC-HC (1.9.8) 32bit & 64bit. It generally took about 3 seconds of non-stop back and forth seeking to trigger. I'm not sure how often that hang would be encountered in normal usage, but i'm guessing it requires other prerequisite(s) such as a video containing at least one subtitle-track; i tried one without a subtitle and that worked fine.
I find that with Neo's Prefetch, one thread and more frames usually performs better. Having one at upstream and another at downstream can mitigate delays caused by bottle-necking from multiple filters. Optimized real world example could even end up looking something like this:
And yes, that's still usage as intended, according to what little documentation exists. PS. This build appears to be working correctly, but i'll test it for a few days and let you know if i encounter any new problems. |
I don't think it is good idea to ask users to spam |
Given that each filter can have it's own optimal setting for both Threads & Frames, it may not always be as simple as setting one Prefetch at the end, applying it for all filters above it and then forgetting about it. I have however personally observed a pattern that filters running in mtmodes 1 & 3 generally work well with just one thread and one frame per core; with filters requiring mtmode 2 or running on GPU things seem to become more complicated. For the final downstream cache at the end, a value equal to Renderer's frame-buffer/queue seems to be the optimal value. (Google-Translated) Documentation:
All that said, i think most of the time users will just end up copy-pasting Prefetch(1,4) or Prefetch(4) anywhere they detect a bottleneck, regardless of whether that's anywhere close to optimal for their script. |
I think most of the time users will just end up copy-pasting other people's code without understanding why, or just use tools like SVP. You are probably the 0.1% people who would ever put more than one Seriously, for most users, if they experience performance problem, they will just upgrade their 10 year old CPU and get immediate result, rather than scratching head to figure out how to optimally place prefetchers to squeeze out maybe 5% performance. |
I think that using AviSynth is more of a power-user thing to do in general. Searching for other people's code-snippets and figuring out where to paste them is in itself a fairly involved process. People with previous knowledge of AviSynth, use AviSynth; People with previous knowledge of Prefetch, use Prefetch, etc.
I think proper cache optimization can produce up to ~25% performance improvement at times. Very often the issue isn't raw computing power, but some old or poorly optimized filter effectively bottlenecking the CPU to ~60%. Upgrading hardware is an easy solution, but it doesn't always work as well as people hope it would, since old software is still going to run like old software and newer alternatives don't always exist or they require more computing power rather than less. |
I've noticed a few minor problems with switching tracks, but can't reliably reproduce most of them, however one exception is a semi-hanged state with >90% CPU usage after a subtitle or audio -track switch with PotPlayer; after seeking once the video starts playing back normally, but do anything else and it hangs completely. I copied the log at hang and then after seeking: PS. Using the splitter from LAV Filters seems to be a prerequisite for triggering a semi-hanged state by switching subtitles, but semi-hanging by switching audio tracks happens with other splitters as well. |
Yes, that fix should affect all use cases where a stop-and-play happens. If it does fix for you and chainikdn, I'll release a version for you guys. BTW, how did you notice an update on a non-participated closed issue? Were you subscribing to all tickets, or ... wait, are you ... actually the second account of chainikdn himself 😉 I'm kidding. |
The video-stream switch output glitch seems to be still happening with MPC-HC. I'm also getting a frame freeze on PotPlayer under the same conditions, Seems to require pretty specific circumstances to trigger; as multiple video streams isn't common, for me it's only happening with a test file i hastily put together with mkvtoolnix for debugging purposes. This specific issue is unlikely to be encountered in real use, but since there could be similar issues arising from the same source, i've uploaded a test clip here. I'm guessing the steps to reproduce go something like this:
After that the video might stick to glitched, still-frame or normal state and you might need to rename the file to (re-)trigger.
I've clicked the 'Watch'-button at the top of this project and configured GitHub to make email notifications for pretty much everything. |
Thanks for providing test clip. I have never seen a file with multiple video tracks. I repeated the steps using MPC-HC (which uses LAV) but I can't get green screen while getting SVP FRC effect. The only difference between the two video tracks are the resolution and the watermark at the black border.
But why? I never expect anyone to watch this repo for non-release stuff (except myself ofc) 😄 BTW, if you use AviSynth 3.5.*, never use more than 1 output thread. Otherwise it is not compatible with 3.5's one-prefetcher limitation. |
I'm planning on using AviSynth Filter as a component in a few future projects (if i decide to do them), as well as recommending it for running my realtime optimized SVPflow Templates. Thus i want to know about any new features, issues, bugs, fixes, technical details, etc. as soon as possible. Also, there are still a few minor problems i would like to figure out, including the one concerning some input-colorspace selections causing crashes and glitches on some systems including mine.
I generally don't use AviSynth+ builds prior to v3.5.2 (r3218) as most of my scripts aren't compatible with them; while troubleshooting i usually use the latest test build.
I tested with MPC-HC (v1.9.8) as as well as MPC-HC Portable (v1.9.7) with default settings, using MadVR & EVR (C/P), with this one line script: 'AvsFilterSource()', even 1 Output Thread and then... I think i figured it out: Looks like all bugs connected to the original issue have now been solved, so i'm closing the issue. |
Environment
or
Describe the bug
Player window hangs as a result of seeking with multiple prefetchers enabled. Simplifying the script seems to have increased the reproduction sensitivity over how it was with filters in between. With the full script i originally detected it with, difference between AviSynth Filter builds seemed more obvious, however it very well could have been present all along.
To Reproduce
Checklist
Did you try a different video player and check if the issue persist? For example, if your main video player is MPC-HC, try MPC-BE.
Answer: Yes.
Did you try a different video renderer and check if the issue persist? For example, if issue exists with madVR, try EVR.
Answer: Yes
Did you try a different video file and check if the issue persist? Try another file with different format, dimension and frame rate.
Answer: Yes
I'll describe the function and purpose of OnCPU & Prefetch (as i understand it) later on in another comment.
The text was updated successfully, but these errors were encountered: