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.


Also note that LSMASH requires separate commands for video and audio along with a dub command to recombine them. for example:

a=LWLibavAudioSource(source="yourfile.m2ts", stream_index=-1, cache=true, av_sync=true, rate=0, decoder="")
v=LWLibavVideoSource("yourfile.m2ts")
AudioDubEx(v,a)

For more info, check out the wiki page here: http://avisynth.nl/index.php/LSMASHSource


If you're trying to load an .avi file, you should probably try:

AVISource("yourfile.avi", audio=true)

instead of FFMPEGSource, as AVISource has better performance and can support some edge case .avi codecs that FFMPEGSource struggles with.

AssumeBFF/TFF deals with interlaced field order.  Simple rule of thumb here: home videos are probably going to be BFF, commercially released dvds or professional video are probably going to be TFF. You'll know if you get this wrong if you preview the video and it "jumps" every other frame.

You may or may not need either

ConvertToYV12(interlaced=true)

or

ConvertToYUY2(interlaced=true)

commands before QTGMC depending on the type of video that you're feeding into FFMPEGSource2. I used to use ConvertToYV12() frequently on older versions of QTGMC that didn't support other color formats, but the current version seems to be a lot more forgiving. 

The main difference between YV12 and YUY2 has to do with chroma subsampling (which is a whole other rabbithole to go down)  but to simplify - some older AVISynth plugins only support YV12, while other support both YV12 and YUY2. If a plugin complains about your source footage not being in either color format, convert to YUY2 if you can.

It's a good idea to try previewing the script without a Convert command and see if it works first, if not then add it in. Thanks to ENunn for the suggestion about adding interlaced=true, which should reduce chroma smearing errors.

The resize I use in this case is to correct the pixel aspect ratio of the footage. I explain in more detail in the video tutorial, but basically SD video was designed to be shown on TVs that slightly vertically stretched the image (or very slightly horizontally in the case of PAL). On "square pixel" displays (pretty much every display except for analog TVs), you need to correct for this in order for the image to have the right proportions. I enlarge the image to retain some detail and create a new "master" version that I can use in different ways, but if you're trying to convert something for a major streaming service, they usually want 640x480 for SD content (and 29.97 or 25 fps rather than 59.94 or 50fps). You can do a different resize method here like Lanczos or Spline64 if you'd like to add some light sharpening.

If you want to upscale slightly to correct the pixel aspect ratio instead (like I did in the example script above), then 720x540 is correct for NTSC, and 768x576 is correct for PAL.

The Prefetch number should be set to 1 or 2 less than the number of "logical processors" in your system. To check what that is, go to Task Manager in Windows, select the Performance tab, then click on the CPU item. You'll see down below in the window an entry for the number of logical processors in your system. For some people, it will be the same as the number of physical cores, for others it might be double that if your CPU supports Hyperthreading. In my case, I have 12 logical processors, so I set Prefetch to 10.

On the other hand, EdiThreads is supposed to be set to half the number of physical cores in your system, and if so can give a mild speed boost. With the current workflow, I've been able to set it to 3 with no issues (only my 6-core system), but your mileage may vary. If you experience any random rendering freezes (not overall system freezes), then lower this number first before restarting the render. 

Update: Looks like EdiThreads can now use all cores without stability issues, so I'm removing my advice about it. If you run into render freezes, you might try adding EdiThreads=1, otherwise leave it out.

If you need to output 29.97fps (25fps for PAL) rather than 59.94fps (50fps for PAL) at this stage, then add FPSDivisor=2 to the QTGMC command like so:

    QTGMC(preset="Slower", FPSDivisor=2)


Rendering

Instead of using command-line FFMPEG, I'm now recommending VirtualDub2 for rendering out AVISynth scripts. This is mainly because VirtualDub2 is a lot easier for most people to work with and seems to be staying around.

Working with AVISynth scripts in VirtualDub2 is pretty simple - launch VirtualDub2, drag your script into the main window, then wait for the preview to appear. Set your desired compression settings under the video and audio menus. Please note: the audio menu defaults to "direct stream copy", which you should change to "full processing mode", then you can select compression afterwards.

I personally use ProRes for most conversions, but you can choose from a variety of other codecs.  I might go into details about the particular settings in a separate blog post/video. 

To export the video, go to the file menu, then select "save video".  Make sure you select the correct file type for the codecs that you're using (For example, you can put H.264 video in an .mp4, .mov, or .mkv container, but ProRes will only go in .mov or .mxf).

Watch your video before sending it out anywhere to make sure that there are no glitches.  I've gotten burned by this in the past when exporting out multiple episodes of a TV series that had random audio dropouts.


PS: VirtualDub2 doesn't generate "official" ProRes files, so if it will be the last stop in your export chain, consider using a different workflow if the file is going to a major TV channel. Some channels have reportedly (at least according to editors on Reddit's /r/editors subreddit) said that FFMPEG ProRes files won't pass QC with them.

Optional - Cropping and resizing to HD resolutions


Here's what to add if you want to upscale SD to HD with a center crop:

    Crop(0,68,0,-68)
    Spline64Resize(1280,720)

Note that the numbers in the crop command refer to left,top,right,bottom respectively, and the right and bottom numbers are negative, while the left and top numbers are positive. Don't ask me why AVISynth does this, it just does.

The above settings will give you as close to a 16x9 frame as you can get out of this resolution. Technically, 720x405 is true 16x9, but the chroma subsampling options supported by QTGMC don't like odd numbers, so 720x404 is the closest you can get.

Also, this may crop off more than you want, so feel free to play around with the settings. If you want to frame a different part of the image (like the top or bottom versus the middle), then just adjust the crop numbers accordingly by adding what you subtract from one number to the other, or vice versa. For example, to use just the top part of the frame, you would do:

    Crop(0,0,0,-136)

It has a ton of additional features listed on the wiki page, which you can play around with if the defaults don't work for you.

One other thing to note: If you notice a color or gamma shift in your upscaled image on render, try adding:

