Saturday, April 15, 2017

An SD interlaced to HD progressive Conversion Tutorial, or A Long-delayed Video

After all the time (see here and here) I've put into getting the AVISynth+QTGMC+FFMPEG deinterlacing workflow working properly on my system, I figured it was about time for a video tutorial. In my spare time, I've been trying to record one.

It's taken a lot longer than I thought.

Partly, this was due to finding new tricks/plugins that improved the process. Partly, it was due to finding unexpected bugs.

However, the main delay came from me not just wanting to do a "do this, then this' tutorial where you come away with no context whatsoever about what's actually happening. I want people who watch the video to get a good idea of what AVISynth is, and what FFMPEG brings to the process.

So, I'd start recording a tutorial, then get caught up in a tangent. An hour and a half later, I still haven't finished the video.

Plus, I make mistakes. There's a lot of material to cover, and I found myself leaving out crucial points (or ones that clear up confusing areas). I could have tried writing out a script, or just patching over my mistakes. However, it turned out that just repeating the actions so many times that you can practically do them in your sleep eventually got me to the right place. I still had some audio issues to address in post, but my overall presentation quality is much improved from earlier attempts.

I could try adding more production values than just a screencast. But at a certain point, you just have to release a project. So, here without further ado is my first full-length tutorial. Because the total video is around 45 minutes, I will probably add chapter links on the video at a later point. For now, though, here is my work. Constructive criticism is welcome.

UPDATE: The AVISynth wiki has been updated with new download links for many of the filters, and the plugin pack is no longer in a place I can easily link to. I've updated the instructions below to reflect this, and made an update video to the tutorial (linked below), but the instructions for setting up QTGMC in the above video are now outdated. I will try to keep this page updated if other significant changes occur in the future. Anyways...

Here's a written description of the process, including links:

BIG DISCLAIMER: This process may not work, may crash, or do other things to your system. I've had an issue with intermittent audio dropouts in the resulting files, but it seems to only happen with Quicktime ProRes files from a certain source. Always check your files before submitting/uploading them. 

You have been warned. 

If you're on a deadline (and using Premiere Pro, After Effects, or Final Cut Pro) probably your best best is to use a paid plugin like FieldsKit.

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.

So, where do you go to get all this goodness? Here's some web links:

AVISynth (You will need both the 32-bit "Official" build and the 32-bit "Unofficial" build)

AVISynth source filters (Get the source filter for the format/codec you want to load. In the above script, I use the built-in AVISource filter, but if in doubt, get FFmpegSource.)

