Friday, June 10, 2016

The Odyssey of trying to upscale interlaced SD to HD without losing quality: Part 2

UPDATE: I have a new version of this tutorial up that is more stable, faster, and even potentially higher quality. Please check that out first. This post is kept up only for archival purposes.


You might want to read the first post in this series, because I'm not going to explain interlacing or what the various programs do again.

Since Part 1, I've discovered a few things:

VapourSynth currently requires the same plugins as AVISynth in order to run QTGMC, with the same stability issues and limitations. I'm actually trying to learn Python at the moment anyways, though, so I might revisit it again in the future and see if someone has ported the process natively in a way that supports multithreading without hacks.

Setting the topmost SetMTMode in my AVISynth script to (5, 10) versus (5, 12) appears to have solved my remaining stability issues. I'll be posting my full script down below.

I discovered AvsPmod, a program that loads AVISynth scripts with syntax highlighting and video preview. It makes adjusting scripts a heck of a lot easier. Because of AvsPmod, I don't need to use VirtualDub to check my work anymore.

I also discovered that I don't need VirtualDub to render the AVISynth scripts, because FFMPEG can load them directly. That means I can convert .avs scripts directly to any format that FFMPEG supports, including ProRes. This is awesome, because I can write .bat files that include all the settings I want for a particular codec/container/etc. All I have to do is change the input and output file names and double-click the .bat file. Also, while ProRes is awesome, I don't actually need to use an intermediate codec - I can render straight to a YouTube-friendly H.264 .mp4 file if I want without the (admittedly minor) quality loss of the extra step.

According to a few TV editors I asked, FFMPEG should probably not be used to render a ProRes deliverable for broadcast TV. Apparently, the implementation of ProRes is not recognized by Apple, and might be rejected by QC because of differences in embedded metadata. Not a problem for my current work, but if I did need to generate a file for broadcast, I would probably want to get a cheap Mac Mini or a month-long subscription to Scratch to make "official" ProRes deliverables. Incidentally, if I could afford to get a permanent license for Scratch, I would do it. Even with its oddball interface, it's still far and away the most responsive grading/compositing program I've ever used.

BIG DISCLAIMER: This process may not work, may crash, or do other things to your system. 

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.

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

SetMTMode (5, 10)
QTSource ("videofile.mov", audio= 1)
ConvertToYV12()
SetMTMode(2)
AssumeTFF()
QTGMC(preset="Slower, SourceMatch=3, Lossless=2, EdiThreads=1)
Distributor()
BilinearResize(720,540)
Crop(0,36,0,-36)
Spline64Resize(1280,720)

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

LimitedSharpenFaster()


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

QTGMC (Get the "Plugin Package for multithreading".)

LimitedSharpen (Optional, note that it requires RGTools to run. Get the x86 version of the latter in order for it to work within a script using QTGMC. )

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

AvsPmod

Install AVISynth. Put the AVISynth filters in the AVISynth Plugins directory, copy the multithreaded build of avisynth.dll to your system folder and replace the existing file. Copy a couple of system .dlls from the QTGMC package to your system folder. Extract FFMPEG and AvsPmod to their own folders. Set up FFMPEG to run from any directory on your PC by adding it to your PATH variable:

http://jonhall.info/how_to/setup_and_use_ffmpeg_on_windows  (skip to where it says "Windows Vista and Windows 7 users:")

In the same directory as your video file that you want to process, make an .avs script with the settings I listed above, changing the filename, source filter, and crop settings as necessary. 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.

Make a .bat file with 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_ks -profile:v 3 -qscale:v 9 -pix_fmt yuv422p10le "output.mov"

Change where necessary. The quotes around the filenames allow you to enter filenames with spaces in them.

I'll post a video soon with a full tutorial and more examples.

No comments:

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