In short, the process could be understood as follows: Raw material (Transportstream, BDMV, DVDiso) -> Filter -> x264 Encode setting -> Encode. On this page I’ll mainly deal with the Filter aspect of encoding. For x264 Encode settings please click here (page not up yet).
What programs do I need?
First things first, you’ll want to have Avisynth+ installed. Next you’ll want AvsPmod for writing your scripts and previewing them. You’ll want to grab this library.zip (do not extract it, simply overwrite the existing library.zip in your AvsPmod installation /lib sub-folder). This fixes a couple annoying errors.
Next you’ll want to get the latest komisar mod build of x264.exe. From here it’ll mostly be about finding all of the Avisynth+ filters you’ll be wanting to use, plus obtaining all of the required filters to make those filters work. It can be a chore to find some of them so I’ll probably update this page with a 7z package of the common filters you’ll be wanting.
How do I write .avs script?
If Avisynth+ is installed and all your plugins are located in the corresponding “plugins+” folder, then you should be able to start up AvsPmod.
AvsPmod is a GUI for Avisynth. As soon as it is started, you can start writing the script.
My first script: The beginning.
To start things off, you’ll need to import the video. This will usually be an 8-bit source unlesss you’re re-encoding another encode (not recommended).
8-Bit Source:
LWLibavVideoSource("I:\Sub\Encode\test.m2ts")
10-bit Source as a 16-bit display for further filtering:
LWLibavVideoSource("I:\Sub\Encode\test.m2ts",format="YUV420P16",stacked=true)
You can find how to deal with 16-bit filtering HERE.
It’s possible the video isn’t recognized as proper 23.976 FPS as if often the case with HorribleSubs improperly flagged Crunchyroll rips. In this case simply add on the same line as LWLibavVideoSource at the end with no space “.assumefps (24000,1001)”.
This method can and should never be used with transport streams or 29.97 FPS sources!
LWLibavVideoSource("I:\Sub\Encode\test.m2ts").assumefps(24000,1001)
If the source has black edges, you can use “crop” to remove them.
Crop(2, 0, -2, -0) #Left, Top, Right, Bottom Spline16Resize(1920,1080) #Should resize after cropping to bring back to original resolution.
If there is halos or the colors are off on the edges of the video instead of just black bars. Rather than crop, you can correct this should be on the edge instead of black edges, this can be solved using ContinuityFixer.
ContinuityFixer(2, 2, 2, 2) #Left, Top, Right, Bottom
Adjust it until it catches it all.
If the source has black frames (eg beginning / end), then you can remove them with “trim”.
Trim(24,0) #Trim in the Trim format (from frame to frame). #If you need more than one trim use "++" example Trim(24,300)++Trim(400,0) #0 at the end means the end of the video #Example: #Trim Start/End of Video: Trim(24,0)++Trim(0,34000)
If you want to downsize such as to 720p for example:
Spline36Resize(1280,720)
If the source has aliasing, you can fix this, but bewarned that depending on strength this could really slow down encode speed. This is done by means of “anti-aliasing” or “edge smoothing”. Aliassing, for example, is when lines aren’t straight. They’ll look kind of like a jagged “stairs”.
HiAA(y=3, u=2, v=2, mask=true, aa="sangnom2", sharp=false, sa_aa=20, show=false, lsb_in=false, lsb_out=false)
If the source is relatively blurred and there is a need to re-sharpen, you can do so. However, I advise caution. Sharper is not always better, if you exaggerate, contours are much too thick or color transitions in dark areas worse.
LSFmod(strength=15)
If the source has banding then you’ll probably want to consider some debanding. This would really be ideal to do in 16-bit, which you can find the guide to do so here. Banding is when the transition between gradients/colors isn’t smooth. However for simplicity sake I’ll cover 8-bit filtering here:
f3kdb(range=15, Y=40, Cb=25, Cr=25, grainY=30, grainC=0)
If you notice haloing in the source, you can clean them up. “Halos” are a kind of border around contours that seem quite transparent. Unlike ringing, these are brighter and cleaner.
DeHalo_Alpha()
If you notice ringing in the source, then you can filter them as well. Ringing often occurs with DVD sources or when too much sharpness was applied to HDTV or Blu-ray material. Ringing and halos are very similar, however, Ringing takes more of an “artifact shape” around contours.
HQDeringmod()
If you’d like to filter specific sections or frames of the video for problematic defects rather than simply applying the filter to the entire video, this can be done, and is a much more ideal solution. However it can be more time consuming to setup as you have to gather up frame numbers. Anyways, it can be done with mapping utilizing ReplaceFrameSimple.
deband1 = gradfun3mod() ReplaceFramesSimple(deband1, mappings="[startframe,endframe][200 300]")
And that pretty much wraps up this section.
Most of this guide has been borrowed from eXmendiC, translated to English, and modified.