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 in the last couple of weeks 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:

Friday, April 14, 2017

Deinterlacing HD footage without losing significant quality - Part 1

After my last post, I played around with bunch of different settings, and discovered that plain old FFMPEG can do decent deinterlacing. One of the reasons I looked into this is that QTGMC (my AVISynth deinterlacing plugin of choice) is ridiculously slow and prone to crashing when processing HD footage.

The problem with FFMPEG is that its documentation is enormous, and while it sometimes includes clear examples to show you how to use certain features, other times it's simply assumed that you're technically savvy enough to know what they're talking about. For example, trying to figure out the best method for deinterlacing involved me doing Google searches for each of the various methods. Normally, something like that would give results pretty quickly, but most of the substantive discussions were from at least five to nine (!) years ago or related to programs that use FFMPEG as a back-end engine, rather than as a standalone app. Even after all that, it wasn't immediately obvious which method would be superior, so I decided to run a few tests.

Method 1: kerndeint - a relatively simple deinterlacing method that automatically halves the framerate and is roughly on par with the default After Effects / Premiere Pro deinterlacer.

Method 2: w3fdif - Developed by the BBC, this is much closer to what I was looking for. Unfortunately it was originally designed for interlaced standard definition PAL content, and as such somehow does not have a mechanism for selecting Top Field First field order. It did successfully deinterlace the footage, but ended up looking herky-jerky as a result of the field order mismatch.

Method 3: nnedi - The method that QTGMC was designed to incorporate/replace. In theory, it does many of the same things, but to say that trying to figure out the options was confusing is an understatement.

Method 4: bwdif - To quote the FFMPEG documentation: “Motion adaptive deinterlacing based on yadif with the use of w3fdif and cubic interpolation algorithms”. This turned out to be the perfect solution. The default settings automatically detect field order (if it's set in the file's metadata) and do not introduce weird image artifacts, but still give decent deinterlacing. Oh, and it runs significantly faster than AVISynth+QTGMC. Like, 6-8 times as fast.

Now, there are some downsides to bwdif. QTGMC can introduce some ghosting artifacts (including misaligned chroma artifacts), but it can also pull more detail out of the original image. This makes bwdif a sub-par solution for SD interlaced to HD progressive upconversion. FFMPEG also doesn't have the (relatively) easy-to-read syntax of an AVISynth script, and definitely lacks the versatility of the insane range of plugins available for the latter.

As always, here’s an example of the command-line options so you can run this process on your system. Note that you have to use -vf before naming the filter in quotes:

ffmpeg -i "input_video.avi" -vf "bwdif" -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -c:a aac -b:a 320k "output_video.mp4" 

This is what I used to deinterlace a 60i HD file and re-encode it for YouTube. For ProRes encoding, see my previous post.