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)

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.

5 comments:

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.