Hello guest, if you like this forum, why don't you register? https://fanrestore.com/member.php?action=register (December 14, 2021) x


Poll: How much do you want to try AviSynth+?
You do not have permission to vote in this poll.
Hook it right into my venes!
100.00%
2 100.00%
Nah nah nah, leave me alooooooone!
0%
0 0%
Total 2 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guide: Upgrade to AviSynth+ for high bit depth support
#1
Now that the age of HDR is here and also with x264 supporting 10 bit encoding, I've been annoyed by AviSynth's lack of support for bit depths above 8 bit per channel.

I've known for a while that AviSynth+ natively supports higher bit depths, but been always concerned that it may break compatibility with older plugins and scripts, which would be pretty stupid.

Luckily, I read today that AviSynth+ is actually very compatible with old plugins and upgrading to it is actually fairly easy.

This shall be a short guide on how to upgrade to AviSynth+ while keeping your old scripts functional and making use of higher bit depths, based on my initial experiences.

1. Get the newest release of AviSynth+. There are some older releases floating around, which led to me initially being unable to use the higher bit depth feature. You can find the newest release here: https://github.com/pinterf/AviSynthPlus/releases

2. According to the documentation, you can leave your old AviSynth installed and install AviSynth+ over it. During installation, you are given the (default) option to simply make use of the old plugin paths for the older compatible plugins. Upon deinstallation of AviSynth+, the old paths etc. would be restored and you would be safely switched back to your old AviSynth. I personally felt that this was cumbersome and deinstalled AviSynth first opting for "do not delete plugin paths"; this did not delete my plugin folders. Then I installed AviSynth+ which gave me the same option I mentioned from the documentation - to keep the old plugin folders in the path and automatically load any needed plugins from there.

3. After the installation, pretty much everything *should be* as you're used to it.


4. Get VirtualDub FilterMod and use this instead of normal VirtualDub for previewing your work. This is because normal VirtualDub does not support deep color/high bit depths and will throw an error if you attempt to use higher bit depths.

