Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th June 2018, 02:21   #41  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Thanks, very useful explanation. Should be easy enough to implement in .NET, it makes multi-threading very easy.
MysteryX is offline   Reply With Quote
Old 9th June 2018, 06:58   #42  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Now it's working in MT ... BUT, it takes a ridiculous amount of memory and fills up 8GB within seconds.

After calling getFrameAsync, are there other functions to call to release resources while processing?
MysteryX is offline   Reply With Quote
Old 9th June 2018, 11:39   #43  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
I guess you're not freeing the frames after you're done using them.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 9th June 2018, 17:52   #44  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Quote:
Originally Posted by jackoneill View Post
I guess you're not freeing the frames after you're done using them.
Was searching "release" in the API and couldn't find anything but freeFrame does the job thanks.

MT is working. I'm calling SetThreadCount(8) send 8 frame requests, and each time a frame is done I add a new one into the queue. Now the CPU still runs only at 40%.

When I call GetFrameAsync on my class, it returns the frames in the same order they were requested so that's working very well.
MysteryX is offline   Reply With Quote
Old 9th June 2018, 21:40   #45  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Is your script complex enough to fully use the CPU?

There is no guarantee you will receive the frames in order. You have to handle reordering them.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 10th June 2018, 00:57   #46  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Code is already written to reorder them. My VsOutput class raises 2 events: FrameDone (when frame is processed, to insert new request into the queue) and FrameReady (for display, guaranteed to be in right order). That's working well.

I see that if I skip display code, it runs MUCH faster; but still, it only runs at 40% CPU. There's only FFM2 in the script so far, maybe it's not designed to run faster than that.
MysteryX is offline   Reply With Quote
Old 10th June 2018, 05:39   #47  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
With only reading or writing plugins, you're probably I/O bound more than anything.
foxyshadis is offline   Reply With Quote
Old 12th June 2018, 04:21   #48  |  Link
amayra
Quality Checker
 
amayra's Avatar
 
Join Date: Aug 2013
Posts: 284
just out of curiosity what is your goals with this ?
__________________
I love Doom9
amayra is offline   Reply With Quote
Old 12th June 2018, 20:42   #49  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Looking to replace Avisynth with VapourSynth in my Yin Media Encoder that goes with the Natural Grounding Player for video processing, and use Avisynth only for audio processing.

Could also add nice features like previewing various versions of a script side-by-side by switching tabs, zooming in, and seeking/scrolling simultaneously in all tabs. This would be better than simply opening up a script in MPC-HC.

I'm also switching into using MPV via dll instead of Windows Media Player for audio and video playback; working on an UI right now because all these alternative media players have no decent UI.

Last edited by MysteryX; 12th June 2018 at 20:53.
MysteryX is offline   Reply With Quote
Old 13th June 2018, 07:46   #50  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
What holds you back from VS audio processing?
foxyshadis is offline   Reply With Quote
Old 13th June 2018, 15:23   #51  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
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 is offline   Reply With Quote
Old 19th June 2018, 18:25   #52  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
OK I got a nice media player UI 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.

Code:
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.
Code:
Paused = true;
Thread.Sleep(500);
Stop();

Last edited by MysteryX; 19th June 2018 at 20:17.
MysteryX is offline   Reply With Quote
Old 19th June 2018, 23:54   #53  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
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 is offline   Reply With Quote
Old 20th June 2018, 04:44   #54  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
I've uploaded the code for if anyone has an idea.

It is mostly between VsMediaPlayerHost.Stop
https://github.com/mysteryx93/Vapour...erHost.cs#L249

and
VsOutput.GetFrameAsync_Callback
https://github.com/mysteryx93/Vapour...Output.cs#L119
MysteryX is offline   Reply With Quote
Old 20th June 2018, 13:32   #55  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
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.
TheFluff is offline   Reply With Quote
Old 20th June 2018, 17:44   #56  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
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)
MysteryX is offline   Reply With Quote
Old 20th June 2018, 17:59   #57  |  Link
amichaelt
Guest
 
Posts: n/a
Maybe look at what VapourSynth Editor does when you seek in that program?
  Reply With Quote
Old 20th June 2018, 19:29   #58  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
Quote:
Originally Posted by amichaelt View Post
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.

Quote:
Originally Posted by MysteryX
(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 is offline   Reply With Quote
Old 21st June 2018, 07:19   #59  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
ok just adding "await Task.Yield()" fixed the freeze. Probably some concurrent actions didn't have time to run on the thread.
MysteryX is offline   Reply With Quote
Old 22nd June 2018, 05:04   #60  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
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.

Last edited by MysteryX; 22nd June 2018 at 05:35.
MysteryX is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.