ColorMatrix(mode="rec.601->rec.709)

after the resize step.

Optional - FFMPEG


If you want to use command-line FFMPEG instead of VirtualDub2, here's some setup instructions:

Open whatever ffmpeg archive you've grabbed, navigate to the "bin" directory, and extract the ffmpeg.exe file to whatever directory your video file/files are located in.

Alternatively, you can extract the archive to somewhere on your system and then set up FFMPEG to run from any directory by adding it to your PATH variable:
  1. Press the Windows and R keys.
  2. Type "control sysdm.cpl,,3". 
  3. Click "Run".
  4. Click on "Environment Variables".
  5. Select "Path" under "System variables" and click "Edit".
  6. Go to where you extracted ffmpeg.exe. 
  7. Select and copy the folder's path address from the address bar towards the top of the window.
  8. Back in the "Edit environment variable" window, click "New" and paste in the folder path. Click OK on all the windows you opened to get here.
Create a new text file in the same directory as your video(s) and change its extension to .bat. Add the FFMPEG commands of your choice. For example, here's a command to encode an .avs script to a ProRes 422HQ Quicktime file:

    ffmpeg -i "videofile.avs" -c:v prores -profile:v 3 -pix_fmt yuv422p10le "output.mov"

102 comments:

Unknown said...

Thank you for the update.
I just happened to dive back into Hi8 conversions that I'd started last Spring.
I was backtracking to figure out what my workflow was and WOW, you just updated the process. Great timing!

After following the steps and confirming via the AVSInfoTool, I fired up AVSPmod and pasted the script with my .avi file/path. In the past, this worked well.
But now, pressing play (F5) starts a spinning (no response) event that doesn't resolve and I end up having to force quit the program. Any suggestions on how to troubleshoot that? Task manager was no help.
Is there a logging or verbose mode I can use to gather clues?
Thanks again - excellent work and information on a mind-numbingly difficult subject.

Unknown said...

Update - I was able to get it working via dragging the script to VirtualDub2.
Perhaps it's the original AVI file size of 40+ GBs?

Unknown said...

Sadly -
I'm dead in the water again.
All efforts to render via QTGMC quickly end in a hung app.


Description
A problem caused this program to stop interacting with Windows.
Faulting Application Path: E:\AvsPmod\AvsPmod.exe

Problem signature
Problem Event Name: AppHangB1
Application Name: AvsPmod.exe
Application Version: 2.6.5.3
Application Timestamp: 4918017b
Hang Signature: 8f6c
Hang Type: 134217728
OS Version: 10.0.19041.2.0.0.256.48
Locale ID: 1033
Additional Hang Signature 1: 8f6c4481abd0f2b765fe8b6e88191bd9
Additional Hang Signature 2: 1e68
Additional Hang Signature 3: 1e6851415aafb333628b9c7937ea53cf
Additional Hang Signature 4: 8f6c
Additional Hang Signature 5: 8f6c4481abd0f2b765fe8b6e88191bd9
Additional Hang Signature 6: 1e68
Additional Hang Signature 7: 1e6851415aafb333628b9c7937ea53cf

Extra information about the problem
Bucket ID: f45cf0062a4c94d63654779cba8b07cf (1609042481906386895)

Andrew Swan said...

Could you paste your .avs script up into a comment?

christina said...

Hi Andrew, thanks again for these tutorials. I found the original immensely helpful in getting myself set up and I don’t think there’s anything else like this on the internet.

One thing that I wanted to point out / ask you about is your colorspace conversion in your boilerplate avs script. If you’re not using any filters that require the YV12 colorspace (qtgmc no longer needs it), and you’re converting to prores, my understanding is that the conversion to YV12 is unnecessary. Prores uses the YUV colorspace so you’re basically converting twice for no reason, which could cause some minor degradation of your video (although it is probably mostly unnoticeable). Also, I am not sure if this has been updated in VirtualDub2 but the last I knew, VirtualDub requires a RGB colorspace. If that is still true, you’re converting from YUV->YV12->RGB->YUV for no reason (if you’re solely using VirtualDub for rendering purposes only).

Now, I’m no expert but I’ve done so much (too much) research for my purposes so the above is more of a question than a statement. It’s possible that VitualDub no longer requires RGB colorspace or perhaps that’s only if you’re adding filters in it... but my workflow is nearly identical to yours and if I am converting to prores, I don’t have any colorspace conversions at all. And I render with ffmpeg command line or batch scripts that process a whole folder at a time, which is easier to me than opening each file in VirtualDub. The only time I convert to YV12 in my script is if I am converting directly to x264/mp4 or if I use a filter that needs it. My understanding is that colorspace conversions, although mostly harmless, should generally be avoided unless necessary.

Correct me if I am wrong on any of the above, please! And thank you!!

Christina

Unknown said...

SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("K:\11071995-02241996.avi", atrack=1)
ConvertToYV12()
AssumeTFF()
AssumeFPS("ntsc_video")
QTGMC(preset="Slower", EdiThreads=3)
BilinearResize(720,540)
Prefetch(10)

#########Additional Comments/clues
One avi will successfully load. All others crash AvsPmod.
That one avi has an (filename).avi.ffindex that has a recent creation date (since I updated per guide).
All other avi files, including those with older .avi.ffindex files crash.
So I suspect this has to to with AviSynth+ plugin locations and some 'ghost in the machine' of past installs.


___________________________________________________________________________________________

Andrew Swan said...

Christina,

You are correct about the ConvertToYV12() command not being necessary if your video uses either 4:2:0 (YV12) or 4:2:2 (YUY2) chroma subsampling. I said that explicitly in the video tutorial, but I will amend the blog post to make it clear there as well.

As to colorspace conversions in VDub2 - I wasn't aware that it does a lossy colorspace conversion unless you tell it to, but I'll check and see. Thanks.

Unknown said...

Hello. Thank you so much for putting these tutorials together. As someone very new to converting video formats for editing, I was not having much fun (and zero success) with trial and error trying to piece information together from posts on various forums. Now I'm happily deinterlacing and transcoding sd minidv footage for editing in Resolve thanks to your blog and vids!

I did run into a problem with some .mts footage I have. It's AVCHD format, 1920x1080, 29.970fps, YUV 4:2:0, 8-bit interlaced with Separated fields, Top Field First. Using the same Avisynth+ script from your tutorial in VirtualDub2 (saving video as pro res, .mov) I get very jerky video jumps forwards and backwards when playing back the output file. I've tried both AssumeTFF() and AssumeBFF() in the script and the result is the same.

I did see an older posts on Doom9 that mentioned QTGMC not playing nicely with .mts files. I was able to deinterlace using the "built-in" filter (Yadif) in VirtualDub2 but the output file had some strange ghosting when played back. Using a free 7-day trial of Premier Pro and Adobe Media Encoder I was able to deinterlace and transcode the .mts files to pro res, but I have a lot of .mts footage and was hoping to avoid Adobe's subscription pricing. Are you aware of an issue with QTGMC and .mts files? Or could you suggest an alternate method of deinterlacing .mts files for editing in Davinci Resolve?

Thanks!

Chris

Unknown said...

Andrew -
I want to make sure that BilinearResize(720,540) is correct for my workflow.
I'm starting with AVI 720x480 HuffYUV, 29.970 (30000/1001) FPS 4:2:2 Interlaced captured in VirtualDub.
The desired output would be progressive .mp4.
My confusion/concern is to ensure the aspect ratio doesn't stretch or compress the content.
When I play the AVI in VLC and take a screenshot, the image is 1.5.
After encoding via QTGMC/Virtualdub workflow outlined here, the .mp4 screenshot is of course 1.33.
I've searched forums until my eyes cross, but find little reference to the 720x540 output, other than DV file sources.
Are the settings here recommended for an analog source (Hi8)? NTSC.
Thank you!

igoriando said...

Andrew, just wanted to say thanks, this is very useful workshop/introduction for the Avisynth newcomers, I've tried it on my DV clips and result is very appealing, this is encouraging!

Sim22 said...

Thanks for the excellent video. I wish all tutorials could be this good.

I've tried this on two PCs (one Win7 and one Win10) and on both I get no sound.

My AvsInfoTool gives the same result as yours (except my OS build is "Windows 10 (x64) (Build 19041)" whereas yours is Build 19042, and my CPU is 4 physical cores / 8 logical cores. My Win10 is up to date.

In case AviSynth+ uses Ffmpeg internally I've tried it with both the zeranoe build (which I already had) and the gyan.dev build (changing the PATH as appropriate).

I am using Media Player Classic HC (MPC-HC.1.9.8.x64).

I've tried it with three video files (an mkv, an mp4 and an avi). All have sound when played in MPC-HC directly.

I've tried searching the Doom9 forum, and general 'googling'.

I've tried playing the avs file both directly (MPC-HC opens) and in VirtualDub2.

FFMpegSource2 plays the video but with no sound.
DirectShowSource could not open any of the files.
AviSource could not open any of the files.

My avs script is a single line (I uncomment one line to test it):

# FFMpegSource2("video.mkv") # no sound
# DirectShowSource("video.mkv") # could not open
# AviSource("video.mkv") # could not open
# FFMpegSource2("video.mp4") # no sound
# DirectShowSource("video.mp4") # could not open
# AviSource("video.mp4") # could not open
# FFMpegSource2("video.avi") # could not open
# DirectShowSource("video.avi") # could not open
# AviSource("video.avi") # could not open

Is there something I could check? Being new to this it's possible I've done something stupid. But after five hours I'm out of ideas and I'm beginning to wonder if there's something affecting the sound on both my PCs.

Sim22 said...

It's important to note that, without the "atrack=-1" switch on FFmpegSource2(), there is no sound. Disabled audio is the default.

Andrew Swan said...

First of all, I'm really sorry for the delay on responding to comments. I keep trying to convince Blogger up to send me a notification emails whenever someone comments, and it keeps not doing it, and then I forget about it for awhile, check and notice that there's a bunch of comments unanswered. I think I've actually fixed it this time, but there's no guarantee. I'm seriously considering switching to a different blog platform in the future.

That being said, let me address the oustanding comments in order of submission:

@Chris: I haven't messed around with .mts files for a while, but pretty much every form of interlaced h.264 supposedly has issues with FFMPEGSource. You might consider transcoding to ProRes first using VirtualDub2 or Shutter Encoder, then running the results through AVISynth/QTGMC. Realize that full high definition video is going to be really slow to deinterlace in QTGMC, so you might consider dropping a little bit of visual quality and going for the "fast" or "faster" preset.

For the bilinear resize question: either 640x480 or 720x540 should be fine in your case. If you want to add a little bit of extra sharpening, try LanczosResize or Spline64Resize instead.

@igoriando: You're very welcome. :)

@Sim22: Yup. I mentioned that in the video tutorial, but I'll try and make it clearer in the blog post.

Dean said...

Hello,

Thank you for your efforts, much appreciated!

Can anyone offer advice on troubleshooting the issue AVSinfo is finding (libfftw3f-3.dll)? I've tried redownloading and reinstalling the components involved. I tried adding the dll's to the System32 folder.


[OS/Hardware info]
Operating system: Windows 10 (x64) (Build 19042)

CPU: Intel(R) Core(TM) i5 CPU M 560 @ 2.67GHz / Arrandale (Core i5)
MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2
2 physical cores / 4 logical cores


[Avisynth info]
VersionString: AviSynth+ 0.1 (r2772, MT, x86_64)
VersionNumber: 2.60
File / Product version: 0.1.0.0 / 0.1.0.0
Interface Version: 6
Multi-threading support: Yes
Avisynth.dll location: C:\WINDOWS\SYSTEM32\avisynth.dll
Avisynth.dll time stamp: 2018-12-20, 18:55:16 (UTC)
PluginDir2_5 (HKLM, x64): C:\Users\dean\AviSynth+\plugins64
PluginDir+ (HKLM, x64): C:\Users\dean\AviSynth+\plugins64+


[C++ 2.6 Plugins (64 Bit)]
C:\Users\dean\AviSynth+\plugins64+\ConvertStacked.dll [2018-12-20]
C:\Users\dean\AviSynth+\plugins64+\DePan.dll [2.13.1.6]
C:\Users\dean\AviSynth+\plugins64+\DePanEstimate.dll [2.10.0.4]
C:\Users\dean\AviSynth+\plugins64+\DirectShowSource.dll [2018-12-20]
C:\Users\dean\AviSynth+\plugins64+\ffms2.dll [2020-08-22]
C:\Users\dean\AviSynth+\plugins64+\ImageSeq.dll [2018-12-20]
C:\Users\dean\AviSynth+\plugins64+\masktools2.dll [2.2.26.0]
C:\Users\dean\AviSynth+\plugins64+\mvtools2.dll [2.7.44.0]
C:\Users\dean\AviSynth+\plugins64+\nnedi3.dll [0.9.4.57]
C:\Users\dean\AviSynth+\plugins64+\RgTools.dll [1.1.0.0]
C:\Users\dean\AviSynth+\plugins64+\Shibatch.dll [2018-12-20]
C:\Users\dean\AviSynth+\plugins64+\TimeStretch.dll [2018-12-20]
C:\Users\dean\AviSynth+\plugins64+\VDubFilter.dll [2018-12-20]

[Scripts (AVSI)]
C:\Users\dean\AviSynth+\plugins64+\colors_rgb.avsi [2016-07-05]
C:\Users\dean\AviSynth+\plugins64+\QTGMC.avsi [2021-02-06]
C:\Users\dean\AviSynth+\plugins64+\Zs_RF_Shared.avsi [2021-02-06]

[Uncategorized files]
C:\Users\dean\AviSynth+\plugins64+\colors_rgb.txt [2016-07-05]



[Plugin errors/warnings]
____________________________________________________________________________________________________

Function duplicates:

"undefined" : "[InternalFunction]"
"Undefined" : "C:\Users\dean\AviSynth+\plugins64+\Zs_RF_Shared.avsi"

____________________________________________________________________________________________________

"C:\Users\dean\AviSynth+\plugins64+\DePanEstimate.dll" requires the FFTW library for some functions.

Note: 'libfftw3f-3.dll' can be downloaded here:
http://www.fftw.org/install/windows.html

'libfftw3f-3.dll' should be placed in "System32" and/or "SysWoW64"
____________________________________________________________________________________________________

"C:\Users\dean\AviSynth+\plugins64+\mvtools2.dll" requires the FFTW library for some functions.

Note: 'libfftw3f-3.dll' can be downloaded here:
http://www.fftw.org/install/windows.html

'libfftw3f-3.dll' should be placed in "System32" and/or "SysWoW64"
____________________________________________________________________________________________________

Andrew Swan said...

Dean,

If you're just using QTGMC, then this error doesn't necessarily mean anything.

If you want to use other plugins that require the FFTW library (or just to make the error go away), then try installing the 64-bit version of FFTW in your System32 directory in addition to the 32-bit version of FFTW in your SysWOW64 directory (same basic process for both, covered in the post).

Dean said...

That did the trick, thank you!

Kind of funny how the 64bit version goes in System32 and 32bit version goes in SysWOW64???

FranzLiebkind0 said...

Hi Andrew - fantastic blog and tutorial - I have been able to successfully deinterlace, sharpen, and lower the file size of a couple of my home videos following your guidance

I did run into an issue with one video - the source video is a VHS of a cousin's birthday shot by a professional vendor, that I had captured via my VCR to PC set-up using OBS (this is what I have done for all my videos)

This video however becomes "wavy" when there is motion after running QTGMC script - reference images in this link: https://imgur.com/a/0e0RjhV

The top image is the interlaced original and the bottom image is the wavy QTGMC output

Below is my current script:
SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("First Birthday 98.mp4", atrack=1)
AssumeBFF()
QTGMC(preset="Slower", EdiThreads=3)
Spline64Resize(720,540)
Prefetch(10)

I have tried AssumeTFF() as well as commenting out the resize/sharpening function but I still get the wavy output

Is there anything I can modify, or should I use an alternate deinterlacer

Thanks!

Andrew Swan said...

Frank - That looks suspiciously like your video was re-recorded from another source and possibly resized. When that happens, the interlacing becomes "baked in" to the image and can't be easily removed.

You might try a second QTGMC command with the progressive repair option like so:

http://avisynth.nl/index.php/QTGMC#Progressive_Input

Otherwise, good luck!

FranzLiebkind0 said...

Thanks Andrew - turns out the issue was the OBS capture output - no matter what I did I couldn't fix the issue. I have re-captured from VCR via Virtualdub capture function and QTGMC works perfectly now - thanks

Patrick Clow said...

Andrew, thank you for your work on this. I’m really new to this type of work, but as a technologist I’m keen to solve problems. I don’t speak the language of video processing beyond, “May I have a glass of water?” or “Where’s the bathroom?” but I’m getting better.

I spent a lot of time looking for deinterlacing solutions for Digital8 captures and VHS captures made through a Digital8 camera. Your steps are easy enough to follow and made for pleasing results, both high quality and streamable. Definitely helpful as I work through a theater organization’s decades of footage for a durable digital archive.

Like Chris above, I have a lot of footage in m2ts files from a Panasonic AVCHD camcorder. It’s all 1920x1080/29.97i. It plays just peachy in VLC which deinterlaces on the fly - hardly any noticeable artifacts. But lately we’ve had the opportunity to stream some of this footage over Zoom, and that’s where the interlacing becomes visually problematic. It is just nicer to have a progressive file for that. I’ve had some luck using Handbrake and EEDI 2 Bob, but the processing time is excessive (like 24 hours of 100% CPU for one hour of video (on an old 4-core machine)) and the end results were ... meh. Good enough, I guess. Considering my success with your instructions, I *really* wanted to use QTGMC as the deinterlacer for my AVCHD material.

I discovered the exact thing you mention: FFmpegSource2 does not play well with interlaced m2ts/h.264 files. Lots of image jumping. Telling it AssumeBFF/AssumeTFF didn’t work. I went down many rabbit holes, including briefly venturing into Hybrid. I was unsuccessful there, but a suggestion for fixing a similar processing problem in Hybrid led me to search for a bunch of terms that eventually led here. That page had some intriguing and simple AVS code for processing AVCHD files similar your workflow.

I installed the 64bit LSMASHSource dll into the plugins64+ directory of AviSynth+. Here’s the script I used:

SetFilterMTMode("QTGMC",2)
a=LWLibavAudioSource(source="C:\Users\neonfrog\Desktop\Pirates\Act1.m2ts", stream_index=-1, cache=true, av_sync=true, layout="DL+DR", rate=0, decoder="")
v=LWLibavVideoSource("C:\Users\neonfrog\Desktop\Pirates\Act1.m2ts")
AudioDubEx(v,a)
QTGMC(Preset="Slower",Edithreads=2)
Prefetch(threads=6)


It works! You can probably ignore my audio arguments (I have my reasons for downsampling 5.1 to stereo). I just drag that AVS script into VirtualDub2, monkey with my output settings to taste, and I go from 1920x1080/29.97 interlaced to 1920x1080/59.94 progressive via QTGMC. Looks nice! It cut my processing time down by 66%. I will say that playing it back locally, I don’t see a lot of difference between VLC’s on-the-fly deinterlacing and my QTGMC files, so deciding if it’s worth the effort is a personal decision. I just thought someone might appreciate this alternative workflow for these specific kinds of files.

Cheers,
neonfrog


Links used above:

LSMASHSource = http://avisynth.nl/index.php/LSMASHSource

Hybrid = https://www.selur.de/

Interesting forum posts:

https://forum.videohelp.com/threads/394294-QTGMC-and-stutter#post2560329

https://forum.videohelp.com/threads/397492-QTGMC-Help-trying-to-de-interlace-VHS-having-a-real-mare-with-errors#post2585171

Andrew Swan said...

neonfrog,

Sorry for the days-later reply - your comment got flagged as spam for some reason.

Anyways, this is great info. I haven't really messed with LSMASH, but I'll look into it now.

In the past, I've used FFMPEG with the bwdif filter to deinterlace 29.97i HD content, which looks decent and is substantially faster than QTGMC. However, if you like QTGMC's results, you might consider using the "fast" preset for HD material - at that resolution, the difference between presets is a lot less noticeable, and "fast" is a lot faster than "slower".

Vodkomotornik Pictures said...

Hello teacher!
Well written - everything is clear and understandable.
I used to use Avisint 2.6 and QTGMC 3.32, but now I just can't configure it!
I did everything as described, but I have an error when opening the file in VirtualDub.
No function QTGMC!

My script:
AviSource ("E: \ 000 \ 2016-cineform.avi")
QTGMC (Preset = "Slow")
SelectEven ()

Avisynth Info Tool:

[OS/Hardware info]
Operating system: Windows 10 (x64) (Build 19042)

CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz / Ivy Bridge (Core i7)
MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX
4 physical cores / 8 logical cores


[Avisynth info]
VersionString: AviSynth+ 3.7.0 (r3382, 3.7, x86_64)
VersionNumber: 2.60
File / Product version: 3.7.0.0 / 3.7.0.0
Interface Version: 8
Multi-threading support: Yes
Avisynth.dll location: C:\Windows\SYSTEM32\avisynth.dll
Avisynth.dll time stamp: 2021-01-11, 13:47:06 (UTC)
PluginDir2_5 (HKLM, x64): C:\AviSynth+\plugins64
PluginDir+ (HKLM, x64): C:\AviSynth+\plugins64+


[C++ 2.6 Plugins (64 Bit)]
C:\AviSynth+\plugins64+\ConvertStacked.dll [2021-01-11]
C:\AviSynth+\plugins64+\DePan.dll [2.13.1.6]
C:\AviSynth+\plugins64+\DePanEstimate.dll [2.10.0.4]
C:\AviSynth+\plugins64+\DirectShowSource.dll [2021-01-11]
C:\AviSynth+\plugins64+\ImageSeq.dll [2021-01-11]
C:\AviSynth+\plugins64+\masktools2.dll [2.2.18.0]
C:\AviSynth+\plugins64+\mvtools2.dll [2.7.44.0]
C:\AviSynth+\plugins64+\nnedi3.dll [0.9.4.57]
C:\AviSynth+\plugins64+\Shibatch.dll [2021-01-11]
C:\AviSynth+\plugins64+\TimeStretch.dll [2021-01-11]
C:\AviSynth+\plugins64+\VDubFilter.dll [2021-01-11]

[Scripts (AVSI)]
C:\AviSynth+\plugins64+\colors_rgb.avsi [2021-01-11]
C:\AviSynth+\plugins64+\Zs_RF_Shared.avsi [2021-03-11]

[Uncategorized files]
C:\AviSynth+\plugins64+\colors_rgb.txt [2021-01-11]



[Plugin errors/warnings]
________________________________________________________________________________

Function duplicates:

"undefined" : "[InternalFunction]"
"Undefined" : "C:\AviSynth+\plugins64+\Zs_RF_Shared.avsi"

Andrew Swan said...

Did you actually put the QTGMC.avsi file in your plugins64+ directory? I don't see it listed in AVSInfoTool's output.

Vodkomotornik Pictures said...

Yes that's right! I forgot about him - everything works!
Thank!

Plubbingworth said...

Are you sure that EdiThreads refers to physical cores and not logical cores? The Avisynth wiki page for QTGMC seemed kind of ambiguous about it. In one instance it just says "cores" and one time it says "logical cores".

Andrew Swan said...

@Plubbingworth - On review, you're correct, and I'm not 100% sure.

I think I could probably eliminate EdiThreads from my script template entirely, as the default of 0 - which just uses all cores - seems to be stable now. It could be that the switch to 64-bit did that, or improvements to AVISynth+'s memory management, or just updates to QTGMC itself.

Regardless, good point - I'll update the blog post.

DroneOps SA said...

I ran across something interesting that might be a quick fix for someone looking to deinterlace and get "59.94" progressive footage from captured HDV tapes.

First off, I freely admit I know almost nothing about interlaced footage. I've been editing for about 8 years, but exclusively DJI, GoPro, Canon & Sony footage, progressive, AVCHD, XAVC, 1080p & 4K. Recently, someone dumped a hard drive on me & asked if I could produce some nice "memory lane" videos for them. It was amateur sports / extreme sports content, shot on a couple different Sony HDV tape cameras circa 2008-2010. I tried using the standard best practice technique for Premiere Pro that I could find, and the results were pretty underwhelming.

I took one of the master files and ran it through the process described in this post, while simultaneously taking the opportunity to to a temporal up sample (what is the proper word for this?) to 59.94 progressive, and the edited result was much better. However, it took a long time, a lot of processor activity and electricity in my country is frightfully expensive. The idea of processing several hundred gigs of files this way was financially unappealing.

By random chance, I tried doing this, using Premiere Pro CC 2019:

Load the master files in to PP2019. Master files in my case are are MPEG2 HDV 1080i 24.3Mb/s 1440x1080, 29.97 Top Field First BT.709 according to MediaInfo.

Without conforming the master files in any way, drop one on the time line. A 29.97 interlaced sequence is automatically created. Do NOT right click on the clip and modify "Field Options" to "Deinterlace Always". They *must* stay at "None". Edit the file as desired. Add slow motion using Optical Flow if desired, all the way down to 50% still looks fine.

Now for the crazy part. Bring up the export screen, select H.264, for an easy head start, select the YouTube 1080p Full HD preset. But now unlock the frame rate by unchecking the box, and set it to 59.94. Field order should already be progressive from this preset, and so should Aspect Square Pixels. I also had Render Max Depth and Use Max Render Quality checked. I then exported the file...

I was shocked to find that the exported file plays like a real 59.94 progressive video. There are no combs when played in VLC with Deinterlace turned off, and it has the nice smooth look of 60fps action cam or Sony mirrorless video (desirable for sports, not so much by filmmakers). MediaInfo confirms that it is a progressive file, and it is not longer anamorphic 1.333 pixels, but an actual square pixels 1920x1080 video.

Further testing shows that a file exported this way looks **significantly** better than one exported using "Match Source, High Bitrate" (which sets frame rate to 29.97 and field order to interlaced), or using a 29.97 progressive preset. Also, modifying the clip "Field Options" to "Always Deinterlace" THWARTS this process completely. Exporting an Always Deinterlace modified clip using the customized preset I mentioned above comes out looking like it was recorded at 20 fps or something!! Also, this custom export takes about 2x longer than when Match Source is used (but is still 2x real time on my machine), and spikes the processor & CUDAs much, much harder, which would seem to indicate that some additional processing is taking place.

I realize my technique is probably the equivalent of high fructose corn syrup vs real Vermont / Quebec maple syrup, but does anybody much smarter than me know WHY this even works at all?? It is completely contrary to all the instructions in best practices tutorials. And it's going to save me a ton of kilowatt hours.

Note - I can't test this with any other type of content like SD, and since PP2020 slowmo is broken for over a year (no wonder The Slow Mo Guys use Final Cut), I don't feel like installing to see if it works in that version. But maybe this can work for you, if you are not doing broadcast work, and looking for a quick solution.

Andrew Swan said...

@DroneOps SA:

Thanks for the tip!

I went and did some testing, and can confirm that your hack works for HDV content. However, when I tried it on my (full HD) interlaced master of a documentary that I worked on, the interlacing lines remained. So my guess is that due to the goofball way in which HDV is encoded, your hack is tricking Premiere into displaying both fields instead of the usual Premiere deinterlacing method, which is to toss out every other field. In both cases, the results look line doubled, which loses some resolution versus interpolation. However, considering that most people don't pixel peep footage like this, I would consider it an acceptable hack.

To be a bit more fiddly, I tested and compared different deinterlace methods. I wish I could attach images easily, but basically, QTGMC smooths diagonal lines and cleans up some compression artifacts, even if you use the "Fast" preset - which I would recommend for HD footage to improve processing times.

DroneOps SA said...

Thank you for your response, Mr Swan. As you and several others have mentioned, this is a deeper rabbit hole than even Morpheus would admit!! Poor Neo, he will never get his editing done!

My initial tests using your method were on very short clips, probably created by a false start recording (press record, realize this is not the moment, press stop a few seconds later). I put some longer clips in, and on closer inspection, the skipping problem that @neonfrog discusses was all over the place in my output clips. This is SO obviously not a TFF / BFF problem, because it isn't wobbling back & forth across subsequent frames (I broke that too, just to see how it looks), it's like it forgot which frame in the GOP it is supposed to be working on & bounces back forth across many frames randomly.

I thought this was a little strange, because my source files are definitely not AVCHD, and definitely not H.264. It turns out I have 2 types of source files. One was created by the camera connected to a firewire card scanning into a computer running something called Ulead Video Studio (based on the file name & search results), which is now owned by Corel, and supported HDV literally years before Adobe did, so I assume that's why it was used. The other type of file is from the same camera, but with something called a "HVR-MRC1K flash recorder" attached, which appears to automatically "capture" everything coming out the firewire port, save it on a CF card, and eliminate the step of capturing the tape. Here is the relevant MediaInfo (from a flash recorder file, however a file recorded into Video Studio has absolutely identical meta-data as below, except for the record time):

[blogger is complaining about the MediaInfo copy / paste, I'll try putting another post below]

Anyway, these files look absolutely horrible when deinterlaced using FFmpegSource2, but come out perfectly when using Lsmash. So maybe it is not so much the compression method, but just the fact that it comes from a tape based camera? I certainly have no idea, but maybe this info will help someone else finding the same problem. Also, my hack method is not impeded by the problem, which I see as a bonus.

All that to say, I did a comparison of my Premier Pro hack (I upped the encoder rate to 50Mbps H264 on the export) versus Lsmash VirtualDub2 H264 with Quality 10, which worked out to 49.8Mbps. Played back with VLC full screen on a 43" 4K Samsung TV connected as a monitor (properly configured for computer use over the HDMI port), I finally was able to see what you are talking about... there is a subtle, but noticeable increase in quality using the Lsmash method.

But then I took a couple Lsmash deinterlaced files, imported them back into my Premiere project, and created a new 59.94fps 1080p project to export at a more reasonable 10-15Mbps like I would deliver a finished 1080p project to any client, and at that stage, there was no obvious difference. I don't know if that is a low number for you G8 nationers, but here in Latin America most people still use Core i3 laptops with 5400rpm 500GB hard drives, so you can't go around giving them videos with 50Mbps bit rates, or they tell you stuff like "it's too big", "my hard drive is full" "Can you put it on the cloud for me" or "it doesn't play on my computer".

Thank you so much for your time and tutorials, Mr Swan. I learned a lot. I'm going to use my hack for this job, but at least I know the right way if I ever need to get every last bit of quality. And maybe my hack will save some other people with lower quality requirements some time.

DroneOps SA said...

MediaInfo for a file from a Sony HDV camera with a Sony flash recorder HVR-MRC1K. The info is absolutely identical in every way to a file from the same camera captured to a computer via firewire (except clip length & recording time, obviously):

Format : MPEG-TS
Commercial name : HDV 1080i
File size : 58.4 MiB
Duration : 18 s 986 ms
Start time : UTC 2009-12-04 13:30:41
End time : UTC 2009-12-04 13:30:59
Overall bit rate mode : Variable
Overall bit rate : 25.8 Mb/s
Maximum Overall bit rate : 33.0 Mb/s
Encoded date : UTC 2009-12-04 13:30:41

Video
ID : 2064 (0x810)
Menu ID : 100 (0x64)
Format : MPEG Video
Commercial name : HDV 1080i
Format version : Version 2
Format profile : Main@High 1440
Format settings : CustomMatrix / BVOP
Format settings, BVOP : Yes
Format settings, Matrix : Custom
Format settings, GOP : M=3, N=15
Format settings, picture structure : Frame
Codec ID : 2
Duration : 18 s 819 ms
Bit rate mode : Constant
Bit rate : 24.1 Mb/s
Maximum bit rate : 25.0 Mb/s
Width : 1 440 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 29.970 (30000/1001) FPS
Standard : Component
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Top Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.518
Stream size : 54.1 MiB (93%)
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

DroneOps SA said...

Wow, this is embarrassing to be back here again so soon.

But I think this is valuable information... there might be an issue / bug / problem with NEW versions of FFmpegSource2. Mr Swan, I went back to your tutorial from last year, and grabbed the version that came out around the time of your tutorial: ffms2-2.23.1-msvc

I replaced ffms2.dll in the avisynth+ directory, and **instantly** the MPEG2 HDV test files I was using played nicely in AvsPmod, and exported nicely from VirtualDub2. Switch back to the new dll, and back to skipping. In other words it's not a coincidence. Also re downloaded the new version ffms2-2.40-msvc just to be sure. To be clear, Everything else was using your new instructions, only the FFmpegSource2 dll was older, and the older version was perfect.

Then I found this guy on Doom9 forums who made a lot of tests, which seems to confirm that new FFmpegSource2 is not working properly. Also notice that he says Lsmash / LWLibavVideoSource is working perfectly (people say his computer is too weak, but I have 16 cores /32 threads + 128GB memory on mine which darn well better be strong enough, and it is broken for me too):

_______________ Start Doom9 Post
Posted by manolito:
I got curious and made a couple of tests using different source filters with Atak's SeekTester 1.2. I used the default frame limit of 1000 frames. As the source I took the "Letter - SHE'S.mkv" (VP9 Video 1080p). My CPU is a Core i5 third generation (2 physical cores plus hyperthreading). I used the default thread values for all source filters which would be 4 for this CPU.

FFMS2 StvG from Oct. 2020: There were 12 corrupted frames out of 1000 frames.

FFMS2 StvG from Aug. 2020: Same

FFMS2 StvG from April 2020: Same

FFMS2 StvG from Nov. 2019: Same

FFMS2 C-Plugin latest 2.31 by qyot27: Perfect

FFMS2 C-Plugin by Reino: Both available versions fail miserably.
Mainly corrupted or inserted frames

FFMS2 official version 2.40 by Myrsloik: Fails miserably.
Mostly corrupted or inserted frames

DirectShowSource with LAV Filters: Many inserted frames

DSS2Mod with LAV Filters (preroll=15): Perfect

LWLibavVideoSource by HolyWu: Perfect

Ok, these results are only for this specific VP9 source file. Other source formats may behave differently, but I find this very interesting. Any comments?
_______________ End Doom9 Post

Andrew Swan said...

@DroneOps SA

Great info. I'll update the post to warn downloaders about version 2.40 of FFMS2.

Ionut-Alexandru said...

Hi Andrew,

Thank you very much for your detailed blog post and the companion YouTube video! I was extremely impressed by QTGMC and it's performance on the Slower preset, even with horizontal and vertical motion in the frame.
I have one quick question: for BilinearResize, does it make sense to resize from HDV 1440x1080 to 1920x1080 or is there a flag that I should flip somewhere to adjust the PAR from 1.33 to 1?
I apologize in advance as I am still a newbie into the recording and processing scene.
Thank you for your great work and support!

Ionut-Alexandru said...

@DroneOps SA
I've captured multiple HDV files in .m2t format, source is a Sony HVR-Z1U using HDV Split without any issues. May I recommend checking the recording software and testing HDV Split in VCR mode over FireWire? My current setup uses a very old (2000) TI OHCI PCI card with Windows 10 x64 and the Legacy FireWire drivers and works as expected. QTGMC did the deinterlacing trick perfectly without any artifacts.

I've had some issues when the recording starts on tape, however I assume it's a known issue for the interlaced video frames to sync in the first few seconds of recording (I'm also looking into getting a head cleaning tape).

Andrew Swan said...

@Ionut-Alexandru

You're very welcome. I personally would just resize HDV to 1920x1080 unless you want to write back to HDV tape for some reason. Just remember that you can use a resizing method with some mild sharpening if desired such as Lanczos or Spline64, and wait until the final step to resize (before PreFetch() ).

Ionut-Alexandru said...

@Andrew Swan
Thank you for the tip, Andrew. Indeed, with Spline64 there is a proper increase in sharpness. Also, looks like my artifacts when changing scenes disappeared. Not sure if it's a QTGMC issue or just a resizer quirk. Splin64 seems to be the key for HDV conversion from 1080i60 to 1080p60.

Ionut-Alexandru said...

@Andrew Swan
One last rookie question: my original .m2t HDV file was recorded with BT.709, however the deinterlacer script output shows BT.470 System B/G. Is there a flag or additional function I can use to keep the same color space as the source?
Thank you for your support!

Andrew Swan said...

@Ionut-Alexandru

Do you notice a color or gamma shift? If not, I wouldn't worry about it. If it really bugs you, you could try either ConvertToYV12() or ConvertToYUY2(), but if you're rendering out using VirtualDub2, it should convert to whatever colorspace your rendering codec of choice uses automatically. If you want to use command-line FFMPEG, *then* it might be an issue.

DroneOps SA said...

@Ionut-Alexandru - I'm sorry my posts were kind of long, so maybe you didn't see it. Some of the files I am working with are from a Sony HVR-MRC1K. If you search it (like I had to), you see it is a box Sony made that connects directly to the camera and captures the transport stream from the firewire to a file on a CF card every time REC is pressed. I think it even works with your camera. On a Z5U it has a connector to clip on behind the battery so it is almost part of the camera. So files from this box are the **purest** form of MPEG2 TS that can possibly exist, I think. They are literally made by Sony themselves. If Sony don't know how to make the file, what hope do any of us have?

We ended up discovering that FFMS2 2.40 (and maybe versions near it) are broken. The TS files I have are fine.

Also, I appreciate your suggestion sir, but it is a customers files, and he sold his V1U and Z5U cameras many years ago. What I have on his hard drive is all there will ever be. I will use the quick hack I describe above to give him memorable results, without burning too many kilowatt hours, and spending too much time he won't pay extra for.

I also had the same question about REC709 becoming BT470 System B/G. It definitely comes from something in the deinterlace process. When I forced it to REC709 in VDub2, it would not play in the Win10 built in player, and Windows wouldn't make a thumbnail for it. I had to use VLC. I haven't tried forcing it in ProRes yet, but it definitely goes to legacy BT470 in ProRes too. Then when you put the Prores in Premiere, then export from Premiere Pro, it is back to REC709 again - which they say is correct for HD Video. I would have thought that the deinterlace process would just pass through this info, but apparently not, it is making it's own, incorrect info. To be fair, I do not see any color shifts, but I also have no scientific tools to check.

All this stuff makes me appreciate my 100% progressive drones, GoPros and Sony A7S-iii 1000x what I did a week ago!!!

Ionut-Alexandru said...

@Andrew Swan
You're right, I didn't check the Pixel Format option in the Video Compression settings. It defaults to 601, however it can easily be changed to 709.

Ionut-Alexandru said...

@DroneOps
Apologies for my ignorance, I unfortunately did not read all your comments in entirety. I stand corrected.

@Andrew Swan
I'm sorry to bother you again. While I was able to force BT709 into the x264-mp4 output through the encoder settings, I can still see color discrepancies between my transport file and the final mp4. Notably, reds, yellows and bright shades of colors look off in the final output, washed out and bland.

I have tested this behavior on VLC, MPC and Mplayer, side-by-side on my monitor calibrated less than 2 weeks ago (granted, I am aware that some media players ignore part/full ICC profiles in Win10; however, even if that is the case, I assume it would impact both player windows in the same fashion, essentially outlining the actual color difference between the two streams open in the same program, if that makes sense).

I am unsure what I'm doing wrong or how I can fix this behavior. My only thought is to try to re-deinterlace, with "No change" selected for the Color Space and Component range in the VirtualDub Compressor settings. In addition, I've noticed that the transport stream has more properties (Color primaries, Transfer characteristics) than the final deinterlaced file (Matrix coefficients). Unsure if that makes any difference for rendering and playback.

Apologies in advance for my rookie questions. While I can build a phone or a computer from the semiconductor fab level all the way to the application interface, I'm still learning the art of video recording, deinterlacing and post-production.

Ionut-Alexandru said...

@Andrew Swan
I was able to fix the colorspace conversion issue.
For x264, in Pixel Format, Color Space -> No Change, Component range -> No change.
In the x264 configuration, Extra command line -> --colorprim bt709 --transfer bt709 --colormatrix bt709.
This will force the encoder to honor all VUI settings and help VLC/MPC/Mplayer to render it properly, as well as dictate the proper matrix for NLEs.
In Hybrid it's easier, just select the proper values in x264 -> VUI.
Thanks for all your help and happy de-interlacing :)

RABinMSUS said...

Thanks so much for the detailed information, both here on this blog and the YouTube video. Using them both together I downloaded and installed everything appropriately (or at least I think so). Used the links in the blog to download and the video was very helpful in making sure I was setting everything up correctly. The only issues showing in Info Tool are the ones you show in the video as being acceptable. However, I can't get the video to play in AvsPmod. It just crashes when I press F5. The same thing happens when I drag the .avs file into VirtualDub2. Vdub crashes. The script is below. My machine has 4 cores and 8 logical processors. Any additional assistance in getting this working would be greatly appreciated.

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

Andrew Swan said...

@ RABinMSUS

If it's an .avi file. you can try using AVISource("test.avi", audio=true) instead of FFMPEGSource2.

However, what's the name of your file? Is it really "test.avi"? If not, you might try changing that first.

RABinMSUS said...

Wow! Thanks for the super quick reply. Yes, the file is an .avi and is named test. Changing that likne to AVISource instead of FFMPEGSource2 did prevent both AvsPmod and VirtuaDub2 from crashing, but now I'm getting another error. I'm assuming it has to do with the compression or other formatting of the file:

TemporalSoften: RGB24/28 Not supported, use ConvertToRGB32/48()
(C:/Users/User/AviSynth+/plugins64+/QTGMC.avsi, line 517
(F:\QTGMC Test\Testavs, line 4)

This is a VHS capture that I need to deinterlace before rotating, deshaking, etc. Using the original VirtualDub (which I have used frequently) I had saved a 3-4 minute clip uncompressed. That is the test.avi file. I have tried to add "ConvertToRGB32/48()" on a new line in the script at various positions, but got a syntax error. I have tried adding a line in various positions using the ConvertToRBG24 I see on the drop down in AvsPmod when I start typing that. It inserts "ConvertToRGB24(matrix="Rec709", interlaced=false)" which gives me the original error.

I'm sure this is user error, but if you're able to indulge me long enough to get me pointed in the right direction I would appreciate it.

Andrew Swan said...

@RABinMSUS

Huh. I would try ConvertToYUY2() instead, right after you load the file in the script.

RABinMSUS said...

Got it working. After checking the forums at videohelp.com I added:

ConvertToYV12(interlaced=true)

This was in your script in the YouTube video but not the boilerplate script on the blog.

Thanks again for ALL of the information.

Mikael said...

Just a heads up the AviSynthPlus fork you link to is quite outdated. It was merged into the mainline AviSynthPlus build (https://github.com/AviSynth/AviSynthPlus) ages ago, and the mainline build is literally years ahead of that fork by now.

So I would strongly recommend linking to that instead.

Andrew Swan said...

@ Mikael

Huh. Don't know how that snuck through. Will update right away.

Peter said...

Virus scan on AvsPmod shows Trojan.Malware.300983.susgen

Detected using Webroot and VirusTotal.

I tried downloading an older version, but come up with same results.

Thoughts?

Peter

Andrew Swan said...

@Peter:

On Virustotal, I'm only seeing it detected as malware with two virus scanners I've never heard of (Webroot timed out), so I would probably consider this a false positive.

However, my general advice on malware scanner results is to go with your gut and your use case - if you feel concerned or you are working on a system that absolutely under no circumstances can get a virus, don't use the file. Thankfully, VirtualDub2 has a decent script editing function that works and can still let you preview your changes.

For myself, I tend to wait until several popular AV products detect something. As I say in my disclaimer - use at your own risk.

Peter said...

Hey Andrew. Thanks for the quick reply!

What's interesting, is that when I scan on the AvsPmod_v2.6.8.7_.Windows_x86-64.zip file, I get the notice of the virus. However, if I unzip the file to its own folder, and scan that folder with all the extracted files from AvsPmod_v2.6.8.7_.Windows_x86-64.zip, a virus is not detected. Strange.

Andrew Swan said...

Yeah, that really suggests false positive to me. Usually, you would get a hit on some included library or .exe file once extracted.

Still, use your own judgement. None of this software has had a security audit.

ThomasFan1945 said...

Hi there, I happen to have a problem.
I copied and pasted your script, done everything in the tutorial correctly, now I have this issue that idk why that is.
I was planning on making HQ versions of the Sailor Moon DiC Dub, restored in 1080P via DVDs.
The DVDS were ripped via MakeMKV
However, I have to deinterlace them first!
Here's my script,
SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("1. A Moon Star is Born .mkv", atrack=-1)
AssumeTFF()
QTGMC(preset="Slower")
BilinearResize(720,540)
Prefetch(10)

I received this error while trying to play the video in AvsPmod and I am not sure what to do,
https://user-images.githubusercontent.com/66193286/130337397-d62beb00-c5eb-419b-8adc-3f5c313745e1.png

Please help me.

Andrew Swan said...

@ThomasFan1945

First of all, I would recommend IVTC rather than QTGMC for animation, unless it contains 29.97fps interlaced content. Check out the Decomb filter in this post (which also has info about another way to work with DVDs):

http://macilatthefront.blogspot.com/2019/01/tutorial-how-to-convert-dvd-for-editing.html

As to the error, I would rename your video file to not have a period before the extension at the end and try again. If not, not sure.

ThomasFan1945 said...

It contains interlaced content, as this was edited on tape with transitions and all that. As for renaming it, that did not work. I renamed it AMoonStarisBorn in my folder, while naming it as AMoonStarisBorn.avi in the script.

ThomasFan1945 said...

I still have the same error.

ThomasFan1945 said...

Also, I am using a different video file.

Andrew Swan said...

@ThomasFan1945

Not sure. You might try running AVSInfoTool and see if any errors pop out there.

Digitech said...

Hello Andrew

Great Video on QTGMC and this create wonderful results for de interlacing

Ok a few questions please

1) I working with PAL VIDEOS IN THE UK, are there any different settings I need ?

this is my current script

my camcorder video was captured at 10bit


SetFilterMTMode("QTGMC",2)
FFMPEGSource2("Melanies 30th Birthday Tape 3 Prem.mov",atrack=1)
ConvertToYUV420(interlaced=true)
AssumeTFF()
QTGMC(preset="Slower", EdiThreads=3)
BilinearResize(720,540)
Prefetch(10)


This works fine with no errors but take 2hours at an average frame rate of 34 fps ?? for hour and half movie

here is my pc spec

CPU: Intel(R) Xeon(R) CPU E5-2643 v3 @ 3.40GHz / Xeon (Woodcrest)
MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, FMA3, AVX, AVX2
6 physical cores / 12 logical cores


why so long to render,

I here there is a cuda version out there, that is much faster KTGMC ??

have you tried as would like to speed up this process and have a very powerful Nvidia card that is not being used by QTGMC

and info and help much appreciated

Regards

Andrew Swan said...

@ Digitech:

1) As I mentioned in the post, 768x576 is the square pixel equivalent for PAL video.

As to speed - that render time doesn't sound unreasonable for your settings. If it bugs you, you could try one of the faster presets - at the cost of less noise reduction and accuracy. Maybe give the "Fast" preset a shot and see what you think.

Also, are you *sure* your videos are 10-bit? I don't know of a consumer standard definition camera that shoots 10-bit video.

As to KTGMC and such - I haven't really messed with it, but IIRC the speed difference isn't massive at the moment. I would try searching the Doom9 forums for more info, though.

As long as you're using 64-bit AVISynth+, QTGMC and rendering program, you should be getting the fastest QTGMC deinterlacing you can get.

Digitech said...

Hello Andrew

thank you for your reply and the great work you do!

I'm still new to this Analog to video capture and having a few issues

Ok Trying to preserve the very best quality for all these old video tapes

VHSC / Sony Hi8 / Mini DV etc

I have chosen to invest in a KONA AJA capture card, not cheap but results a fairly impressive on this old analogue material captured via Svideo

The reason my captures are 10bit is because I chose this over 8bit in the AJA capture card settings. I also originally choose RAW which gave huge files, but have now opted for apple PROres 442HQ giving smaller files. Again this may be overkill but these original captures are the master archives, so want max quality from the analogue video input with minimum quality loss


I have followed your very good video 2020 of QTGMC but still have a few issues with settings / cropping / resizing and overall scripts

If you would be kind enough to look here, this is where I am at after following your very good video

https://forum.videohelp.com/threads/402997-QTGMC-best-quality-settings-for-PAL-SD-Video-Capture


I would appreciate you feedback and advice

Thank you very much in advance

Kind Regards John

Digitech said...

Hello Andrew

thank you for clearing this up
1) As I mentioned in the post, 768x576 is the square pixel equivalent for PAL video.

are there any other problems or thing I should add to my script ?

I'm guessing I should crop edges slightly

please see current script

SetFilterMTMode("QTGMC",2)
FFMPEGSource2("JERSEY TAPE 1 Final Interlaced.mov",atrack=1)

# ConverttoYV12(interlaced=true) ONLY GOOD FOR 8bit Video !!

ConvertToYUV422(interlaced=true) # MY VIDEO CAPTURE IS 10bit DO I NEED THIS ?? as already 10bit

AssumeTFF() # My Interlacing is TOP FRAME FIRST !

# crop(0, 2, 0, -10)
#addborders(0,6,0,6)
#crop(5, 2, -5, -2)
#Crop(0,0,704,576)
QTGMC(preset="Medium", EdiThreads=3, Sharpness=1)
#QTGMC(Preset="slow", EdiThreads=3, SourceMatch=3, Sharpness=0.5, TR2=2, Lossless=2)
BilinearResize(768,576)
#''BilinearResize(640,480)
#LanczosResize(720,540)
#Spline64Resize(720,540)
#LanczosResize(696,520)

Prefetch(10)


Thank you

Regards John

Digitech said...

Hi Again

when converting to h.264 to playback on pc/web at best quality

should I choose 10bit h.264 as the original is 10bit prores

or choosing 8bit h.264 will I see any degrade in quality ?


Thanks in advance

Andrew Swan said...

@Digitech:

Considering your original source, I don't think it should matter too much. Other settings - like compression - will matter more. Make sure you're using enough bitrate to protect quality, and don't be afraid to experiment to see what settings work best.

If you can hold onto the original ProRes captures, though, I would recommend it, as deinterlacing methods may improve over time.

Sharif said...

Hi, Andrew.

Thanks so much for this guide; I've been really happy with the deinterlacing results from my tape captures. I had a slight hiccup with audio; most of my captures are ProRes 422 with 24 bit audio but I understand that VirtualDub2 can't handle 24 bit audio so I added ConvertAudioToFloat() which seemed to do the trick and I converted a large batch of video viles with no problem.

However, I've come back a few days later and now VirtualDub2 crashes sometimes when I'm setting the audio options, sometimes once I start the job. If I remove the ConvertAudioToFloat line, then all is well (except I have no usable audio).

I'm somewhat puzzled as it worked fine for so many identically made files a few days ago and nothing has changed that I can think of.

The script is as follows:

SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("FILENAME.mov", atrack=1)
ConvertAudioToFloat()
#ConvertAudioTo16bit()
AssumeTFF()
#For DV, change to BFF
QTGMC(preset="Slower")
BilinearResize(960,720)
#Spline64Resize(960,720)
Prefetch(10)

Any thoughts you have would be greatly appreciated.

Andrew Swan said...

@Sharif,

Honestly, you stumped me there. I haven’t messed with 24-bit audio in AVISynth before, so it’s possible that it may not support that properly.

However, you can always just forgo handling the audio in AVISynth and mux it back in during the render instead. FFMPEG will let you do this pretty easily, and I believe both VirtualDub2 and Shutter Encoder can replace existing audio.

Unknown said...

I'm confused, at the beginning of the article it tells me I need 32-bit FFTW3 library.

However, a few paragraphs later it says this: "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. "

So which version do I need 32 or 64? Or both?

I will be only using AviSynth+ and not any older version.

Andrew Swan said...

If you're only using 64-bit QTGMC (and not any other plugins that rely on FFTW3), then the 64-bit FFTW3/plugins64+ option is fine. If you're using older 32-bit plugins that require FFTW3 as well, then you'll probably need to do the whole goofy original install method into SysWOW64 and use the 32-bit version of FFTW3.

Unknown said...

Hi Andrew, I just found your blog and briefly read on it few tutorials. I have a question about video grabbing. I'm rather newbie in this topic and assume that all this steps to deinterlace video are done to some raw footage grabbed via some method earlier rather than done simultaneously with ripping the material from source media.

What do you use to grab video from some external source like TV or VCR and save it on PC? What hardware you use to grab signal, which software do you use to save it to file, which codec you use?
I want to digitalize old VHS cassettes with family footage in PAL system - I have working VCR and looking for best way to connect it to PC.

I have tried using some SCART to HDMI converter and grabbing video via hdmi-usb grabber (both form aliexpress: https://imgur.com/a/v7MRp92), but i don't like results. Converter output image is slightly shifted to the right, so video is croped od the right side, also converter adds contrast filer i dont like.
USB grabber doesn't capture image as crisp as raw output from converter.
Also I had problems with audio sync, so i'm looking for another way to connect VCR to PC.

I also own old pc with TV-tuner card (very similar to this one: https://imgur.com/a/dG2Wr3k). I have tried grabbing footage with it many years ago but image looked very noisy.

I would be very grateful for a list of things you use for video grabbing and any other advice.

Thanks in advance, Antoni

Andrew Swan said...

@Antoni,

Hardware capture isn't as much my area of expertise, but I generally see one of three routes for VHS capture:

- Use an older computer with a firewire port, and plug in a MiniDV deck (or camera, if it has RCA inputs). You can then use WinDV to capture footage. This is my current solution, and has the advantages of not really requiring any extra setup due to rock solid audio sync handling. However, it also is less likely to work on Windows 10 or current versions of MacOS, so you may need to have a system running Windows XP for best results. The DV codec also has compression that can sometimes be visible, and pretty strong chroma subsampling, so colors may look blotchier than your source - especially strong reds. It's better than capturing to DVD, but still not idea for best quality.

- One of a handful of older capture devices that can capture uncompressed/losslessly compressed video via VirtualDub, combined with an outboard device such as a TBC (Time Base Corrector) to fix signal issues. The advantage here is excellent image quality for the price, along with a fair degree of tolerance for errors. Again, this is best done on Windows XP. I would direct you to LordSmurf's posts on DigitalFAQs about capturing VHS for a bunch more info.

- A professional capture device such as a Decklink 4K or AJA Kona card, running on a modern system. This can give amazing quality, but is more expensive and generally much less fault tolerant. A TBC can supposedly still help, but it's still best used with pristine sources.

sean said...

Hi Andrew! Thanks so much for you video and the written tutorial. They've both already saved me soo much legwork I know I would've flailed with a lot more on my own. Really appreciate all this work you've done!

I'm currently at the step where we are using AvsPmod to finally take a look at your test video. When I try to run that first basic script you entered with my test video I get a message that says "Script error: There is no function named 'Interleaved2Planar'"

I'm running a 64 bit setup and was reading on a few forums about how it might be part of a plugin (SSE2Tools.dll) that doesn't work with a 64 bit setup. I'm currently googling myself in circles and not wanting to mess up anything I've done before, so I wanna tread cautiously.

Have you run into this one before? Any advice?

Andrew Swan said...

@sean,

I haven't had that issue myself, but have you tried removing the plugin from your plugins folder and seeing if that fixes things? You could also check your install using AVSInfoTool and see if it gives an error related to RemoveGrain.

If not, I would recommend using TemporalDegrain2 for noise reduction instead. It has most of the same dependency plugins as QTGMC, and gives good results with several types of grain.

sean said...

Thanks, Andrew! I ran AVSInfoTool and it didn't come up with any errors related to RemoveGrain. I also tried removing it from my plugins folder and I got the same error.

Just tried adding TemporalDegrain2 (as well as a dependency plugin I didn't already have, FFT3DFilter) and I'm still getting the same error.

Andrew Swan said...

@sean,

Could you post up the text of your .avs script so I can look it over?

sean said...

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

Thanks!

Markos said...

Thanks for the tutorial Andrew!
I'm trying to digitize some old VHS tapes (home videos). I used Virtualdub2 to capture and was experimenting with different deinterlacing methods. In the search for the best one I came across your site.
I think I did everything right but when I try to preview the script in AvsProd I get the following error message at the bottom:

RemoveGrain: cannot specify U or V mode for planar RGB!
(C:/Program Files (x86)/AviSynth+/plugins64+/QTGMC.avsi, line 1100)
(C:/Program Files (x86)/AviSynth+/plugins64+/QTGMC.avsi, line 1126)
(C:/Program Files (x86)/AviSynth+/plugins64+/QTGMC.avsi, line 547)
(New File, line 4)

I also have a question about resizing. I am in the UK and use PAL system. The source video though as is captured is already 640x480, in the right proportions, so upscaling to 768x576 seems to me just upscaling, not aspect ratio correction. Unless I'm missing something that perhaps happens during the deinterlacing process, where additional visual info exists and is preserved that way, isn't this simply stretching the existing image to a higher resolution?

Andrew Swan said...

@sean,

That looks pretty standard. I'd empty your plugins folder and re-add them from scratch one at a time, then test and see when the error appears.

Andrew Swan said...

@Unknown,

Sounds like your source file is in an RGB colorspace (probably captured to an uncompressed RGB avi?). Try adding a ConvertToYV24() command right after loading the file in your script and see if that helps.

As to resizing, PAL SD digital video has a native resolution of 720x576, so you might have done a resize during capture already. Some capture devices will also convert to 640x480 before outputting to your system, so that could also be the case here.

sean said...

Thanks! I didn't run into that error again (yet, at least!) -- though now I'm seeing "There is no function named 'FFMPEGSource2'". Familiar with this one?

Thanks!

Markos said...

Thanks, you are right, the file I was testing on was RGB. Adding ConvertToYV24 didn't help it gave this error:
"ConvertToYV24: only 8 bit sources allowed"
But then I went back to virtualdub and got a fresh capture and I can see a preview this time. So it must have been that my previous file had already some processing that prevented avisynth from working on it.

Regarding resolution, I hadn't come across any resolution settings to modify and I had assumed (incorrectly) that it defaulted to max resolution.
I now found them under menu Video -> Set custom format... (Shift-F)
This brings up a menu to select frame size and I can indeed go up to 720 by 576.

One last thing: My source has a green horizontal line at the bottom of the video that I want to crop, so then the captured video would be something like 720x573.
Should I then do BilinearResize(764,573) to preserve aspect ratio?

Markos said...

further to my previous comment, when I tried BilinearResize(764,573) I got: "SeparateFields: height must be even"
I want to avoid resizing height for just a couple pixels as I think that it may hurt quality, so I guess the optimal height may be 570 pixels for me. And I can actually crop a bit more. So I'll capture 720x570 and then do BilinearResize(760,570)

Cameron Kiesser said...

I still get these weird interlacing artifacts. I keep on learning so I keep on realizing I'm doing things wrong but here's my current script:

SetFilterMTMode ("QTGMC", 2)
a=LWLibavAudioSource(source="title_t05.mkv", stream_index=-1, cache=true, av_sync=true, rate=0, decoder="")
v=LWLibavVideoSource("title_t05.mkv")
AudioDubEx(v,a)
Converttoyv12(interlaced=true)
ColorMatrix(mode="Rec.601->Rec.709")
TFM()
TDecimate()
AssumeFPS(24, sync_audio=true)
AssumeTFF()
QTGMC(preset="Very Slow", EdiThreads=14)
LanczosResize(854,480)
Crop(6,0,-6,0)
LanczosResize(854,480)
Prefetch(30)

Generally, everything runs good. It's just those pesky bands. Is there something I need to reorganize? Thanks.

Andrew Swan said...

First of all, folks, sorry for the massive delay. I've been insanely busy and haven't had time to check the blog for a while.

@ sean,

That could be from a variety of issues. Make sure you're using the same bit version of FFMPEG2Source (32 or 64 bit) as your version of AVISynth+, FFMPEG or Vdub2, etc. Also, check and make sure you have all the currently needed dependent plugins/filters, as newer versions of filters can change those sometimes. Check the FFMPEGSource page on the AVISynth wiki for that.

@ Cameron Kiesser,

A few things stick out to me:

* Your AssumeTFF() command should go before TFM(), otherwise, it's just adding potential interlacing issues after you've done an IVTC.
* If the IVTC worked, you really shouldn't need AssumeFPS. If you're having framerate issues, check the TIVTC/TFM documentation to make sure you're using the right settings. If you're working with a (legal for you to use) DVD rip, you might extract out the video and audio streams using MKVExtractGUI (or something similar), then run the video through DGMPEGDec to get a .d2v file. You can then load the .d2v file using MPEG2Source, load the audio separately using the LibAV command you currently use, and reference the .d2v file to determine the frame pattern like so:

TFM(order=-1, d2v="your_video.d2v")
TDecimate(mode=1)

In my experience, this has a much better chance of removing interlacing artifacts.

* If you're doing IVTC, you really don't need to also do QTGMC. Use one or the other. If you're trying to do progressive mode frame repair, you probably have an issue with the IVTC process.
* If you're going to crop the video like that, try doing it before resizing. Otherwise, you're doing two sharpening resize passes, which will potentially accentuate noise and other artifacts more than you might want.

Cameron Kiesser said...

Thanks. Moving the AssumeTFF() to the top of TFM() and removing excess resizing has helped! FYI I use AssumeFPS to make all of my videos exactly 48fps, including NTSC and PAL. If I didn't, it would be either 47.96fps or 50fps. (I don't decimate PAL video).

larkalarhki said...

Hi, I'm trying to convert 720x400 to HD, can you please let me know which plugin and setting I need to make the SD video to HD

I have following script at the moment

SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("video.mp4", atrack=1)
ConvertToYV12()
AssumeBFF()
QTGMC(preset="Slower", FPSDivisor=2)
#BilinearResize(720,540)
#ColorMatrix()
Spline64Resize(1280,720)
ColorMatrix()
Prefetch(10)

Andrew Swan said...

@larkalarhki:

A couple of questions:

1) I noticed you're using an .mp4 file in the input line. Are you 100% sure it's actually interlaced? While the .mp4 container can support interlacing, it's really uncommon. If the video is not interlaced, then you don't need QTGMC.

2) 720x480 is the standard resolution for SD, not 720x400. Was that a mistake, or is the original file actually 720x400? If it's the latter, see my first question.

3) What are you trying to do with the ColorMatrix() command? Is it to correct for the colorspace transform issue that can crop up when converting from SD to HD, or something else? I mention this as you haven't set any settings in the command, so I don't know if it's actually doing anything. If you're getting a color/brightness shift on conversion, you might try ColorMatrix(mode="Rec.601->Rec.709") and see if that helps.

4) Is your source material anamorphic widescreen (like from a widescreen DVD)? If not, you might need to crop the image to avoid it looking stretched.