5. Note that AviSynth+ (as well as VirtualDub Filtermod) comes in both 32 bit and 64 bit version in the same package. Which version gets actually used depends *solely* on whether the app you use AviSynth with (avisynth being a library) is 32 bit or 64 bit. This means that if you open your avs file in VirtualDub Filtermod 64 bit (it's a seperate file called veedub64.exe), then you are using the 64 bit version of AviSynth+ which does NOT have access to the 32 bit plugins of the old AviSynth that you need. Hence, use the normal 32 bit VirtualDub Filtermod and you're good! Same goes for ffmpeg versions btw. - a 64 bit ffmpeg will call the 64 bit AviSynth+ library.

6. Test one of your scripts. If you, like me, get a popup called "System Exception - Access Violation", then you have some incompatible plugins in your plugins folder. I had this error and made post about it over on Doom 9 (Permalink). AviSynth+ uses an AutoLoader for plugins. This means that when you call an unknown function, the plugin directories are scanned for plugins. If there is any plugin in your plugin folder that is not fully compatible, it will throw this error (even if the plugin you are trying to use *is* compatible). There are two solutions to this. First solution: Move all your plugins into a temporary folder, then move them back in batches while testing the script again - that way you can find out which plugin (likely some unimportant niche plugin you never used anyway) is making trouble. Second solution: Add ClearAutoloadDirs() to the beginning of the script. This will completely disable AutoLoading. Then simply manually load every plugin you need like this: Loadplugin("C:\Program Files (x86)\AviSynth\plugins\ffms2.dll")

7. To use higher bit depths, use the ConvertBits function. It's as simple as srcclip = srcclip.ConvertBits(16) for 16 bit depth per channel. This should not create any visible change in your preview, as your display (likely) and VirtualDub (likely) only supports 8 bit preview anyway. But it will improve postprocessing as long as the filters support it. For example, if you do some kind of averaging of various sources or color/levels manipulation, you will have 255x the former precision per channel and 16,777,216x more available colors in the spectrum overall. I think you can go even deeper than 16 bits per channel.

8. The resulting script can be encoded as you are used to it. If you want to use a 64 bit software for encoding, like x264 64bit builds, then you can use a neat little software called avs2pipemod to pipe your 32-bit AviSynth script into a 64 bit tool. For example, here's an overly convoluted commandline I am using to pipe a 16 bit depth 32bit AviSynth+ script into 64 bit ffmpeg, where I apply a 3D LUT and further pipe it into x264 64 bit for final encoding:
Code:
avs2pipemod -rawvideo grain-16bitversion.avs|ffmpeg -f rawvideo -pix_fmt bgra64le  -s 1920x800 -r 24000/1001 -i pipe:0 -c:v prores -vf lut3d="collectall-sorted-REFERENCE_50p_50p_8bit.secondtry.mat.cube.darkenedinPS-nobluehue.CUBE" -pix_fmt yuv444p16le -vcodec rawvideo -f rawvideo - 2>null2 | x264_x64_10bit_tmod.exe --preset=veryslow --tune=grain --b-adapt=2 --deblock=-3:-3 --rc-lookahead=60 --keyint=400 --min-keyint=40 --me=umh --merange=64 --psy-rd=1.0:0.10 --aq-mode=3 --qpstep=40 --partitions=all --no-dct-decimate --bframes=16 --no-dct-decimate --no-fast-pskip --deadzone-inter 0 --deadzone-intra 0 --aq-strength=4 --aq3-mode=1 --aq3-strength=4 --aq3-boundary=820:224:36 --trellis=2 --qcomp=1 --subme=11 --ref=8 --crf 30 --output="Armarendron.264" --profile high444  --input-csp i444 --output-csp i444 --input-res 1920x800 --input-depth=16 --frames=216988 --fps=24000/1001  -

(Yes, it does actually work!)

Conclusion

Upgrading is really a breeze and of course totally worth it. The only problem you *may* encounter are some incompatible plugins in your plugin folder resulting in nasty error messages. But, Uncle Tom already told you what to do about that (step 6), so no need for worrying. How compatible is it? Well, I haven't tested THAT much yet, but let me just say ... there's this rather obscure AviSynth plugin called FQSharpen, written by some random dude with terrible horrible documentation that likely wasn't touched for 10 years ... and it works! FFmpegSource2 also works!

Oh, regarding that avs2pipemod I recommended ... for some reason it flips the image for me ... dunno why. FlipVertical() at the end of my script put that error out of its misery!
Reply
Thanks given by: spoRv
#2
Thanks! Sooner or later I'll find the courage to switch to it... Happy
Reply
Thanks given by:
#3
Think about what you can do ... regrade 10 Bit UHD sources with your ColorMatch™ technique without introducing banding! Wink
Reply
Thanks given by:
#4
Small update on this. I went through my plugins folder to find out which one was causing the error. Turns out it was merely one file named TCannyMod.dll, among dozens of other plugins that load fine. I don't even remember what it does. So I moved it out of the folder and now AviSynth+ runs perfectly just like normal AviSynth, including all the old plugins. In other words, all the big caveats from this post are not nearly as much of an issue as I thought they might be.

In other good news, newer versions of ffmpegsource2 (ffms2) automatically load video into AviSynth+ at the correct bit depth, which is great. One great use case of this is the creation of nice 16 bit screenshots of videos that have more than 8 bit with VirtualDub (the FilterMod VirtualDub version can save 16 bit TIFFs!).

Smart way to do this:

Code:
video = ffmpegvideosource("yourhighbitdepthsource.mkv")
video = video.convertBits(16)                #increase bit depth to 16 for more precision in further conversions
video = video.ConvertToYUV444()              #Change to 4:4:4 mode
video = video.ConvertToRGB64(matrix="Rec709")   #Convert to 16-bit-per-channel RGB using the correct matrix, otherwise VirtualDub colors will be off. If dealing with HDR, use matrix="Rec2020" instead.

I also figured out how to do HDR to SDR with AviSynth+; if there's any interest, I can post a short guide here. (though I believe I already posted some of it over in the UHD 2 BD thread)
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginners Guide to Colour Grading alexpeden2000 26 9,672 2023-02-24, 10:54 AM
Last Post: alexpeden2000
  Any way to test an audio file for resampling/bit-depth conversion? BusterD 5 3,778 2020-12-04, 09:46 PM
Last Post: BusterD
  Beginners Guide To Syncing Audio alexpeden2000 31 25,768 2020-10-09, 05:42 PM
Last Post: pipefan413
  AviSynth AiUpscale Chewtobacca 9 8,171 2020-07-30, 09:31 AM
Last Post: Hitcher
  AVISynth AutoOverlay frame delay Mediahead 6 3,918 2020-05-29, 12:45 AM
Last Post: Mediahead
  Dummies guide to AviSynth? Jetrell Fo 11 13,694 2016-08-01, 09:11 AM
Last Post: jerryshadoe

Forum Jump:


Users browsing this thread: 1 Guest(s)