CrendKing / avisynth_filter

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

Playback freezes on some content after a few frames #24

Closed mark007 closed 3 years ago

mark007 commented 3 years ago

Environment

Describe the bug

An issue which I assume also somehow related to the frame queue/cache. When madVR is set (as I have it set) to "delay playback start until render queue is full", and "delay playback start after seeking, too", sometimes (perhaps 50% of the time, but I can't find a pattern), when starting some videos, the image plays a few frames and then freezes. I have gpu and cpu queue set at 16 now. The audio continues in the background fine.

Manually seeking in the file, restores video playback.

Changing display modes (by double clicking madVRs image and letting it change my desktop from default of 60 to 48hz) seems to completely stop the audio.

This clip is an interlaced clip that I'm using LAV Video Yadif to de-interlace to double its original frame rate. (its a live performance of Lady Gaga Born This Way titled "Born This Way - 2011(HDTV-1080).mpg")

This occurs without SVP enabled (exited from the system tray completely), so avisynthfilter in this case has no actual avisynth script to process.

To Reproduce

  1. Play clip
  2. Wait about 0.5 seconds
  3. The image freezes but audio continues

Checklist

mark007 commented 3 years ago

avisynth_filter.zip Log attached.

CrendKing commented 3 years ago

If only one video file has the issue, I'll need that file. Don't upload copyrighted videos here though.

mark007 commented 3 years ago

If only one video file has the issue, I'll need that file. Don't upload copyrighted videos here though.

sent you a PM on doom9 with a sample @CrendKing

CrendKing commented 3 years ago

I can't legally download videos from torrent sites. I tried interlaced videos from https://forum.videohelp.com/threads/388984-How-to-best-de-interlace-and-work-this-samples-out with the same setup in LAV and madVR. Can't cause any crash or freeze.

If you can find un-copyrighted video that has the symptom, please let me know.

CrendKing commented 3 years ago

I tried my best to replicate your setup, but I can't get any freeze. The only things I don't have are madVR beta 114, which I can't find and thought it is some dynamic tone mapping data on top of 0.92.17, and XySubFilter which I don't think matters since the video has no subtitle. There's about 0.5 second delay at beginning, but never completely freeze. Also, your log file shows everything was working as expected. Could be a madVR bug. Try with the stable version.

Nuihc88 commented 3 years ago

I got curious and did a quick search for the beta version of MadVR and found the following link:

http://madshi.net/madVRhdrMeasure114.zip

Haven't tested it myself, but it seems to contain the aforementioned binaries.

CrendKing commented 3 years ago

Thanks. But that version seems only change some HDR stuff, unrelated to seemingly freezing problem. If that version introduces the freeze, the bug should be reported to madVR.

mark007 commented 3 years ago

I have gone back to the latest stable madVR version now, 0.92.17, but it persists for this clip. I will see if madshi can take a look, but as this is the first filter that has ever exhibited an issue like this with madVR for me, I'm really not sure where to take it. Its one of those strange ones that's a combination of multiple factors, maybe multiple filters that causes it.

CrendKing commented 3 years ago

BTW, if you remove avsf from the graph, would it never freeze? What if you add ffdshow raw video filter to the graph (let it do some seemingly harmless work, such as cropping)?

mark007 commented 3 years ago

Yeah I have removed it from the graph and reinstalled ffdshow 64 4531 and added the ffdshow raw video filter to the external filters. I can see SVP actually updating ffdshows avisynth section and ticking the box for avisynth when playback starts. I also enabled blurring, and tried a few different back / forward buffer sizes in the avisynth section, as I suspect (as a non filter developer of course) that its somehow related to frames/buffers/timestamps somehow.

I can't reproduce the issue with ffdshow however.

Perhaps another clue in case you didn't try it. When using LAV Video Decoder make sure you have YADIF deinterlacing enabled (I know I mentioned that before as being part of it) but make sure its on 50p/60p mode, not 25p/30p mode. It only happens with 50p/60p mode. Is the splitter reading the original framerate of 30 in this case and not reading the updated 60 fps framerate coming from YADIF doubling the framerate.

CrendKing commented 3 years ago

Am I missing anything?

1 2 3 4

mark007 commented 3 years ago

Thank you for trying.

Ahhh actually there was one remaining difference in my settings and yours, and it was the queue sizes. With 16/16 its working perfectly with no freezes, but not at 12/12. With the hardware D3D11 decoder the player actually just closes. With software decoding which I normally use in LAV Video, the player doesn't close, so I can still hear the audio continue, but no video.

What I see on the avisynth filter status page when the freeze happens (and when in LAV Video Software decoding mode which doesn't close the whole player), it consistently shows the following at the point of the freeze. Whether this means anything in particular, or gives a clue I'm not sure.

Frame Numbers: 580 -> 578 -> 578 Input buffer size: 2 Output buffer size: 0

I have tried other madVR queue sizes, down as far as 14 works. As soon as I put both at 13 it starts to freeze at this same frame.

Its the cpu queue that seems to matter. Setting the GPU queue to 4 and CPU queue to 14 all is fine, but GPU queue at 4, and CPU queue at 13 it freezes.

Trying other combinations, here's the results

CPU queue 4, GPU queue 4: PASS always CPU queue 5, GPU queue 4: FAIL sometimes CPU queue 6, GPU queue 4: PASS always CPU queue 12, GPU queue 4: FAIL always CPU queue 13, GPU queue 4: FAIL always CPU queue 14, GPU queue 4: PASS always

CrendKing commented 3 years ago

I managed to reproduce the crash/freeze with this extremely specific setup. Some CPU queue size from madVR trigger crash, as you documented, with 14 as the threshold number. And there is a format change after the 15th frame. GPU queue size or AviSynth version don't seem matter.

Interestingly, if I insert ffdshow in between LAV and avsf, the crash is gone. Log file shows the difference is that the format change is gone.

I can debug this further and update this comment later, but my initial thought is that this is more likely a bug of madVR handling the combination of events (delay for buffer fill, CPU queue size, format change and deinterlace).

CrendKing commented 3 years ago

Here is what I discovered so far. When using LAV with your specific setup, after the 15th source frame, it will issue a input format change. avsf will deliver the format change to downstream, which is madVR. If madVR gets this format change BEFORE the CPU queue is full (with the delay option enabled), it freezes.

Now the explanation of why some CPU queue sizes work. Internally, avsf has a buffer size, let's call it X. Currently it is hardcoded as 8. avsf can queue up to this number of source frames ahead of output frames. So assuming the madVR CPU queue size is Y, the math for not freezing is:

X + Y < 15

In my test, every Y that is less than or equal to 6 does not freeze. When X == 8 and Y == 7, it freezes. If I adjust X to a smaller number such as 7, and increase Y to 8, it also does not freeze. There is a minimum requirement of X equal to 3. So once I increase Y to 12, it always freezes.

Since this bug requires specific configs of at least 2 filters (LAV and madVR), and a specific video. I don't think the root problem is in avsf until further evidence. I'll close for now.

CrendKing commented 3 years ago

I figured out a way to fix this. Now madVR will not freeze. However, EVR still rarely freezes for some reason. But since we don't have EVR's source code or debug symbol, I guess we won't know why.

avisynth_filter_64.zip

CrendKing commented 3 years ago

Fixed in https://github.com/CrendKing/avisynth_filter/releases/tag/v0.10.0

mark007 commented 3 years ago

Fixed in https://github.com/CrendKing/avisynth_filter/releases/tag/v0.10.0

Thank you for the fix!