Saturday, April 15, 2017

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



Hey folks - just wanted to let you know that this tutorial is now officially outdated.  I'm leaving it up here are for up historical interest, but here's a link to a post that I will maintain from this point forward with the current instructions for setting up AVISynth and QTGMC:



============================================




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.

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)

AvsPmod

Setup:

  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.

Process:

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)
ConvertToYV12()
SetMTMode(2)
AssumeBFF()
QTGMC(preset="Slower, SourceMatch=3, Lossless=2, EdiThreads=1")
Distributor()
BilinearResize(720,540)
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:
Crop(0,68,0,-68)
Spline64Resize(1280,720)
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:

LimitedSharpenFaster()

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 "output.mov"

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

16 comments:

Unknown 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")
AssumeBFF
QTGMC( Preset="faster", FPSDivisor=2 )
Distributor()
AddBorders(60,0,60,0)
Spline64Resize(1280,720)
LimitedSharpenFaster()


and it worked great!

Screenshot:
https://i.imgur.com/tpiuqe6.jpg

Unknown 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?

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

Unknown 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)

Andris said...

Hi
Could somebody share plugin folder?
had a lot of errors after 3 hours now stuck at Dither_Luma_Rebuild

Mr F said...

Hi Andrew,
Thank you again for the tutorial. I'm getting an error in response to:

QTGMC(preset="slower", SourceMatch=3, Lossless=2, EdiThreads=1)

The error message is:

Script error: there is no function named "mt_makediff"
(QTGMC.avsi, line 935)
(QTGMC.avsi, line 479)

Thoughts?

Andrew Swan said...

Hey Fehraz. My blog comment spam filter is ridiculously aggressive, so I didn't see your comment until today. Really sorry about that - I'm going to be checking moderated comments daily now. :(

You've probably already either solved the problem yourself, or have moved on, but just in case, my suggestion would be to uninstall AVISynth 2.6 and grab AVISynth+. I switched to it last year, and it's been both more stable and faster. There's a link to an updated tutorial at the top of this page now that can walk you through the process.

Unknown said...

I have the same problem and switching to AVISynth+ didn't fix it

Andrew Swan said...

Apologies for the delay in responding, I will be turning on "email follow-up comments".

Since I've never run into this issue, I wondered if there was anywhere else that might have suggestions. A Google search got me this thread:

https://forum.videohelp.com/threads/390035-Error-when-using-QTGMC-v3-361-with-Masktools-2-2-17-missing-mt_makediff

Basically: Make sure that you're using the versions of the dependent filters listed on the QTGMC page, don't mix 64 and 32-bit filters, if all else fails, re-download and install from scratch.

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