Log in

View Full Version : View VapourSynth Output in .NET


Pages : 1 [2]

MysteryX
13th June 2018, 15:23
AFAIK VapourSynth doesn't have any audio support. You can "hack" it into holding audio data but that's about it.

I'm using it to tune 440hz audio to 432hz audio, and then open those scripts in MPC-HC to tune video audios in real-time. I haven't seen any such feature in VapourSynth.

MysteryX
19th June 2018, 18:25
OK I got a nice media player UI (https://github.com/mysteryx93/MediaPlayerUI.NET) with seek bar, play/pause/stop. Was working around some multi-threading memory leak issues, which also caused clearOutput to crash. Now that's fine.

Now I'm having issues with vsscript_freeScript freezing the app when pressing Stop.


if (output != null) {
lock (outputLock) {
if (output != null) {
output.ClearQueue(null);
output.Dispose(); // Good
scriptApi.Dispose(); // Freeze
scriptApi = null;
}
}
}

// output
public void Dispose() {
VsInvoke.vsscript_clearOutput(apiPtr, nodeIndex);
Api.freeNode(nodePtr);
}

// scriptApi
public void Dispose() {
VsInvoke.vsscript_freeScript(scriptPtr);
}



Any idea?

Edit: It works if I stop while on Pause, so it has to do with pending frame requests. However, even waiting until the processing queue is empty before calling Dispose doesn't help.

If I'm on Pause, request one frame, display it, then click Stop to dispose of objects, everything is fine. If I have 1 thread while playing, click Stop, wait for that 1 request to callback, free the frame, then dispose of objects, it freezes on vsscript_freeScript.

Furthermore, if I click Pause then Stop, it works. If I call this before Stop (which should have the same action), it freezes.

Paused = true;
Thread.Sleep(500);
Stop();

MysteryX
19th June 2018, 23:54
I placed debug code on GetFrameAsync and on ReleaseFrame to see whether there's an unreleased frame that slipped by.

Every frame is released by the time I dispose of the script. I guess there's something else I'm missing then. What could it be?

MysteryX
20th June 2018, 04:44
I've uploaded the code for if anyone has an idea.

It is mostly between VsMediaPlayerHost.Stop
https://github.com/mysteryx93/VapourSynthViewer.NET/blob/master/WpfScriptViewer/VsMediaPlayerHost.cs#L249

and
VsOutput.GetFrameAsync_Callback
https://github.com/mysteryx93/VapourSynthViewer.NET/blob/master/VapourSynthViewer.NET/VsOutput.cs#L119

TheFluff
20th June 2018, 13:32
I may be missing something, but in Stop() you call ClearQueueWait(), which seems to be intended to clear the frame request queue and free all requested frames (since that's what ClearQueue does), but that method doesn't seem to actually do anything...? The setter for Pause does call ClearOutput, so that may explain things.

MysteryX
20th June 2018, 17:44
I can clear the processing queue but not all callbacks are triggered yet so there's not much I can do within Stop. I have to wait for callbacks to be triggered.

ClearQueue flushes the queue right away and subsequent callbacks are ignored because they're not found in the queue. Good for seeking. However, in the case of stop, this doesn't allow to know when all callbacks are done and frames are freed. As a work-around, I created a 2nd function that simply tells to stop refilling the queue and notify when it's empty.

(perhaps this might cause some issue if I seek and then stop immediately after, in some rare cases? Seek flushes 8 requests and puts 8 new requests in. Stop waits for those 8 new requests to be done. In a weird case where 1 flushed frame is returned after the 8 new frames are done, this could cause an issue, but that's very unlikely)

amichaelt
20th June 2018, 17:59
Maybe look at what VapourSynth Editor does when you seek in that program?

MysteryX
20th June 2018, 19:29
Maybe look at what VapourSynth Editor does when you seek in that program?
Seeking works no problem. Pause/Resume works no problem. Stop while on Pause works no problem.

Stop while playing "should" work as well, but it fails even if I call Pause in-code first.

(perhaps this might cause some issue if I seek and then stop immediately after, in some rare cases? Seek flushes 8 requests and puts 8 new requests in. Stop waits for those 8 new requests to be done. In a weird case where 1 flushed frame is returned after the 8 new frames are done, this could cause an issue, but that's very unlikely)
With conditional filters, some frames can take vastly longer time than others to process so I must fix this.

MysteryX
21st June 2018, 07:19
ok just adding "await Task.Yield()" fixed the freeze. Probably some concurrent actions didn't have time to run on the thread.

MysteryX
22nd June 2018, 05:04
How do I get Vapoursynth's installation path to find its DLL? From the registry I suppose?

Actually it seems I don't even need to specify the path, if I trust Windows will load the right files.

Mystery Keeper
22nd June 2018, 20:32
https://bitbucket.org/mystery_keeper/vapoursynth-editor
Study the source. It does many things.
API use, installation path discovery, async requests, preview - it's all there.

ChaosKing
22nd June 2018, 21:25
This is how I do a reg query in python to check for a VS installation.

import winreg
try:
aReg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
aKey = winreg.OpenKey(aReg, r"SOFTWARE\VapourSynth")
q = winreg.QueryValueEx(aKey, 'Plugins')
return q[0]
except Exception as e:
pass

return None

MysteryX
2nd July 2018, 18:45
I'm nearly done writing VapourSynth Multi-Viewer, a tool allowing to view multiple scripts side-by-side, while padding, zoom and seeking simultaneously in all tabs. This will make it easier to see which settings give the best results on the eyes. Zoom in the eyes, and switch between the various script versions.

However there's a math problem I haven't been been able to resolve; and some of you guys are really good with low-level math problems.

https://github.com/mysteryx93/EmergenceGuardian.WpfExtensions/blob/master/Controls/ZoomViewer.cs#L130

This adjusts scrollbar positions when zooming. Currently it maintains the top-left corner fixed when zooming in and out. Ideally I would want to maintain the center fixed when zooming in and out using keyboard, or keep the image under the mouse fixed when zooming using the mouse wheel. Any idea which formula would achieve that?

ChaosKing
3rd July 2018, 07:33
Something like this?
https://stackoverflow.com/questions/12794779/math-for-zoom-to-cursor-on-mouse-wheel-scrolling
https://gamedev.stackexchange.com/questions/9330/zoom-to-cursor-calculation

MysteryX
6th July 2018, 22:12
Something like that, but the variables are a bit different so it's still confusing. Got everything else working but this.