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 > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st May 2023, 12:24   #2501  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 605
Quote:
Originally Posted by StainlessS View Post
Thanks - and sorry for not seeing it in avisynth.nl wiki - at the time I was using the offline documentation html files that come with Avisynth which is out of date and doesn't mention those ones like VarExist and FunctionExists.
flossy_cake is offline   Reply With Quote
Old 21st May 2023, 13:22   #2502  |  Link
gispos
Registered User
 
Join Date: Oct 2018
Location: Germany
Posts: 996
Quote:
Originally Posted by DTL View Post
New version - https://github.com/DTL2020/ConvertYU...ases/tag/0.3.0

Now can take also 10..16bits YUV planar and convert to 8bit YV12 internally before processing.

With skipping ConvertBits(8) before YUV to RGB with one more full frame scan it also adds performance at out-of-cache frame sizes. If AVS can either have lots of ready to use SIMD functions inside for different conversions with single source scan or can dynamically compile required SIMD program for requested format conversion it can save from several host RAM read/writes for sequence of formats conversion and adds to performance.
That's great, the new version runs faster even with YUV420P16 than the previous one with only YUV420P8.
With the previous one I had to put a ConvertBits(8) in front.

Thanks for the new version!
A big improvement would be if the mod 64 could be scaled down.

I have a new Pre-Release that works with both DLL versions.
https://drive.google.com/drive/folde...usp=share_link
__________________
Live and let live
gispos is offline   Reply With Quote
Old 21st May 2023, 15:00   #2503  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,041
Here is attempt to process all widths - https://github.com/DTL2020/ConvertYU...ases/tag/0.3.1

It looks with 64 samples per pass it is not compatible with max mod64 bytes rows strides ? So the last columns up to 63 are processed with simple C-scalar program. At UHD frame 3840+60 width and at i3-9100T CPU it looks not add significant penalty -
3840 width 313 fps
3840+60 width 308 fps.

It is not tested with all possible frame widths so some bugs may happen.

"the new version runs faster even with YUV420P16 than the previous one with only YUV420P8. "

From ver 0.3.0 I set cs default to false as I see it typically make storing data faster and users may be lazy to test best setting of true/false at current host.

Last edited by DTL; 21st May 2023 at 15:04.
DTL is offline   Reply With Quote
Old 21st May 2023, 20:41   #2504  |  Link
gispos
Registered User
 
Join Date: Oct 2018
Location: Germany
Posts: 996
Quote:
Originally Posted by DTL View Post
Here is attempt to process all widths - https://github.com/DTL2020/ConvertYU...ases/tag/0.3.1
.
Wow! Wow! Wow! I can hardly believe it, excellently done!

Tried all dimensions and no error received so far.
4K ColorBar YUV420P10 with AvsPmod 'Resample Filter' and option 'Prefetch display conversion' resized to 1980 x 1080
runs in playback with ~153 fps shrunk to 1280 x 720 it is ~189 fps

ColorBar 1920 x 1080 YUV420P10 ~196 fps in the playback with display drawing.

I've spent a few hours optimizing everything, at least it was worth it.

Thanks!
__________________
Live and let live

Last edited by gispos; 21st May 2023 at 21:00.
gispos is offline   Reply With Quote
Old 27th May 2023, 11:46   #2505  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 605
Quote:
Originally Posted by StainlessS View Post
And see Gavino stuff here [try move as much code as you can out of Scriptclip script and into function].

Quote:
Originally Posted by Gavino View Post
string (as a whole) is created only once when the containing script is loaded. However, that string itself is parsed afresh on every frame, which means that any identifiers and string literals within it are repeatedly added to the string heap...this was the source of a memory leak in SRestore

The solution is to move the code inside the run-time script to another function, reducing the run-time script itself to a simple function call. This effectively eliminates memory problems, and also gives a speed increase.

In other words, instead of
Code:
ScriptClip("""
... very long script ...
""")
use
Code:
function f(... some params ...) {
  ... previous script code ...
}
...
ScriptClip("f(...)")
Unfortunately it appears the solution above requires ScriptClip(local=true) which doesn't allow messaging between frames, which I absolutely need.

So I am stuck with a huge memory leak - around 2MB/sec in my case

Is there perhaps some way to manually "clear the string heap"?
flossy_cake is offline   Reply With Quote
Old 27th May 2023, 12:50   #2506  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Is there perhaps some way to manually "clear the string heap"?
Nope, nuttin' at all, no mem is garbage collectable.

