Friday, January 1, 2021

Deinterlacing with AVISynth and QTGMC - Updated occasionally

Welcome to the new home of my QTGMC deinterlacing tutorial. This post will be updated periodically as new changes happen and new info comes out, or until a better option comes along.

Changes since last post/video:

  • I've switched to an entirely 64-bit workflow
  • QTGMC has some new requirements
  • I've dropped FFMPEG as the recommended rendering program in favor of VirtualDub2
  • AVISynth Info Tool is now the recommended way to check and make sure that you've installed AVISynth correctly.


BIG DISCLAIMER: This process may not work, may crash, or may do other things to your system. Virus scan everything you download. It's not a 100% guarantee that you'll avoid getting a malware infection, but it's a lot better than not checking at all.

If you're doing professional work, always watch any files you create using this process before submitting/uploading them to check for audio and/or video glitches.

Follow this tutorial at your own risk. 

Also, this tutorial is for Windows 10. Most of the steps work for previous versions of Windows, but may require slight modifications. Users of MacOS and other OSes should look elsewhere.


Here's the video version of the setup and basic QTGMC deinterlacing workflow:




Setup


7-zip (optional)

If you don't have 7-zip already installed, you won't be able to open many of the downloaded archives. The stable, 64-bit version should be fine.

Next, we're going to need to get AVISynth+. You can grab it from here:


If you don't already have the MSVC 2019 Redistributable installed, grab the version ending with "vcredist".

Then, we'll need to get all the filters (plugins) needed:

FFMPEGSource

Note: Version 2.40 has been shown to corrupt video frames. Please either use a different version, or use LSMASHSource as linked below.

This is what will allow AVISynth+ to load our video files. Works with almost any container/codec combination, but read the "Known Issues" section for things to look out for (hint: don't use interlaced h.264 video with it).

Note: If you do need to work with interlaced h.264 video, try LSMASHSource instead. It requires two commands rather than one to work (technically three if you count AudioDub(video, audio) to combine the two together), but can support some non-standard formats. Thanks to neonfrog for the heads up.


QTGMC

The deinterlacing plugin of choice. Requires a whole host of additional plugins, of which you will be using the 64-bit versions (if an option is given). For most uses, only the "Core Plugins and scripts" are necessary.

For the "Zs_RF_Shared.avsi" link, right-click on the link and do "Save Link As", or whatever the equivalent is in your browser of choice.

DO NOT forget to download the 32-bit FFTW3 library as well. Without it, QTGMC will not run.


With all the AVISynth filters and scripts grabbed, it's time to get the supporting software:

AvsPMod

This is like an IDE for AVISynth scripts, and is pretty much essential IMO. Grab the 64-bit version for this tutorial.


This allows us to detect processor features and check to see if AVISynth is properly installed.

Finally we need to grab a rendering program.  For ease of use, I now recommend VirtualDub2 - a fork of the original program used to render AVISynth scripts. 

VirtualDub2


When finished downloading, virus scan all the things.


Installing

AVISynth+ has a simple installer. I recommend installing into whatever your user folder is (for example C:\Users\Me\) rather than the default of Program Files(x86) so you don't have to deal with authentication requests every time you add a plugin. Also, I highly recommend checking the "Add AVISynth Script to New items menu" option. Otherwise, you can stick with the defaults.

Then, go to the plugins64+ directory for AVISynth+. For example, the default install creates a plugin folder at:

C:\Program Files(x86)\AVISynth+\plugins64+\

Extract all "x64" versions of the .dll and .avsi files to the plugins directory (if given a choice) from all plugins EXCEPT the fftw-3*.dll archive. If there's a choice between AVX, AVX2 and a version without AVX, you'll need to know what instruction sets your processor supports. CPU-Z  or AVISynth Info Tool can tell you this if you're not sure.

Now, open the fftw-3*.dll archive, then (as noted on the QTGMC page) extract the libfftw3f-3.dll file. Make a copy of it and rename it as "FFTW3.dll". Place the files "libfftw3f-3.dll" and "FFTW3.dll" in the SysWow64 folder. Don't ask me why you have to do this, I agree that it seems pointlessly tedious.

Please note: If you're only using AVISynth+ (not older versions of AVISynth) and only need to use QTGMC, you can skip the above step and just download/put the 64-bit version of libfftw3f-3.dll in the plugins64+ directory. Despite the error message in 32-bit AVSInfoTool, QTGMC will now work in both modes (although you can drop the 32-bit version of libfftw3f-3.dll in the plugins+ director to clear the error if you like, and to clear the Zf_RF_Shared error, you need to do the regular install method above)

Also, if you want to be able to run QTGMC's "EZDenoise" & "Sharpness" functions, put the 64-bit version of "fft3dfilter.dll" into the plugins64+ directory.

Thanks to Spammy Family for pointing this out.

Speaking of tedious, if you want to use the "Very Slow" or "Placebo" preset for QTGMC, it looks like you need to install the 64-bit version of FFTW in your System32 directory using the same method mentioned above.

Extract the AvsPMod archive to wherever you want to run it from - again, I recommend your user folder.

Extract AVISynth Info Tool in the same way. If you like, you can install it more officially by clicking on the AVSInfoToolInstaller.exe file, but I generally just run it directly from the "AVSInfoTool_FilesOnly" folder. 

Go ahead and run it now, making sure to select the "AVISynth 64-bit" option once loaded.  If you get errors that are not about the FFTW3 library or Zs_RF_Shared.avsi (to fix those errors, install the 64-bit version of FFTW in your System32 directory using the same renaming/copying process listed above), then double-check and make sure you followed all the previous steps correctly. You might also want to take note of how many cores and logical processors you have, along with what instruction sets are supported by your CPU. 

Finally, create a folder for VirtualDub2 and extract its archive there.


Making your .avs script


Now that everything's ready, let's go to the directory with your video files and make an .avs script. Right-click anywhere in the directory, select New, then AVISynth Script and rename it however you want. If that option doesn't show up, you can just create a new text file and change the .txt extension to .avs.

Open AvsPMod, then go to the Options menu and click on "Associate .avs files with AvsPMod". You should now be able to double-click on .avs scripts and have them open directly in AvsPmod. Do so with the script you just created.

Here's my boilerplate .avs script settings for deinterlacing:

    SetFilterMTMode ("QTGMC", 2)
    FFMPEGSource2("videofile.avi", atrack=1)
    AssumeBFF()
    QTGMC(preset="Slower")
    BilinearResize(720,540)
    Prefetch(10)


The "atrack=1" option for FFMPEGSource selects the track of audio that is passed through during processing. If the default option doesn't give you audio in the results, try "atrack=-1" instead.

Please note that by default both FFMPEGSource and (certain modes of) LSMASHSource index your video file the first time you load the .avs script into either AvsPMod or your rendering program of choice. This may take a while and give the appearance of freezing the program. When it's finished, you'll see an .ffindex or .lwi file appear in the same directory as your video with the same name as your video.

Which deinterlacing algorithm is the best? Part 1 - HD interlaced footage

Before I began, I'd like to give a special thanks to Aleksander Kozak for his help in testing and providing the HD footage used in this ...