Also, this script will resize the image, but won't add any additional detail. If you're trying to get the image to actually look like it's HD to begin with, a tool like Topaz AI would be better.

larkalarhki said...

Hi Andrew, Thank you for replying back soon.

Following settings are apply after ready your blog and others to get best quality for all of the videos I have

1) Most of my videos are MP4 or AVI files.
Can you please provide an script for different format
2) the video i'm testing is 720x400
3) I read it on another blog to add this to give it more colours - I did try this "ColorMatrix(mode="Rec.601->Rec.709")" but it was giving me error but the one you provide works fine

I try using Topaz AI but it takes around 3 days to encode 30 minutes video and video doesnt look real to me.

Your solution provides better quality

Andrew Swan said...

@larkalarhki:

At this point, I would test a few things. First, try this modified version of your script:

FFMPEGSource2("video.mp4", atrack=1)
Spline64Resize(1280,720)
Prefetch(10)

If you get "combing" in the image (edges that look like zipper teeth), then your video is interlaced and you can put the QTGMC commands back in. If not, then you're saving on unnecessary processing. If it does look interlaced, then you can try:

SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("video.mp4", atrack=1)
AssumeBFF()
QTGMC(preset="Slower", FPSDivisor=2)
Spline64Resize(1280,720)
Prefetch(10)