What are you trying to do, post what you attempted.

EDIT: You can still use globals even when Local = true.
Must use eg
Code:
Global SomeVar = WhateverVar
Trying to pass a 'Stored Frame", will fail after a few (hundred or thousand) frames, ie Huge mem usage.
(You are calcing current frame, based on previous frame, which is also based on frame before it, etc.
Not possible to just "throw away" prev temp frames as re-seek requires every frame before it to be available.)

EDIT:
I have tried many times (and find hard to accept the futility) to try find solution for what it is I think that you are trying to do,
even this attempt at solution failed.
FrameStore v0.03 - Avs+ x86/x64 - 15 Jan 2019
https://forum.doom9.org/showthread.php?t=175212
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th May 2023 at 13:08.
StainlessS is offline   Reply With Quote
Old 27th May 2023, 13:29   #2507  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 605
Quote:
Originally Posted by StainlessS View Post
What are you trying to do, post what you attempted.
This is leaking around 1.3MB/sec for 30fps video on my system (too big to paste on forum): https://pastebin.com/raw/pKfBJ26Q

This however produces no leak: https://pastebin.com/raw/PGWtzubz

But it won't allow runtime funcs like this:

Code:
ScriptClip( last,
\ function [] (c) {
	
	diff = YDifferenceToNext(c, -1)  # requires local=true, else error message
	c
	
} , after_frame=true, local=false)
If I set local=true then I lose the ability to message between frames:

Code:
global PrevFrameNumber = 0

ScriptClip( last,
\ function [] (c) {
	
	global PrevFrameNumber = PrevFrameNumber + 1  # doesn't work, just stays at 1
	c.SubTitle(String(PrevFrameNumber))  
	
} , after_frame=true, local=true)
Perhaps messaging could be done through frame properties instead.
flossy_cake is offline   Reply With Quote
Old 27th May 2023, 13:43   #2508  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Sorry, I aint got a clue about that new fangled "Function [] (c)" stuff, old dog and new trick thingy.

Quote:
Perhaps messaging could be done through frame properties instead.
Same, old dog, new tricks.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 27th May 2023, 13:52   #2509  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Is this what you are tryin' to do with that there new fangled stuff ?

Code:
/*
ScriptClip( last,
\ function [] (c) {
    # EDIT: "Plane Difference: this filter can only be used within run-time filters.
    diff = YDifferenceToNext(c, -1)  # requires local=true, else error message
    c

} , after_frame=true, local=false)
*/

Colorbars.Killaudio.ConvertToYV12

Function func(clip c) {
    diff = YDifferenceToNext(c, -1)  # EDIT: Works. Does NOT require local=true
    c.Subtitle(String(diff))
}

SSS = """
    func()
"""

ScriptClip( SSS , after_frame=true, local=false)
And
Code:
/*
ScriptClip( last, function [] (c) {
    global PrevFrameNumber = PrevFrameNumber + 1  # doesn't work, just stays at 1
    c.SubTitle(String(PrevFrameNumber))
} , after_frame=true, local=true)
*/


Colorbars.Killaudio.ConvertToYV12

Global PrevFrameNumber = 0

Function func(clip c) {
    Global PrevFrameNumber = PrevFrameNumber + 1  # EDIT: Works,  Does NOT stay at 1
    c.SubTitle(String(PrevFrameNumber))
}

SSS = """
    func()
"""

ScriptClip( SSS , after_frame=true, local=true)
EDIT: Both above WORK OK.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th May 2023 at 18:50.
StainlessS is offline   Reply With Quote
Old 27th May 2023, 21:01   #2510  |  Link
Rob105
Registered User
 
Join Date: Oct 2021
Posts: 43
Code:
path = "C:\Video\"

v0 = FFmpegSource(path + "video.mp4")

v1 = ImageSource(path + "Colors Gradient Horizontal 1920x1080.jpg", fps=50, end = 299).crop(0,980,0,0)
v2 = ImageSource(path + "BW Gradient Horizontal 1920x1080.jpg",     fps=50, end = 299).crop(0,980,0,0)

StackVertical(v0, v1, v2)
Avisynth open failure: StackVertical: image formats don't match

How do i make it work?

