Selur's Little Message Board

Full Version: Accessing parameters of TemporalDegrain2 in Hybrid
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I am new to this forum, but I have played around with Hybrid for a while. Since I find it very tiresome and error-prone to use software like AviSynth from the command line, I am happy to have tools like StaxRip or Hybrid. For my particular project (description following below) I have found that Hybrid performs about 10 times faster than StaxRip, so I would like to optimize my use of Hybrid; but I would need a bit more information how to do use it properly.

Many years ago I had some Super 8 movies transferred in very good quality to digital video, on miniDV tape cassettes, i.e. D1 AVI, 720x576, 25fps interlaced. There is no need for a higher resolution, because the film grain of the Super 8 material determines and limits the sharpness and Full HD would not improve it.

However, interlacing is the problem because in the interlaced material I cannot access individual frames to retouch artefacts like dust or hairs, so one of the many steps in my workflow it deinterlacing with QTGMC (in Hybrid), converting interlaced AVI to progressive MP4. Hybrid always aborts this process in the first attempt, but the job sits in the queue with the status WAITING, can be started from there and will complete without any further issues, so this is not my actual problem.

The problem comes at a later stage, once I have completed my single-frame retouching and try to degrain the cleaned MP4 video using TemporalDegrain2 in Hybrid. Hybrid aborts the process consistently when I try using the AviSynth version, so I have to resort to the Vapoursynth version; and as discussed in this thread by Lipomo, the two versions are different. The TemporalDegrain2 documentation lists only 11 parameters that may be used to control the results:
  • degrainTR
  • grainLevel
  • grainLevelSetup
  • postFFT
  • postSigma
  • postDither
  • degrainPlane
  • outputStage
  • postMix
  • fftThreads
  • postSigmaC
No other parameters should be touched.

However, the parameter sets that are made available in the Hybrid GUI under (a) x264 > Filtering > Avisynth > Grain > TemporalDegrain 2 and (b) x264 > Filtering > Vapoursynth > DeGrain > TemporalDegrain2, are different from each other and do not correspond to those 11 parameters, as shown in these screenshots (green: parameter identified; red: parameter not identified).

[attachment=3399]
[attachment=3400]

I would need to access some of the parameters that are not included in this GUI. So here is my question: As a workaround, is it possible to specify the TemporalDegrain2 filter for Vapoursynth in Hybrid directly, i.e. by replacing the automatic call with in Hybrid with something like "TemporalDegrain2 (degrainTR=1, grainLevel=0, postFFT=1, postSigma=0, outputStage=1, postMix=25)"?

Thank you! 

ThoM
Quote:Hybrid aborts the process consistently when I try using the AviSynth version,
You didn't care to share a debug output or the error message the Avisynth Preview produces, so nothing I can say about that.

Quote: The TemporalDegrain2 documentation lists only 11 parameters that may be used to control the results: ... No other parameters should be touched.
*gig* That is the beauty of it. Personally, I don't use most of these, but those that should not be touched. Smile


The Avisynth TemporalDegrain2 version that Hybrid uses has this signature:
Code:
function TemporalDegrain2 ( clip input, int "degrainTR", int "grainLevel", bool "grainLevelSetup", int "degrainPlane", int "postFFT", float "postSigma", int "postDither", int "fftThreads", int "postTR", int "postMix", int "postPlane", int "postBlkSz", int "meAlg", int "meAlgPar", int "meSubpel", int "meBlksz", bool "meTM", bool "meChroma", int "limitFFT", float "limitSigma", int "limitBlksz", int "devId", float "ppSAD1", float "ppSAD2", float "ppSCD1", int "thSCD2", int "DCT", float "gaussParam", bool "extraSharp", int "outputStage", bool "debug", bool "CUDA", string "dftsfile", int "postFFTc", float "postSigmaC", bool "degrainChromaTwoStep", bool "degrainAvoidChromaShift")
see: Hybrid/64bit/TemporalDegrain2.avsi on your system.
So all your options are present. Smile
Aside from
  • grainLevelSetup
  • postMix
  • postSigmaC
all are available in the gui.
The Vapoursynth version has this signature:
Quote:def TemporalDegrain2(clip, degrainTR=1, degrainPlane=4, grainLevel=2, grainLevelSetup=False, meAlg=4, meAlgPar=None, meSubpel=None, meBlksz=None, meTM=False,
limitSigma=None, limitBlksz=None, fftThreads=None, postFFT=0, postTR=1, postSigma=1, postMix=0, postBlkSize=None, knlDevId=0, ppSAD1=None, ppSAD2=None,
ppSCD1=None, thSCD2=128, DCT=0, SubPelInterp=2, SrchClipPP=None, GlobalMotion=True, ChromaMotion=True, rec=False, extraSharp=False, outputStage=2, neo=True)