If you need the ColorMatrix command to fix a color/brightness shift when upscaling, you might try reversing the command and see if it works. So instead of ColorMatrix(mode="Rec.601->Rec.709"), you would use ColorMatrix(mode="Rec.709->Rec.601"). It doesn't make logical sense, but I have seen cases where it fixes colorspace issues.

If you get an error, paste it back here in a comment and I'll try to diagnose further.

komal said...

followed your guide. I am installing this on Virtual Machine Windows 11 ARM on Macbook m1 processor. I am getting error in Avisynth info tool Avisynth 64bit tab "C:/......./nnedi3.dll can not be used as avisynth plugin".
Error
"[OS/Hardware info]
Operating system: Windows 10 (x64) (Build 22621)

CPU: Virtual CPU @ 3.20GHz / Athlon 64 (ClawHammer/512K)
MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2
4 physical cores / 4 logical cores


[Avisynth info]
VersionString: AviSynth+ 3.7.2 (r3661, 3.7, x86_64)
VersionNumber: 2.60
File / Product version: 3.7.2.0 / 3.7.2.0
Interface Version: 9
Multi-threading support: Yes
Avisynth.dll location: C:\Windows\SYSTEM32\avisynth.dll
Avisynth.dll time stamp: 2022-03-17, 16:54:52 (UTC)
PluginDir2_5 (HKLM, x64): C:\Users\kiaara\AviSynth+\plugins64
PluginDir+ (HKLM, x64): C:\Users\kiaara\AviSynth+\plugins64+