Source files https://www.upload.ee/files/15277223/video.zip.html
Rob105 is offline   Reply With Quote
Old 27th May 2023, 23:27   #2511  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 605
Quote:
Originally Posted by StainlessS View Post
EDIT: Both above WORK OK.
Hmm neither are working for me - I'm getting the same result as the previous samples. I copy pasted your exact code so I'm not sure what's going on. What version Avisynth are you using? I've got 3.7.3 (r3936, 3.7, x86_64).
flossy_cake is offline   Reply With Quote
Old 27th May 2023, 23:36   #2512  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
Quote:
Originally Posted by Rob105 View Post
How do i make it work?
Easy peasy lemon squeezy: a simple Converttoyv12() after you index the images will do it.

Code:
FFMPEGSource2("D:\video\video.mp4", fpsnum=50000, fpsden=1000, atrack=-1)

img1=ImageSource("D:\video\Colors Gradient Horizontal 1920x1080.jpg", fps=50, end=212).crop(0, 980, 0, 0).Converttoyv12()

img2=ImageSource("D:\video\BW Gradient Horizontal 1920x1080.jpg", fps=50, end=212).crop(0, 980, 0, 0).Converttoyv12()


StackVertical(last, img1, img2)




Explanation:

when you stack together different clips, they must all be the same, so you need to convert either the original video file you're indexing to reflect the two jpg you're trying to add on OR the other way around. In the example, I've done the opposite, so I've converted the two images to yv12 (4:2:0 planar 8bit).


I can now shut down my computer and go to bed :P
FranceBB is offline   Reply With Quote
Old 28th May 2023, 05:37   #2513  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by flossy_cake View Post
Hmm neither are working for me - I'm getting the same result as the previous samples. I copy pasted your exact code so I'm not sure what's going on. What version Avisynth are you using? I've got 3.7.3 (r3936, 3.7, x86_64).
v3.7.3(r3825,master, x86_64)

EDIT: Re-checked and both do work OK here.
Perhaps others with either version could verify results.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th May 2023 at 05:43.
StainlessS is offline   Reply With Quote
Old 28th May 2023, 06:11   #2514  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 605
Quote:
Originally Posted by StainlessS View Post
v3.7.3(r3825,master, x86_64)

EDIT: Re-checked and both do work OK here.
Perhaps others with either version could verify results.
Thanks, I tried a few other versions without luck. In the end I got it working by copying exactly what Gavino's SRestore does:

Code:
global count = 0

ScriptClip(last, "MyFunc(last, current_frame)", after_frame=true, local=false)

function MyFunc(clip c, int current_frame) {
    
	global count = count + 1	
	diff = YDifferenceToNext(c, -1)
	c.SubTitle(string(diff) + ", " + string(count))
}
Passing current_frame to MyFunc is what makes it work for me, otherwise I get "this filter can only be used within run-time filters".

