VideoHelp Forum

+ Reply to Thread
Results 1 to 22 of 22
Thread
  1. I want to degrain/denoise a 1080p anime ripped straight from the Blu-ray. I'm not too skilled with scripting, so I use Handbrake or Hybrid. I can kind of use scripts in ffmpeg and VirtualDub.

    My issue is that most methods I try end up leaving grain in the first few frames when scenes change, so there's a distracting flicker of grain. I'd like to get rid of as much grain as possible while still maintaining some sharpness and fine lines to keep the file sizes reasonable.

    So far, Handbrake's NLMeans Medium with Animation preset seems to give the best results, but it's way too slow. All of Avisynth/Vapoursynth filters I try seem to leave the grain after a scene change almost untouched. It looks like the grain is frozen for a few frames. Maybe that makes it harder to detect and degrain?

    I haven't been able to duplicate NLMeans results in other degrainers, but I don't understand most of the settings. I wanted to try using equivalent settings for something like KNLMeansCL.

    I've attached a few seconds of scenes where it's noticeable.
    Image Attached Files
    Quote Quote  
  2. Temporal noise filters require the grain to be different in successive frames. They see something that's the same across frames as detail that's supposed to be retained. What you could do is remove the duplicates, denoise, then replace the missing duplicates with copies of the first non-duplicate frame. As a proof of concept:


    Code:
    LWLibavVideoSource("sample1.mkv", cache=false, prefer_hw=2) 
    Crop(240,0,-240,-0)
    ShowFrameNumber(x=20, y=20)
    
    Trim(0,36)+Trim(39,0) #Remove frames 37 an 38
    SMDegrain(tr=2, thSAD=1000, refinemotion=false, contrasharp=false, PreFilter=0, mode=0, truemotion=false, plane=4, chroma=true)
    Trim(0,36)+Trim(37,37)+Trim(37,37)+Trim(37,0) # restore frames 37 and 38 with copies of frame 39
    Another way to deal with it would be to remove duplicates (eg, DeDup), denoise, then encode variable frame rate.
    Image Attached Files
    Quote Quote  
  3. Quick and dirty solution is to use strong spatial NR, like this combo:
    Code:
    Removegrain(2)
    FFT3Dfilter (bt=1, sigma=2, sigma2=2, sigma3=10.0, sigma4=10.0, beta=2, plane=4, ncpu=2)
    KNLMeansCL(d=0, a=3, h=5)
    @OP, dunno what you prefer, like smoother look or with a bit of residual grain, but here is a script for a smooth one:
    Code:
    LSMASHVideosource ("G:\Temp\sample12 [nvenc].mp4")
    
    RemoveGrain(2)
    neo_vd (threshold=15, method=1, nsteps=5, y=2,u=3,v=3, percent=80)
    #FFT3DGPU (bt=1, sigma=2, sigma2=2, sigma3=10.0, sigma4=10.0, beta=2, plane=0)
    FFT3Dfilter (bt=1, sigma=2, sigma2=2, sigma3=10.0, sigma4=10.0, beta=2, plane=0, ncpu=2)
    prefetch(4,4)
    KNLMeansCL(d=0, a=3, h=5)
    
    tr=2  bs=16  thSAD=350  thSAD2=250  limit=5  mt=false
    AddBorders(8,8,16,8)
    sc_full = MSuper(hpad=0,vpad=0)
     pre_ds = BicubicResize (width/2,height/2,b=0,c=0.5)
     sc_ds  = pre_ds.MSuper (hpad=0,vpad=0)
     mv_ds  =  sc_ds.MAnalyse (multi=true, delta=tr, blksize=bs, mt=mt)
     mv_dsr =  sc_ds.MRecalculate (mv_ds, tr=tr, blksize=bs/2, overlap=2, thSAD=100, mt=mt)
     mv     =  mv_dsr.MScaleVect(2)
     MDegrainN (sc_full, mv, tr, thSAD=thSAD, thSAD2=thSAD2, limit=limit, mt=mt)
    Crop(8,8,-16,-8)
    prefetch(4)
    And the output looks like this:
    Image Attached Files
    Last edited by buzz1891; 16th Jan 2022 at 08:08.
    Quote Quote  
  4. Here's a pair of scripts for variable frame rate encoding with DeDup:

    pass 1:
    Code:
    v1 = LWLibavVideoSource("sample1.mkv", cache=false, prefer_hw=2) 
    v2 = LWLibavVideoSource("sample2.mkv", cache=false, prefer_hw=2) 
    v1+v2
    Crop(240,0,-240,-0)
    Stab(dxmax=8, dymax=8, range=8, mirror=15)
    
    BilinearResize(width/4, height/4)
    DupMC(log="blah.dup.txt")
    # pass 2
    Code:
    v1 = LWLibavVideoSource("sample1.mkv", cache=false, prefer_hw=2) 
    v2 = LWLibavVideoSource("sample2.mkv", cache=false, prefer_hw=2) 
    v1+v2
    Crop(240,0,-240,-0)
    Stab(dxmax=8, dymax=8, range=8, mirror=15)
    
    ShowFrameNumber(x=20, y=20) # so we can see exactly which frames were chosen
    DeDup(threshold=1.0, trigger2=22, maxcopies=3, maxdrops=3, show=false, log="blah.dup.txt", times="blah.times.txt", decwhich=2)
    SMDegrain(tr=3, thSAD=1000, refinemotion=false, contrasharp=false, PreFilter=0, mode=0, truemotion=false, plane=4, chroma=true)
    KNLMeansCL(d=0, a=3, h=3)
    The video and the timestamps (blah.times.txt, produced during pass 2) were then muxed together with mkvtoolnix.

    You can use more or less noise reduction if you want. You can also change the DeDup threshold to get more or fewer dups removed.
    Image Attached Files
    Quote Quote  
  5. I think I like the results of DeDup since it looks sharper while still removing a lot of grain. I'll try to experiment with the spatial NR method too. Not sure when I'll get time to really dive into it.

    Some questions:

    Will removing frames and changing to VFR create stutter?

    Do two passes mean I run two different scripts?

    Is stab required to help remove duplicate frames?

    Is it something that can be batch processed?

    Is there an easier way to run scripts these days instead of manually creating .avs files and loading all of the plugins and dependencies? I'm looking at StaxRip now, since I'm hoping a GUI will make it easier.

    What's the difference between DeDup and ExactDeDup, which is what I see in StaxRip?
    Quote Quote  
  6. For the fun of it I applied vs-dpir with strengh 35 followed by DeSpot on the sources.
    That really smooths things.

    Cu Selur
    Image Attached Files
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  7. I managed to get DeDup working with VirtualDub2. I'm trying to get it to work in ffmpeg now, but it just creates an empty blah.dup.txt file but no video.

    DeDupPass1.avs:
    Code:
    LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64\DeDup.dll")
    LWLibavVideoSource("sample2.mkv", cache=false, prefer_hw=2)
    Crop(240,0,-240,-0)
    
    
    BilinearResize(width/4, height/4)
    DupMC(log="blah.dup.txt")
    ffmpeg .bat file:
    Code:
    ffmpeg -i "DeDupPass1.avs" -c:v libx264 -crf 20 "video.mkv"
    pause
    Quote Quote  
  8. I have the same problem with ffmpeg. I often use:

    Code:
    ffmpeg -benchmark -i %1 -c copy -f null -
    to run through a script quickly. That normally works but for scripts with DupMC it doesn't take long enough to actually process the video and produces an empty log file. Even if you use ffmpeg to encode the first pass video the log file is empty (the video is fine). I wasn't able to figure out why this happens.

    Using x264 CLI with -preset ultrafast works fine for the first pass. As does VirtualDub.
    Quote Quote  
  9. My ultimate goal is to batch run the script so I can process multiple videos while I sleep. I'm having trouble figuring out how to get the script to source multiple videos in a folder instead of linking to the exact video name, and having the txt filenames automatically match the names of the videos. Is there some syntax to do that or do I need to make multiple avs files linking to each video?
    Quote Quote  
  10. You can build the AVS scripts within the batch file that steps through file names. Or you can rename each file as it's being processed so it matches the name in the AVS scripts. Then rename it and the output file when the processing is done. I'll post an example later.
    Quote Quote  
  11. For now, I'm just copying the scripts into folders for each disc and quickly editing groups of them with Notepad++ and then queuing them up in MeGUI. That seems to be meeting my needs so far.

    Is the video created from pass 1 safe to delete after it generates the .dup.txt file?
    Quote Quote  
  12. Here's a post with a batch file that creates an AviSynth script for each video then calls ffmpeg to encode:

    https://forum.videohelp.com/threads/396064-DePALifying-TV-Episodes#post2574487

    Yes, you can delete the video created during the first pass. Only the stats file is needed for the second pass.
    Quote Quote  
  13. I'm still having trouble with some scene changes looking grainy. I tried raising the threshold, but I don't know what a safe value is.

    threshold=1.6 seems to help with the grain on the scene of the switch.
    threshold=2.5 gets rid of the grain in an earlier scene change, but there's noticeable skipping.
    Image Attached Files
    Quote Quote  
  14. Sample3.mkv has as many as 4 frames in a row with static grain. Change maxdrops and maxdups to 4. Threshold can remain at 1.0.
    Quote Quote  
  15. It was looking good until I noticed some fades are no longer smooth when increasing maxcopies and maxdrops, like in this sample video. So far I've only noticed it at the beginning and end of the episode, and every episode will begin and end the same way.
    Image Attached Files
    Quote Quote  
  16. The grain fades away along with the rest of the picture. So when the grain falls below the DeDup threshold the frames are tossed out, even though the picture is changing. One possible way to address this is to add grain to the small video that's given to DupMC whenever the overall average luma falls below some threshold value. After a few calculations and little experimentation... Add:

    Code:
    ConditionalFilter(last, last.AddGrain(5.0), last, "AverageLuma()", "lessthan", "24")
    to the first pass code after BilinearResize() and before DupMC().

    During the second pass (even though you're no longer adding grain to the dark frames) DeDup will see the dark frames as non-identical.
    Quote Quote  
  17. That seems to have fixed it. I appreciate the help.

    I noticed what's hopefully the last issue. Is there a way to retain small details like in the sample video of small specks of debris trailing from the spaceship? Lowering SMDegrain thSAD seemed to help, but I'm wondering if there are better options.
    Image Attached Files
    Quote Quote  
  18. Originally Posted by tom_nito View Post
    Is there a way to retain small details like in the sample video of small specks of debris trailing from the spaceship? Lowering SMDegrain thSAD seemed to help, but I'm wondering if there are better options.
    It's tough. With a background moving differently than the spots a temporal filter will have problems. It it locks onto the scrolling background the spots will be blurred away. If it locks onto the spots the scrolling background will be blurred. Increasing the temporal radius (tr=5) and decreasing the thSAD to 300 keeps a bit more of the spots and still provides a lot of the noise reduction.
    Quote Quote  
  19. Originally Posted by jagabo View Post
    Originally Posted by tom_nito View Post
    Is there a way to retain small details like in the sample video of small specks of debris trailing from the spaceship? Lowering SMDegrain thSAD seemed to help, but I'm wondering if there are better options.
    It's tough. With a background moving differently than the spots a temporal filter will have problems. It it locks onto the scrolling background the spots will be blurred away. If it locks onto the spots the scrolling background will be blurred. Increasing the temporal radius (tr=5) and decreasing the thSAD to 300 keeps a bit more of the spots and still provides a lot of the noise reduction.
    I didn't really notice a difference in noise reduction, but maybe it's hard to notice in that scene. I did notice that refinemotion=true seems to help a lot with the scrolling stars fading. Any negatives to using that?
    Quote Quote  
  20. Originally Posted by tom_nito View Post
    I didn't really notice a difference in noise reduction
    You can see more noise around the edges of the space ship, in the nook and crannies.

    Originally Posted by tom_nito View Post
    I did notice that refinemotion=true seems to help a lot with the scrolling stars fading.
    Sorry, I started with a cut/pasted from another script (which dealt with heavy noise but little motion) and forgot to check that variable. Setting it to true does help with this video. Changing the prefilter option may help too. Try values between 0 and 4 (different noise reduction algorithms are used to clean a copy of the video that's used for motion analysis). That should give you better motion vectors for the main noise reduction.

    Originally Posted by tom_nito View Post
    Any negatives to using that?
    Processing is slower. But since it helps a lot it should be worth it. Same for the prefilter variable.
    Quote Quote  
  21. Yes, refinemotion=true seemed to be twice as slow.

    I noticed a weird freezing frame issues with refinemotion=true at the end of the explosion in this sample.
    Image Attached Files
    Quote Quote  
  22. The freezing problem seems to have went away over the course of tweaking the SMDegrain settings.

    Another issue I noticed is that I see flickering splotches of smeared grain in some parts of the background.
    Quote Quote  



Similar Threads