[C++ 2.6 Plugins (64 Bit)]
C:\Users\kiaara\AviSynth+\plugins64+\ConvertStacked.dll [2022-03-17]
C:\Users\kiaara\AviSynth+\plugins64+\DePan.dll [2.13.1.6]
C:\Users\kiaara\AviSynth+\plugins64+\DePanEstimate.dll [2.10.0.4]
C:\Users\kiaara\AviSynth+\plugins64+\DirectShowSource.dll [2022-03-17]
C:\Users\kiaara\AviSynth+\plugins64+\ffms2.dll [2020-08-22]
C:\Users\kiaara\AviSynth+\plugins64+\ImageSeq.dll [2022-03-17]
C:\Users\kiaara\AviSynth+\plugins64+\masktools2.dll [2.2.30.0]
C:\Users\kiaara\AviSynth+\plugins64+\mvtools2.dll [2.7.45.0]
C:\Users\kiaara\AviSynth+\plugins64+\nnedi3.dll [0.9.4.61]
C:\Users\kiaara\AviSynth+\plugins64+\RgTools.dll [1.2.0.0]
C:\Users\kiaara\AviSynth+\plugins64+\Shibatch.dll [2022-03-17]
C:\Users\kiaara\AviSynth+\plugins64+\TimeStretch.dll [2022-03-17]
C:\Users\kiaara\AviSynth+\plugins64+\VDubFilter.dll [2022-03-17]