Vapoursynth version does not have 'postDither', 'postMix', 'postSigmaC' options and 'outputStage' is not supported in the gui. (hope I didn't miss anything)
If you know a better port of TemporalDegrain2 to Vapoursynth let me know and I may add support for it in Hybrid.


Quote: As a workaround, is it possible to specify the TemporalDegrain2 filter for Vapoursynth in Hybrid directly, i.e. by replacing the automatic call with in Hybrid with something like "TemporalDegrain2 (degrainTR=1, grainLevel=0, postFFT=1, postSigma=0, outputStage=1, postMix=25)"?
No. You can't replace or modify the generated code. I might could add a 'additions'-option or something like that, which would allow you to add additional parameters, some time in the future.
You can however:
a. use the 'Custom'-section to add your own code where you could call TemporalDegrain2 with whatever paramters you like.
b. you could add your own 'Custom script/filter additions' to the gui. read: Custom script/filter additions? and look inside the Hybrid/CustomSynthScripts for some examples that are included this way in the gui.

Cu Selur

Ps.: If you want help to fix the Avisynth issue, read the sticky and provide a debug output of you calling Avisynth Preview with your settings, this should produce an error and include the script in the debug output.
(27.11.2025, 16:32)Selur Wrote: [ -> ]If you know a better port of TemporalDegrain2 to Vapoursynth let me know and I may add support for it in Hybrid.
very interested on this.
Wow, that was a really fast reply! 👍🙂
I did not attach debug data at first because I got it working with the Vapoursynth version; but since you seem to have the time to look into this, here comes some documentation ... 😉

I am attaching a video with a short sample of two scenes as well as some Hybrid log outputs; the numbers refer to the various stages of my workflow:
1 - Original AVI source.
2 - Deinterlacing with QTGMC in Hybrid; the log shows that Hybrid aborted, but could be restarted from the WAITING state. This step already removed some of the excessive grain. Using a very high bit rate to minimise quality loss in the many workflow steps.
3 - Creating a sequence of PNG frames using FFMPEG and retouching many of them.
4 - Using FFMPEG again to recombine the retouched PNG frames to the attached MP4.
5 - Applying TemporalDegrain2 in Hybrid to remove the remaining grain without losing too much structure and clarity. The log shows that this did not work at all in the Avisynth version, whereas it worked well in Vapoursynth.

My problem is the loss of detail in larger areas like the road surface, e.g. towards the end, top left. The subsequent MP2 coding for DVD authoring will remove even more small features, creating just a cloudy area without any detail, so I would like to reduce the strength of the degraining even further. Maybe it will be sufficient to use the less aggressive settings listed in the TemporalDegrain2 documentation; if that is not enough, they suggest using outputStage and postMix, but these are not available in the GUI. So I will try your "Custom" suggestions to access those options when I find the time.

Thank you!
About the workflow:
1. ideally use a lossless format, when using x264 in lossy mode, you might want to use 10bit encoding.
2. "Using FFMPEG again to recombine the retouched PNG frames to the attached MP4." you are aware that you can load an image sequence into Hybrid right? (the ffmpeg step seem unnecessary)

Looking at the Avisynth step, the script seems fine:
Code:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\LoadDll.dll")
LoadDLL("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\d3d9.dll")
LoadDLL("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\libfftw3f-3.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\LSMASHSource.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\neo-dfttest.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\KNLMeansCL.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\dither.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\RgTools.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\mvtools2.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\FFT3dGPU.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\neo-fft3d.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\hqdn3d.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\masktools2.dll")
LoadPlugin("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\ConvertStacked.dll")
Import("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\mtmodes.avsi")
Import("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\TemporalDegrain2.avsi")
Import("C:\Program Files\Hybrid\64bit\Avisynth\avisynthPlugins\dither.avsi")
# loading source: E:\Daten\Filme\2025\KurzFilmFestival\Video\Footage\4_MP4_PR_GRN_RET\4_Retouched.mp4
# color sampling YV12@8, matrix: bt601, scantyp: progressive, luminance scale: limited
LWLibavVideoSource("E:\Daten\Filme\2025\KurzFilmFestival\Video\Footage\4_MP4_PR_GRN_RET\4_Retouched.mp4",cache=false,format="YUV420P8", prefer_hw=0,repeat=true)
# current resolution: 720x576
TemporalDegrain2(degrainTR=0,grainLevel=0,postSigma=0)
# setting output fps to 25.00000fps
AssumeFPS(25,1)
PreFetch(8)
#  output: color sampling YV12@8, matrix: bt601, scantyp: progressive, luminance scale: limited
return last
the encoding call:
Code:
"C:\Program Files\Hybrid\64bit\ffmpeg.exe" -y -loglevel fatal -noautorotate -nostdin -threads 8 -i "C:\Users\Thomas Mechau\AppData\Local\Temp\encodingTempSynthSkript_2025-11-28@12_38_47_1810_0.avs" -an -sn -pix_fmt yuv420p -fps_mode auto -r 25/1 -f rawvideo - | "C:\Program Files\Hybrid\64bit\x264.exe" --pass 1 --slow-firstpass --bitrate 24400 --profile high --level 5.1 --direct auto --b-adapt 0 --sync-lookahead 24 --qcomp 0.50 --qpmax 51 --partitions i4x4,p8x8,b8x8 --no-fast-pskip --subme 5 --trellis 0 --weightp 1 --aq-mode 0 --sar 16:15 --non-deterministic --range tv --stats "C:\Users\Thomas Mechau\AppData\Local\Temp\5_TemporalDegrain2_Avisynth_1_2025-11-28@12_38_47_1810_02.stats" --demuxer raw --input-res 720x576 --input-csp i420 --input-range tv --input-depth 8 --fps 25/1 --output-depth 8 --output "C:\Users\Thomas Mechau\AppData\Local\Temp\5_TemporalDegrain2_Avisynth_1.264" -
does seem to be fine too.
I would recommend to change temp-path to something outsice of 'AppData' and direct Windows folders and add an exemption to whatever virus scanner you are using.

According to the debug output the decoder crashes. So it either something with the script, Avisynth Preview should then show an error, or the deocidng call.
Please try:
a. does the Avisynth Preview work?
b. does enabling 'Config->Internals->Avisynth->Prefer FFmpeg as decoder' fix the problem?
If the Avisynth Preview already crashes, it might be a problem with one of the filters and your hardware setup. (I suspect it's fft3dgpu, since it's the only gpu filter that is really used with your settings and it's not used in Vapoursynth since it doesn't exist there.)
Using a similar script (same filters&co, different paths), I have no problems here.

Quote:My problem is the loss of detail in larger areas like the road surface, e.g. towards the end, top left. The subsequent MP2 coding for DVD authoring will remove even more small features, ...
a. for my taste you use too many loss encoding steps.
b. try adding CAS with 0.7 strength before the denoising; maybe even use it after the encoding in the first step,... (you need to adjust the filter order for this)
c. If you want to lower the strength of the degrain use another filter. I would use SMDegrain or MCDegrainSharp instead of TemporalDegrain2 on such a source, for my taste the source is not grainy enough to use TemporalDegrain2.
(personally, I would also use a deblocker and maybe denoise the darker areas a bit)

Quote:they suggest using outputStage and postMix, but these are not available in the GUI.
Personally, I never use outputStage, which is why it's not offered in the gui, since in my experience in those case where it might make sense, usually using another filter is a better approach. For a degrain filter, TemporalDegrain2 is a rather strong filter by design,...

Cu Selur
Thanks a lot! That has been quite a bit of information to digest – and so I have not found the time to dive into this earlier.

This whole project has been keeping me busy for decades; I have researched a lot and worked out my own solutions. It's a pity that I did not come across Hybrid and this forum a bit earlier; maybe you could have helped me saving some time and trouble ... 😉

But let’s take this one step at a time ...

Quote:1. ideally use a lossless format, when using x264 in lossy mode, you might want to use 10bit encoding.
What lossless format would you recommend? I am using x264 with a bit rate of 24,400 Kb/s, and in the original workflow step to assemble the retouched single frames to MP4 (which can be left out, as you have pointed out, see (2.) below), I was using -c:v libx264 -crf 16, which should deliver a very high quality.
Where can I specify 10-bit encoding?

Quote:2. "Using FFMPEG again to recombine the retouched PNG frames to the attached MP4." you are aware that you can load an image sequence into Hybrid right? (the ffmpeg step seem unnecessary)
Thanks for the tip – in fact, I was not aware of this, and you are right: This can streamline my workflow considerably.

Quote:I would recommend to change temp-path to something outsice of 'AppData' and direct Windows folders and add an exemption to whatever virus scanner you are using.
Actually there seems to be a real problem with my Hybrid installation or with Hybrid in general. I installed the program 3 or 4 times on different (non-C: ) drives and in different folders and specified all sorts of path names
[attachment=3467]
but no matter what, after closing and re-starting Hybrid the result is always the same: All path settings are blank (so the user log complains that the "Default output" path is empty)
[attachment=3468]
except for the "Default temp" path, which points to ...AppData\Local\Temp; and "Generate debug file" is unchecked. This means I can't permanently change the Temp folder.

(By the way, your instruction page about "infos needed to fix and reproduce bugs" is a little outdated (from 2017) and does not reflect that the Path settings now include a dedicated "Debug output path" in addition to the "Default output path" (for the video output?). But this does not matter so much because any path specified here will be reset after the next program start.)

Anyway – no matter what I try, specifying AviSynth reliably fails.

Quote:a. does the Avisynth Preview work?
It does.

Quote:b. does enabling 'Config->Internals->Avisynth->Prefer FFmpeg as decoder' fix the problem?
It is already enabled by default.

But all this is not a real issue because the VapourSynth version works satisfactorily.

Quote:c. If you want to lower the strength of the degrain use another filter. I would use SMDegrain or MCDegrainSharp instead of TemporalDegrain2 on such a source, for my taste the source is not grainy enough to use TemporalDegrain2.
Most of my DV footage has the rather high quality as shown, but I have some with much worse grain (coming from a different transfer service provider or from high-speed Super 8 stock); and for those, TemporalDegrain2 works best. But for my high-quality material, SMDegrain is working magic; I am now tweaking its settings to deliver the best results – so thank you very much for these recommendations!
Unfortunately, this forum software allows only uploads with a rather limited file size; is there another way to send you samples?

Quote:(personally, I would also use a deblocker and maybe denoise the darker areas a bit)
I can't see any problems with blocking, but which tools would you recommend?

I now have a lot to try out and fine-tune – so thanks again for all this input!
Quote:What lossless format would you recommend?
Depends on the tools you use. If FFV1 is supported I would use that.

Quote:Where can I specify 10-bit encoding?
using x264, you would need to select a AVC Profile which supports 10bit and then set "x264->Base->Calculation Precision" to 10bit.

Quote:but no matter what, after closing and re-starting Hybrid the result is always the same: All path settings are blank (so the user log complains that the "Default output" path is empty)
You need to save the defaults for them to change.
reading [INFO] About profiles and saving settings,.... might help

Quote: Unfortunately, this forum software allows only uploads with a rather limited file size; is there another way to send you samples?
Post a link (or send via pm) to a GoogleDrive share or upload to MediaFire.

Quote: I can't see any problems with blocking, but which tools would you recommend?
Just to see problems of a source it often helps to enable 'Retinex'. Smile
Depending on the blocking usually Deblock_QED is a good choice.
The denoiser should be chosen depending on the 'strength' and 'nature' of the noise. I usually try a few.
Also (assuming Vapoursynth is used) if you want only denoise the dark parts use a limitmask limitting the filtering to i.e. only luma values < 30.

Cu Selur
Thank you for all your suggestions; I am working my way through them and am going to test them all. I have found most of what you are suggesting except:
Quote:Just to see problems of a source it often helps to enable 'Retinex'. Smile
Where would I "enable Retinex" for my test purposes?
Thanks! 🙂
a. the source needs to be cropped of black bars before applying Retinex
b. when Retinex is used as a 'highlighter', best move it to the end of the filter queue

Cu Selur
Thanks again,
Quote:Where would I "enable Retinex" for my test purposes?

a. the source needs to be cropped of black bars before applying Retinex
b. when Retinex is used as a 'highlighter', best move it to the end of the filter queue
These details are helpful, but I had the more basic problem that I could not find the Retinex function (somewhat hidden in Vapoursynth > Color > Misc) ...

Now I am almost ready to start my tests; but here is another quite practical problem:
Quote:Also (assuming Vapoursynth is used) if you want only denoise the dark parts use a limitmask limitting the filtering to i.e. only luma values < 30. 
How can I define such a mask for a filter to affect only a certain Luma range?

Thanks!
Pages: 1 2