QTGMC (Get the QTGMC download, then get both the "required" and "optional" filters as listed on the page. If there's a choice, get the 32-bit [x86] version of filters.)

For the .avsi pastebin links, select the text of the link and copy it, then click on the link, right-click and do Save Page As, select All Files in the Save As drop-down box, paste the name of the file, delete any spaces from the front of the filename, then save the file. For a demonstration, check out this update to my video tutorial:

LimitedSharpen (Get the x86 version in order for it to work within a script using QTGMC. )

FFMPEG Windows Binaries (Get the current 32-bit static version)



  1. Run the main AVISynth installer. 
  2. Put the AVISynth filters you downloaded (.dlls and .avsi files) in the AVISynth Plugins directory. Make sure to use the 32-bit (x86) versions of any filters if there is a choice. Make sure you're using version 2.2.7 (or later) of MaskTools2.
  3. Copy the multithreaded build of avisynth.dll to your system folder (Usually C:/Windows/SysWow64/) and replace the existing file.
  4. Copy the libfftw3f-3.dll file your system folder.
  5. Extract FFMPEG and AvsPmod to their own folders. Keep the folder with the ffmpeg.exe binary open.
  6. Set up FFMPEG to run from any directory on your PC by adding it to your PATH variable:
    1. Press the Windows and R keys.
    2. Type "control sysdm.cpl,,3". Click "Run".
    3. Click on "Environment Variables".
    4. Select "Path" under "System variables" and click "Edit".
    5. Go back to your open folder where ffmpeg.exe is located. Select and copy the folder's path address from the address bar towards the top of the window.
    6. 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.


In the same directory as your video file that you want to process, make an .avs script with the settings listed below. Change the filename, source filter, and crop settings as necessary.

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

SetMTMode (5, 10)
AVISource("videofile.avi", audio=true)
QTGMC(preset="Slower, SourceMatch=3, Lossless=2, EdiThreads=1)
A quick note here: Amazon and some other streaming services prefer 640x480 over 720x540 for SD content. I use the latter because I consider the resulting file a new "master" file that can be used to create future derivative versions, but if you're going to send the file directly to a distributor or service, read/ask for their deliverables spec to see what resolution and framerate they want.

Anyways, here's what to add if you want to upscale to HD:
This may crop off more than you want, so feel free to play around with the settings.

I've also found an awesome conservative sharpening filter that can be added at the end for a little extra punch:


Loading this script in AvsPmod will let you preview your results, and change to your preference. When you're done, don't forget to save your work.

Create a new text file in the same directory 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 ""

Change where necessary. The quotes around the filenames in the FFMPEG command allow you to enter path addresses and filenames with spaces in them.


umetnic said...

Thank You Andrew! U helped a lot of users with Your tutorial. Keep 'em coming!

Peter said...

Really appreciate this Andrew. I'm at the beginning of transferring all my Sony Handycam videos to Vimeo. Using Vegas to render the DV avi file through Frameserver, and then using Megui along with your script and instructions to create 1280 x 720 mp4 files, while maintaining my original 720 x 480 video aspect within the 1280 x 720 frame. Your instructions really helped in giving me the quality I was looking for!

Andrew Swan said...

You’re welcome, Peter. Glad to be of help. Any stability issues with using the frameserver plugin?

Peter said...

Hi Andrew. No stability issues with using the frameserver plugin. My videos have been short so far since I'm still testing various settings to get the ideal video ration in the 1280 x 720 frame. Right now I'm finding that my original ratio of my 720 x 480 seems a little stretched within the 1280 x 720 final output.

Andrew Swan said...

That would make sense. If you’re using the full 720x480 frame, it’s a different aspect ratio (4x3 vs 16x9). Generally, I prefer to crop to 720x404 first (405 would be a more accurate 16x9 crop, but you have to crop to multiples of 2 due to one or more of the plugins in the process.) You could also pillarbox the image if you don’t mind black bars on the sides, but I don’t remember how to do that off the top of my head.

Peter said...

Just tried this:

Import("C:\1-Vegas tools\LimitedSharpenFaster.avsi")
SetMTMode (5, 10)
AviSource("C:\1-Vegas tools\Video\fs.avi")
ConvertToYV12(interlaced=true, matrix="PC.709")
QTGMC( Preset="faster", FPSDivisor=2 )

and it worked great!


Robin Hardison said...

Hi Andrew. Thank you SOOO much for spending the time in helping people. But I am having a hard time following the original video, the update video and the blog post with the needed files/plugins needed. I hate to ask for additional hand-holding since you have spent so much time on everything but it's not clicking with me. Would you be able to provide a zip'd directory of everything other than the actual exe files that need to be installed?

Robin Hardison said...

Well I think I've made more headway. I got AvsPmod open and entered your basic commands and I 'think' I have all the necessary plugins installed. But I'm getting an error "couldn't locate a decompressor for fourcc hfyu"

But I installed the huffyyuv coded when I imported the video to begin with. I'm trying to import some old family videos on a variety of 8mm, digital 8mm and mini-dv tapes.

Any suggestions would be greatly appreciated.

Andrew Swan said...

You might need to use a different import plugin instead of AVISource. I would try using FFMPEGSource, which I describe how to use in my DVD conversion tutorial. Sorry that the info is spread out across so many different posts/videos, but AVISynth is a complex program with a huge number of options.

Robin Hardison said...

I installed FFMPEGSource. Is the command to load the video: FFmpegSource2="video.avi"?

It seems to accept it but I'm getting another error: Script error: there is no function named "Dither_Luma_Rebuild (QTGMC.avsi line 488).

I was getting other errors with QTGMC using your example line but when I use the only option of preset=slower for QTGMC then it went further than it has until I got the error about Dither_Luma_Rebuild.

I have researched that and I think it has to do with SMDegrain. But I have that .avsi plugin and saved it like your described in your video and placed it in the avisynth plugin directory.

What am I doing wrong now?

Andrew Swan said...

Did you install all the “optional” required plugins for QTGMC as well? If you didn’t, that would explain an error with the SourceMatch command. Also, make sure that for any plugins that have 64bit (aka amd64 or x64) vs 32bit (aka x86) versions, you’re using the 32bit version.

For FFMPEGSource, the command should be something like:

FFmpegSource2(“yourvideofile.avi”, atrack=1)