[Scripts (AVSI)]
C:\Users\kiaara\AviSynth+\plugins64+\colors_rgb.avsi [2021-01-11]
C:\Users\kiaara\AviSynth+\plugins64+\QTGMC.avsi [2022-11-23]
C:\Users\kiaara\AviSynth+\plugins64+\Zs_RF_Shared.avsi [2022-11-23]

[Uncategorized files]
C:\Users\kiaara\AviSynth+\plugins64+\colors_rgb.txt [2021-01-11]



[Plugin errors/warnings]
____________________________________________________________________________________________________

Function duplicates:

"undefined" : "[InternalFunction]"
"Undefined" : "C:\Users\kiaara\AviSynth+\plugins64+\Zs_RF_Shared.avsi"

____________________________________________________________________________________________________

"C:\Users\kiaara\AviSynth+\plugins64+\DePanEstimate.dll" requires the FFTW library for some functions.

Note: 'libfftw3f-3.dll' can be downloaded here:
http://www.fftw.org/install/windows.html

'libfftw3f-3.dll' should be placed in "System32" and/or "SysWoW64"
____________________________________________________________________________________________________

"C:\Users\kiaara\AviSynth+\plugins64+\mvtools2.dll" requires the FFTW library for some functions.

Note: 'libfftw3f-3.dll' can be downloaded here:
http://www.fftw.org/install/windows.html

