dubhater / vapoursynth-mvtools

Motion compensation and stuff
181 stars 27 forks source link

Request for MScaleVect port #45

Open Boulder08 opened 4 years ago

Boulder08 commented 4 years ago

Would it be possible to have the smart MScaleVect functionality in Vapoursynth's MVTools as well? It can be used to speedup analysing by doing analysis on the original 8-bit clip and then using the vectors in high bit depth degraining etc. It would also make dct=5 usable, which helps with the quality of the vectors. In 16-bit analysis, it tends to slow things down quite a lot.

https://forum.doom9.org/showthread.php?p=1826390#post1826390

dubhater commented 4 years ago

What happens if you try to run Analyse on 8 bit video and Degrain on 16 bit video?

Boulder08 commented 4 years ago

No errors appear at least. I never thought trying that as it's always been a no-no to mix clips of different formats.. Some changes when comparing the results of 8-bit and 16-bit analysis and amplifying the change, but that is expected, of course.

clp = core.dgdecodenv.DGSource(source=r"whatever.dgi")
degrain16 = core.fmtc.bitdepth(clp, bits=16)

superanalyse8 = core.mv.Super(clp, pel=2, chroma=True, rfilter=4, sharp=1)
supermdg16 = core.mv.Super(degrain16, pel=2, chroma=True, rfilter=4, levels=1, sharp=1)

clp16 = core.fmtc.bitdepth(clp, bits=16)
superanalyse16 = core.mv.Super(clp16, pel=2, chroma=True, rfilter=4, sharp=1)

analyze_args = dict(blksize=32, overlap=16, search=5, searchparam=8, pelsearch=8, truemotion=False)
degrain_args_16 = dict(thsad=200, thsadc=100, limit=1*256, limitc=2*256, thscd1=300, thscd2=80)

bv1_8 = core.mv.Analyse(superanalyse8, isb=True, delta=1, **analyze_args)
fv1_8 = core.mv.Analyse(superanalyse8, isb=False, delta=1, **analyze_args)

bv1_16 = core.mv.Analyse(superanalyse16, isb=True, delta=1, **analyze_args)
fv1_16 = core.mv.Analyse(superanalyse16, isb=False, delta=1, **analyze_args)

finalclip8 = core.mv.Degrain1(clp16, supermdg16, bv1_8, fv1_8, **degrain_args_16)
finalclip16 = core.mv.Degrain1(clp16, supermdg16, bv1_16, fv1_16, **degrain_args_16)

result = core.std.MakeDiff(finalclip8, finalclip16)
result = core.std.Levels(result, min_in=125*256, max_in=132*256, min_out=0, max_out=255*256, planes=[0])

result.set_output()

So are you saying that code-wise, it should be safe to go without any problems with scaling values etc.?

Boulder08 commented 4 years ago

Original: original

Diffs: diffs

IFeelBloated commented 4 years ago

What happens if you try to run Analyse on 8 bit video and Degrain on 16 bit video?

VectorStructure::sad would be corrupted (invalid range).

Boulder08 commented 4 years ago

Is it something that should be immediately visible or just in some corner cases? I tried looking at different places in that test video but couldn't find anything totally strange.

Boulder08 commented 4 years ago

In fact, if the whole function seems too big to port, I think the bitdepth scaling would already cover most use cases easily without any noticable quality loss. In UHD resolutions, motion analysis at high bitdepth gets very slow and dct=5 is totally unusable.

adworacz commented 1 year ago

The actual code to do this isn't that complicated, if we use pinterf's version as an example: https://github.com/pinterf/mvtools/blob/mvtools-pfmod/Sources/MScaleVect.cpp

Should be easy for anyone to do, but I'll add this to my todo list. Might get to it sometime in 2023... ha