Hopefully there is no other weird side effect of doing it this way, but I've got a feeling it's going to be weird about something.
flossy_cake is offline   Reply With Quote
Old 28th May 2023, 11:17   #2515  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Also, the first of the scripts [works for me, not for you], kinda surprised me,
I was under the impression that current_frame did not survive when calling a function,
stangely it worked for me in that script where I might have expected it not to.
[perhaps something strange in the version I'm currently using].

Quote:
Passing current_frame to MyFunc is what makes it work for me, otherwise I get "this filter can only be used within run-time filters".
Yep, I posted similar in Usage a little while ago.
https://forum.doom9.org/showthread.p...42#post1986042
Quote:
Originally Posted by StainlessS View Post
Current_frame is not available outside of the runtime environment, and dont make much sense there either.
But, (probably not of use in required case) you can hack a one time use (on a single frame) just by setting
it to that frame number, eg

Code:
blankclip(length=100,pixel_type="YV12")
C = Last.BlankClip(length=0) # zero len clip, same characteristics as Last clip
For(n=0,FrameCount-1) {
    current_frame = n # HACK for below AverageLuma
    Y = AverageLuma # access frame n
    T = Trim(n,-1)
    T = T.Subtitle(String(n) + String(Y," : %f"),align=5)
    C = C ++ T  # add single frame n, to clip so far
}

C # Play C
current_frame is set only for use within runtime (eg by ScriptClip) where it is initialised before each frame that is processed by
the script arg of Scriptclip. Hacking current_frame to some number just allows to use some runtime func (eg AverageLuma), on that SINGLE frame.

EDIT:
Nuther script of limited use
Code:
blankclip(length=100,pixel_type="YV12")

Function SomeFunc(clip c, int n) { # Dont think current_frame is visible within this func, but can be provided by caller in n
    current_frame = n
    Y = c.AverageLuma
    Return Y
}

SSS="""
    Y = SomeFunc(Last,current_frame)
    return Subtitle(String(current_frame) + String(Y," : %f"))
"""

ScriptClip(SSS)
# ...
EDIT:
Code:
Function SomeFunc(clip c, int current_frame)
Does not taste quite right to me, so I used an int n then assigned to current_frame internal to function.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th May 2023 at 11:32.
StainlessS is offline   Reply With Quote
Old 28th May 2023, 17:06   #2516  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by StainlessS View Post
Also, the first of the scripts [works for me, not for you], kinda surprised me,
I was under the impression that current_frame did not survive when calling a function,
stangely it worked for me in that script where I might have expected it not to.
[perhaps something strange in the version I'm currently using].
Are you using GRunT's ScriptClip()?
In GRunT (unlike vanilla Avisynth 2.x), current_frame is a global variable (though still of course only visible inside the run-time environment).
Avs+ has incorporated some functions of GRunT, but I'm not sure if this one applies there.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 28th May 2023, 22:31   #2517  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Are you using GRunT's ScriptClip()?
Yep, renaming Grunt.dll so as not to use it,

1st script produces error report.

2nd script, shows subtitle '1' for all frames.

Cheers Gavin. [nice Welsh name].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 28th May 2023, 23:26   #2518  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,041
Made new version of converter to RGB32 - https://github.com/DTL2020/ConvertYU...ases/tag/0.4.0

It is finally more correct processing in 16bit intermediates and in narrow range the resudual error only about +1LSB. After gained to Full range - at some colours may reach error of 2LSB.

Also when compared to ConvertToRGB32(matrix="PC.709") it was found that matrix (coefficients ?) in AVS core is somehow broken:

At script:
Code:
ColorBarsHD(640, 480, pixel_type="YV24")
ConvertToYV12()

ConvertToRGB32(chromaresample="point", matrix="PC.709")
Output for colours (R,G,B):
Yellow 181, 180, 12
Cyan 12, 181, 180
Green 13, 181, 12
Magenta 183, 15, 184
Red 184, 15, 16
Blue 15, 16, 184

The DecodeYUVtoRGB with narrow range mapping (gain=64 and offset=16) keep output in 15..17 and 179..181 range. It was found with math simulation the 8bit YUV can not be decoded to ideal 16 and 180 RGB at all colours because or already rounding errors in 8bit YUV. So only with 10bit and more it can be reach ideal 16 and 180 levels output.

Also added 32bit immediates processing mode - it run 2+ times slower at AVX2 and provide only slightly better precision in the Full range mapping (error looks like +-1LSB). And close to no better in narrow range. So it looks 32bit immediate processing only required for >8bit sources and results. And can make a bit better precision with 8bit output only if input is >8bit.

For some possible future of fastest 16bit immediate processing engine for YV12 to RGB32 it is possible to play with coefficients tweaking and rounders tweaking and may be reduce average error over all possible range of YUV input 8bit values - using some math simulator engine. But it require programmer of such optimizing engine.

Also added x86_32 build if someone still use 32bit Windows. It runs only slightly slower (register file size in 32bit CPU mode is 1/2 of size and compiler make more data temporal store/load from cache).

Last edited by DTL; 28th May 2023 at 23:31.
DTL is offline   Reply With Quote
Old 29th May 2023, 01:08   #2519  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,153
First time for 32 bit from DTL
kedautinh12 is offline   Reply With Quote
Old 29th May 2023, 03:00   #2520  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Note that "PC matrices" are not quite the same thing as "Studio RGB", or "limited range RGB" used in broadcast or some NLE's

The equivalent way in avisynth as what's used a Studio RGB NLE (like vegas) for 8bit for that example above would be

Code:
ColorBarsHD(640, 480, pixel_type="YV24")
ConvertToYV12()
Levels(0,1,255,16,235, coring=false)
ConvertToRGB32(chromaresample="point", matrix="rec709")
Y 180,179,16
C 16,181,179
G 16,179,14
M 179,16,181
R 180,16,17
B 15,16,180

There was an old dedicated "studio RGB" function by "trevlac" for avisynth


EDIT:
It should be coring=false . Limiting (for example 0,255) is separate . Nominal Black to white is defined as 16 to 235 for studio RGB, but you can have superblack, superwhite . If you clip it in the levels (coring=true), you never get superblack or superwhite

Last edited by poisondeathray; 31st May 2023 at 05:10.
poisondeathray 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 20:32.


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