'libfftw3f-3.dll' should be placed in "System32" and/or "SysWoW64"
____________________________________________________________________________________________________

'C:/Users/kiaara/AviSynth+/plugins64+/nnedi3.dll' cannot be used as a plugin for AviSynth.
____________________________________________________________________________________________________

"

Andrew Swan said...

@komal:

Try using the regular "Release_W7" version of NNEDI3, as it looks like your (virtual) processor doesn't support AVX or AVX2 instructions. And obvious, make sure it's the 64-bit version of that.

komal said...

Thanks a lot.. This regular version worked.

OfficeSpace said...

Thanks for your work, much appreciated. If I knew more about programming and creating setup files I would make a simple, one-click install for all these packages including the recommended script.

Andrew Swan said...

@OfficeSpace:

First of all, you're very welcome.

As to creating an installer, it's a nice thought, but I think it actually comes with some downsides in this case. Given how often these plugins are updated, and how they can change prerequisites and/or URLs without warning, I think putting something together that stays up to date would be nontrivial. Also, if people come to rely on the installer script rather than learning to go to each individual page, they may not understand the interplay between all of these different components, and so not be able to properly troubleshoot when things go wrong.

All that being said, I agree that the setup process for QTGMC is pretty ridiculously complicated, and I'm genuinely shocked that FFMPEG hasn't been able to add on a motion interpolated deinterlacer that rivals it. If that were to happen, it would make high quality deinterlacing orders of magnitude easier and more accessible.

sebsgs said...

I have everything installed properly to be able to use "Very Slow" or "Placebo" yet this still crashes VirtualDub. I got one tiny taste of ambrosia when "Very Slow" worked briefly, and I saw very good picture quality. Before I had a chance to begin any transcode, it crashed. Now any attempts to reload the script is met with an immediate crash. I have tried deleting the index file and starting anew, and even loading it set to "Slower" and then changing it again, but to no avail. What are my options here?

My script is this so far

SetFilterMTMode ("QTGMC", 2)
FFMPEGSource2("01. 1st tape Spring '00.avi", atrack=1)
AssumeTFF()
QTGMC(preset="Very Slow", SourceMatch=3, Lossless=1)
cropped=Crop(8, 0, -8, -0)
resized=Spline36Resize(cropped, 640, 480)
Prefetch(14)

return resized

Andrew Swan said...

@sebsgs:

- Are you using 64-bit programs and plugin versions for everything?

- Is your PreFetch set correctly for your processor?

- Does the script process just fine without the QTGMC command?

If none of those help, try using AVISource or LWLibavVideoSource/LWLibavAudioSource/AudioDub to load your video.

sebsgs said...

Everything is above board as far as I'm aware, and the entire script runs just fine as-is if I only change the preset to "Slower". Those two settings which require the extra plugins in the System32 folder are the only ones that don't work, and the "Very Slow" even DID work for approximately 3 minutes before the first crash. Crashing doesn't present an error, it only closes as if I'd done that on purpose. The prefetch was set according to the guidelines and my processor info.

Andrew Swan said...

How much system memory do you have?

Again, you might try another Source filter and see if that changes anything.

sebsgs said...

I've now tried substituting AVISource and LWLibavVideoSource/LWLibavAudioSource for the input. AviSource just crashes the same way as before, and LWLibavVideoSource returns a divide by zero crash. I'm worried that the actual issue is my setup of the necessary DLL files in the necessary locations. I've installed the FFTW3 DLL's in both my SysWOW64 and System32 folders as directed in the tutorial. Was one set of these meant to be the 32bit versions? I'm not well-versed in code at all, so there could be a very simple issue I'm simply overlooking. I could resign to just using the "Slower" setting, but I got 3 minutes of temptation making me want to get higher quality settings to work. Is it worth trying the whole setup again using the 32bit program?

64GB of physical memory, btw

Andrew Swan said...

For FFTW3, you want the 32-bit versions in your SysWOW64 and the 64-bit in System32. If they’re swapped, that could cause an issue.

You might also consider redoing your setup from scratch, following the directions one step at a time, and see if that helps.

sebsgs said...

I had had 64bit versions in both folders... OOPS!

Unfortunately this didn't end up fixing the issue. I ended up redoing the entire thing from scratch, but this time with AVX2 DLL's (only seemed to be a thing with the needi3 one though) once I realized my CPU allows those. It all works fine in VirtualDub and using FFMPEG command, but still does all of the same behavior if I dare invoke "Very Slow" or even some of the noise settings described in your comparison tutorial. I'm starting to suspect it's something involving threads or memory, with that 3 minute false positive being the main evidence. I wish I had attempted to save the video during that moment to see if it would have even tried to begin a transcode. My system info says I have 16 logical cores, hence the Prefetch(14), but it doesn't help to lower this number seemingly at all.

sebsgs said...

I figured out that I have to save the pre-process video in YV12 and then it will work without crashing!

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 ...