QTGMC DVD Encoding Guide version 0.2 (2/2018)

Written by LeoBloom for Empornium.

Feel free to share. This work is licensed under a Creative Commons Attribution 4.0 International License.

Version history:

0.2, 2/2018: Added detailed software and plugin installation instructions 0.1, 12/2017: Initial release

1

Contents Contents ...... 2 Background ...... 3 Why should I go through all this trouble, it’s just porn ...... 3 Required and recommended Software ...... 4 Required software/scripts: ...... 4 Recommended software/scripts: ...... 4 Software installation notes ...... 5 Avisynth plugin installation notes ...... 6 List of installed plugins after correct installation ...... 7 Ripping scenes from the DVD image and making them AviSynth readable ...... 8 Creating and tuning AviSynth scripts ...... 15 Encoding and Muxing ...... 18 Other QTGMC and AviSynth parameters ...... 21 Flickering at top/bottom ...... 21 Keeping original frame rate ...... 21 Sharpening ...... 21 Adjusting the color balance ...... 21 Retaining more noise ...... 22 Removing noise ...... 22 Using QTGMC with progressive material ...... 22 Detelecining/Inverse telecining ...... 22 Final Checks before Release ...... 24 Summary: Workflow and final words of wisdom ...... 24 Useful Batch Scripts and Commands ...... 25 DGIndex_all ...... 25 Create_avs ...... 25 Masterbatch (test encodes) ...... 26 Masterbatch ...... 26 Make_mono_and_keep_AC3 ...... 26 mkvmerge_all_from_vob ...... 26 Possible improvements and alternative routes to QTGMC ...... 27 Further reading ...... 27 Acknowledgements...... 28

2

Background Traditional CRT TVs used to display 60 half-images per second (USA/NTSC, 50 per second in Europe/PAL). As DVDs were introduced in the late 1990s, long before affordable LCD TVs were available, the vast majority of DVDs adheres to this standard and encodes its content as half images. 50% of the stored movie frames contain the odd lines, and 50% contain the even lines – the movie is interlaced. Assembling these alternating half images into full images is called deinterlacing and is necessary if the material is to be displayed on a non-CRT display. This deinterlacing process turns out to be surprisingly difficult, and most freely available encoding software like Handbrake gets it wrong. The results are left- over combing artifacts and/or aliasing (jagged diagonal lines) as well as shimmer around moving objects. The aim of this guide is to show how to deinterlace properly with much improved image quality using an algorithm called QTGMC. This algorithm substantially increases image quality through motion compensated temporal averaging of the images and eliminates the above-mentioned artifacts. QTGMC is written in AviSynth, a simple for . The concept of a scripting language may be intimidating, but it is actually very easy to use, thanks to a great editor called AvsPmod. With it, one can preview in real time the effects of changes in the script.

Why should I go through all this trouble, it’s just porn You are going to watch your favorite porn clips many more times than your favorite movies. It is worth putting some effort into making your favorite scenes as good looking as they can possibly get. Of course, all methods described here also work just as well for mainstream movies.

3

Required and recommended Software This guide is for Windows 7-10. QTMGC should be possible on and OS X as well, using alternative software (see page 27) or windows emulation/, but that is beyond my expertise. All software listed here is freeware.

Required software/scripts: FFmpeg (for encoding, 32 bit version): https://ffmpeg.org/download.html AviSynth (32 bit version, for running QTGMC): https://sourceforge.net/projects/avisynth2/ QTGMC and required scripts: http://avisynth.nl/index.php/QTGMC DGIndex and DGDecode plugins: http://avisynth.nl/index.php/DGDecode DVD Shrink: https://www.videohelp.com/software/DVD-Shrink MKVToolNix: https://www.fosshub.com/MKVToolNix.html VOB Merge: https://www.videohelp.com/software/VOBMerge (2.55 unofficial is much better than 2.52) AvsPmod: https://github.com/AvsPmod/AvsPmod/releases

Recommended software/scripts: DVD Decrypter: https://www.videohelp.com/software/DVD-Decrypter Mediainfo: https://mediaarea.net/en/MediaInfo/Download Avidemux: http://avidemux.sourceforge.net/ Sed: http://gnuwin32.sourceforge.net/packages/sed.htm LSFmod (for AviSynth): http://avisynth.nl/index.php/LSFmod TIVTC/TDecimate: http://avisynth.nl/index.php/TIVTC/TDecimate Decomb: http://avisynth.nl/index.php/Decomb

4

Software installation notes Some software is installed with installers, most is just unzipped from folders. I recommend creating a new directory in C:\ called “Software” or something similar, and extract these zip files there, into a sensible folder name. It is also possible to put these files into the Windows Program Files (x86) directory, but this is less advisable from a security point of view.

Installation instructions:

Avisynth: Default install, use 32 bit version DVDShrink: Default install VOBmerge: Extract into a folder, e.g. c:\software\vobmerge AvsPmod: Extract into a folder, e.g. c:\software\AvsPmod DGIndex: Extract into a folder, e.g. c:\software\DGIndex. One DLL file needs to be copied to the Avisynth plugin folder, see below. FFmpeg: Use 32 bit version. Extract into a folder, e.g. c:\software\ . Put the bin folder with the executables (e.g.c:\software\ffmpeg\bin) into the system environment PATH variable. Guide for setting environment variables: https://www.computerhope.com/issues/ch000549.htm

5

Avisynth plugin installation notes The process of installing these plugins is cumbersome indeed, so here are precise instructions. Make sure you only install the 32 bit (also sometimes called x86 or Win 32) versions of the plugins. Accidentally installing 64 bit versions seems to be the most common mistake. Almost all AviSynth plugins go into this folder: C:\Program Files (x86)\AviSynth\plugins .

This includes dll files and text files with the .asvi or .asv ending. All plugins listed on the QTGMC webpage need to be in that folder, with these exceptions: libfftw3-3.dll, libfftw3f-3.dll, and libfftw3l-3.dll need to go into a folder within your system environment PATH variable, e.g. c:\software\ffmpeg\bin if you have set the path up as described above.

The Dfttest manual even states that these files should go into the system directories "C:\Windows\SysWOW64" on a 64-bit OS or "C:\windows\system32" on a 32-bit OS, but in my hands simply including these files in the search path is sufficient.

Installation instructions:

QTGMC: copy QTGMC.avsi into Avisynth plugins directory Masktools2: masktools2.dll from the x86 zip folder goes into the Avisynth plugins directory MVtools2: mvtools2.dll, DePan.dll, and DePanEstimate.dll from the x86 zip folder go into the Avisynth plugins directory Nnedi3: nnedi3.dll from the x86\Release_W7 zip folder goes into the Avisynth plugins directory RgTools: RgTools.dll from x86 zip folder goes into the Avisynth plugins directory SMDegrain: SMDegrain_v3.1.2.93s.avsi goes into the Avisynth plugins directory AddGrainC: addgrain.avs from root and AddGrainC.dll from win32 zip folder go into the Avisynth plugins directory Dfttest: dfttest.dll goes into the Avisynth plugins directory, libfftw3f-3.dll goes into a directory within PATH (e.g. ffmpeg\bin). Same for libfftw3-3.dll and libfftw3l-3.dll, though these files are not required for basic QTGMC. EEDI2: EEDI2.dll from the 32 zip folder goes into the Avisynth plugins directory Eedi3: eedi3.dll from x86 zip folder goes into the Avisynth plugins directory FFT3DFilter: fft3dfilter.dll from x86 zip folder goes into the Avisynth plugins directory KNLMeansCL: KNLMeansCL.dll from the zip root goes into the Avisynth plugins directory PlanarTools: PlanarTools.dll from the zip root goes into the Avisynth plugins directory Tdeint: TDeint.dll goes into the Avisynth plugins directory Yadifmod2: yadifmod2.dll from root directory goes into the Avisynth plugins directory AnimeIVTC: AnimeIVTCmod_v2.20.avsi goes into the Avisynth plugins directory DGDecode: copy DGDecode.dll from the DGIndex software directory (see software installation notes) into the Avisynth plugins directory

6

List of installed plugins after correct installation

Basic QTGMC configuration Extended QTGMC Configuration

AviSynth addgrain.avs addgrain.avs Plugins AddGrainC.dll AddGrainC.dll Folder AnimeIVTCmod_v2.20.avsi AnimeIVTCmod_v2.20.avsi colors_rgb.avsi colors_rgb.avsi DePan.dll Decomb.dll DePanEstimate.dll DePan.dll dfttest.dll DePanEstimate.dll DGDecode.dll dfttest.dll DirectShowSource.dll DGDecode.dll EEDI2.dll DirectShowSource.dll eedi3.dll EEDI2.dll fft3dfilter.dll eedi3.dll KNLMeansCL.dll fft3dfilter.dll masktools2.dll KNLMeansCL.dll mvtools2.dll LoadPluginEx.dll nnedi3.dll LSFmod.v1.9.avsi PlanarTools.dll masktools2.dll QTGMC.avsi mvtools2.dll RgTools.dll nnedi3.dll SMDegrain_v3.1.2.93s.avsi PlanarTools.dll TCPDeliver.dll QTGMC.avsi TDeint.dll RgTools.dll yadifmod2.dll SMDegrain_v3.1.2.93s.avsi TCPDeliver.dll TDeint.dll TIVTC.dll variableblur.dll warpsharp.dll yadifmod2.dll

System Path libfftw3f-3.dll libfftw3-3.dll libfftw3f-3.dll libfftw3l-3.dll

7

Ripping scenes from the DVD image and making them AviSynth readable Rip the DVD to hard drive using your favorite DVD ripping software, either as a DVD folder with VIDEO_TS inside, or as an ISO image. I recommend DVD Decrypter (recommended software) for this purpose. Most porn DVDs are not copy protected, so you could even skip this step. But it is faster and more comfortable to work with a DVD image than the raw DVD.

Once you have the DVD ripped, open it with DVD Shrink (Fig 1). Use Open Disc for ISOs and physical DVDs, Open Files for DVD images.

Fig. 1: DVD opened in DVD Shrink

8

Click on the Re-author button to enter reauthoring mode (Fig.2):

Fig. 2: Reauthor mode in DVD Shrink

Drag the main movie (Title 5 in Fig. 2) to the left. In principle, one could extract the entire movie now. However it is often preferable to extract single scenes, especially for split scene releases. Otherwise it might later be impossible to cut the scene at the precise location you want to cut.

Right-click the dragged-over file and select Set Start/End Frames (Fig 2). This pops up a new window (Fig. 3) in which we can select the beginning and ending of the scene. This can be done either by using the DVD chapters or frame-based with the forward and reverse button. Keep in mind that it is always easy to remove something from the end of the video, but often impossible to remove a precise frame number from the beginning. Therefore, try to be very precise with the start frame.

9

Fig. 3: Selecting the beginning and end of a scene in DVD Shrink

Press OK to confirm the selection. Now click on Compression Settings and select “No Compression”. (Fig. 4). This is very important, otherwise you could severely damage your video quality in this step. To prevent accidental compression here, it might also be a good idea to change the target size in the DVD shrink options to DVD9.

10

Fig. 4: It is important to export the video stream without compression

Now press Backup! and choose your save location (Fig 5). Personally, I use a Ram Disk as temporary storage, but any drive will do.

Fig. 5: DVD Shrink Save Dialogue

11

Many scenes and certainly all movies will be split in several DVD files. For the further steps, it is preferable to have only one VOB file per scene/film. Therefore, we merge the VOB files using VOBMerge (Fig 6, make sure to select VOB in the options). This step is not necessary if the scene was already contained in a single VOB file. In that case, it might be good to give it a more informative name than “VTS_01_1.VOB”.

Fig. 6: VOBMerge

Once you are done with creating all VOB files you want to encode, move them all into a new directory, which will be your working directory for encoding.

In order to import the VOB files into AviSynth, we need to create a d2v file using the program DGIndex (there are other ways to import VOB files into AviSynth, but they are less precise). Using DGIndex also has the added advantage that it extracts the audio (usually as an AC3 file), so that we can restore the untouched audio after encoding. Open the VOB in DGIndex and select Save Project (Fig. 7). I also wrote a batch file that does this automatically for all VOB files in one directory, which makes it easier if you have a large number of VOB files (See Useful Batch Scripts).

12

Fig. 7: Creating D2V and audio files with DGIndex

Now we should have a working directory with a VOB file, a D2V file, and an Audio file (mostly AC3) for each scene we want to encode (Fig. 8) and are ready to start with the actual encoding work.

13

Fig. 8: Working directory after all preparations are done. The .mp2 files are an older audio codec in use before AC3. I recommend using Total Commander instead of Windows Explorer.

14

Creating and tuning AviSynth scripts Rather than passing the video file directly to the encoder as one would usually do, we are passing an AviSynth script instead. This AviSynth script therefore has to handle the opening of the file, and can include instructions on what to do with each frame. This is the standard script I start with: 1 MPEG2Source("InputFileName.d2v", cpu=0) 2 ConvertToYV12() # Make sure color space is correct 3 AssumeTFF() # Check this manually with small samples for each file 4 QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1) 5 BilinearResize(720,540) # Does some AA as well 6 Crop(0,0,-0,-0) # Adjust to each file in AvsPmod Script 1 (AviSynth): Standard AviSynth script for QTGMC. Comments start with #. When you copy/paste, make sure there are no extra line breaks in individual lines. Let us go through each line and see what they do. Line 1: MPEG2Source("InputFileName.d2v", cpu=0) Here we load the file InputFileName.d2v, which is corresponding to InputFileName.vob. The cpu=0 instruction prevents any post-processing but can be modified to include deblocking if so desired. Line 2: ConvertToYV12() This converts the DVD into the only color space QTGMC can work with. Most DVDs are already in YV12, so this command will do nothing. Line 3: AssumeTFF() Here, we tell AviSynth how the deinterlaced images are woven together. The 2 options are Top Field First (AssumeTFF) and Bottom Field First (AssumeBFF). More than 90 percent of porn DVDs I have seen are TFF. Often (but not always) one can look up this information in MediaInfo (Scan order, in HTML view). If the wrong parameter is chosen, the image will appear very unnatural and jerky, very easy to identify. One reason why it pays off to do small test encodes before starting to full encoding. Line 4: QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1) Now this is where the magic happens and QTGMC gets called and applied to each frame. Let us go through the parameters here: Preset: The slower the better the quality. “Placebo” is the slowest and best, “Very Slow” and “Slower” are faster and still deliver good quality. SourceMatch=3: Here, QTGMC gets instructed to make its magically deinterlaced image as close to the original as possible without introducing shimmering Lossless=2: Parameter for SourceMatch, include even more of the original into the deinterlaced frame MatchEnhance=0.75: Parameter for SourceMatch, makes image slightly sharper and enhances detail EdiThreads=1: Use only a single . Multi-threaded use required a modified AviSynth, is very unstable, and sometimes leads to bad frames in the encode.

15

Line 5: BilinearResize(720,540) DVDs are encoded anamorphic, for 4:3 DVDs that means the image will get displayed as 720x540 , but is actually encoded as 720x480 pixels. In this line, the image is interpolated to the correct aspect ratio using the BilinearResize algorithm, which helps reduce residual aliasing. Other possible algorithms in AviSynth are for example BicubicResize or Spline64Resize. The differences between these algorithms for such small interpolations (480540: 12.5%) are very subtle and almost impossible to see. It is not necessary to do this interpolation, the resizing can also be done later via a file flag, which saves space when encoding. Doing the resizing in script however can have advantages if further post-processing is desired, as those effects will be applied to undistorted geometries. In the end, whether to resize here or not is a matter of taste and style. Line 6: Crop(0,0,-0,-0) Crop away black bars or damaged lines at the sides of the video. The four parameters are in order Left, Top, Right, Bottom, with the last two parameters needing a minus in front of them. Crop(2,4,-6,- 8)will thus crop two pixels on the left, 4 pixels at the top, 6 pixels on the right, and 8 pixels at the bottom. Only even numbers of pixels can be cropped from any edge. You must remove black bars from your image, especially on the top and bottom, as otherwise the encoded file will not fill the full screen. Oftentimes one would need to crop a single line, which is impossible, and then has to decide whether to crop two lines or leave a single black line in. This is again a matter of taste, personally I much prefer to have clean edge a crop generously. Cropping is best adjusted in AvsPmod, and can even be done there automatically. To open the file in AvsPmod, use any text editor, copy/paste the script in it, and save it under YourFavoriteFilename.avs (AVS is the ending for AviSynth Scripts). Now you can load this avs file into AvsPmod. As soon as you click on the time bar at the bottom, an image as rendered by AviSynth will appear (Fig. 9), or an error message should the script contain a mistake.

16

Fig 9: AvsPmod with syntax-highlighted script and preview image of the AviSynth output In practice, QTGMC is so slow that it can take a few seconds for the output preview to appear. Here you can adjust the crop parameters and play with other parameters to see their effects. To apply changes in the script to the output image, hit F5 or advance a frame using the fast forward button. Once you are happy with the results, save the results. Do this for every scene you wish to encode. Further down I present a script to quickly generate default avs files for each video file to accelerate the process. Once avs files for all scenes have been created, we are ready for encoding.

17

Encoding and Muxing Encoding videos is just as complex a topic as deinterlacing, and I will not go into details. Since the aim of QTGMC encodes is maximal quality, I recommend to err on the side of caution and use high bitrates. Using QTMGC takes so much time and effort that it would be unwise to throw any quality away at the encoding stage just to save a few megabytes. With regards to codecs, after many careful frame-to-frame comparisons I have come to the conclusion that H.264 produces higher quality SD encoded than H.265, even at identical bitrates, provided the H.264 bitrate is high enough. I.e. a 3000 kb/s H.264 SD encode (Very Slow settings) looks better than a 3000 kb/s H.265 SD encode (Medium settings). As H.265 is still in development, this might change at some point, but for now I recommend using H264 at CRFs of 18-15 (corresponding to bitrates between 2000 and 4000 kb/s).

To encode the video, open a command line and type or paste: ffmpeg -i "InputFileName.avs" -c:v libx264 -preset veryslow -vlevel 4.1 - me_range 32 -crf 17 -deblock -3:-3 "OutputFileName.mkv"

This will generate the video file OutputFileName.mkv from the AviSynth script InputFileName.avs. The most important parameter to adjust is -crf, the lower the value the higher the quality and file size. I would not go higher than 18 for QTGMC, and if you are encoding your favorite file in the world and just want the best quality independent of size, go for 16 or even 15. The preset determines the encoding speed, at veryslow and above, ending will be faster than deinterlacing. The slower the encoding speed, the smaller the file. There are also effects of encoding speed on quality, but those are complex and unintuitive. Suffice it to say that there is no need for placebo encoding speed with regards to having the best quality (encoding speed is completely separate from the QTGMC deinterlacing speed). The vlevel, me_range, and deblock parameters are fine tuning the encode and have only minor effects.

QTGMC encodes with the setting presented here so far typically encode at 0.1 – 0.05 times real time on a 4GHz Intel i5 quadcore (at 60% CPU usage). That means it takes 10-20 hours on my current machine to encode 1 hour of video. Since it would be very upsetting to find a fault with the encode only after such a long time, it is advisable to encode short preview clips first. For this, you can use the following command: ffmpeg -ss 00:01:00 –t 15 -i "InputFileName.avs" -c:v libx264 -preset veryfast -crf 17 "OutputFileNameTest.mkv"

The -ss parameter contains the start time (one minute in the example above) and the -t parameter sets the length in seconds (15 seconds in the example above). Here you can check if you like the deinterlacing settings, cropping, and if TFF/BFF have been selected correctly. A batch file for batch encoding of many scenes is available in the batch script section.

18

Ok, now we have encoded the video but no audio yet. To restore the audio track, we will us MKVToolNix. Load the newly made mkv video file into MKVToolNix. Also drag and drop the corresponding audio file (most likely AC3) into MKVToolNix (Fig. 10). At the bottom are the tracks. Deselect the tags and global tags. Now click on the audio track to see the options on the right. Note how each audio file has delay information in its filename. MKVToolNix is smart and automatically enters the delay in the delay box. Double check that this information is there, because otherwise audio will not be in sync.

Fig. 10: MKVToolnix, with audio options

Now click on the video track to see the corresponding options on the right (Fig. 11). Here you can adjust the aspect ratio (absolutely necessary if you chose not to interpolate the video to 540 lines before). I like to assume that the cropped video should correspond to a 4:3 aspect ratio in the camera and that any black bars were just the result of the DVD transfer. Therefore, I set the AR to 4/3 (1.333). But it is also fine to leave it untouched after resizing. Again, a matter of personal taste.

19

Fig. 11: MKVToolNix Video Options

Press Start Multiplexing, and your video in will be saved in your desired aspect ratio with the untouched original audio, in sync to the video. Your video is now properly QTGMC deinterlaced.

20

Other QTGMC and AviSynth parameters In this section I will present a select few additional options and possibilities with QTGMC and AviSynth as well as a few common obstacles and how to overcome them. One very important method to see the effects of parameter changes is to save screenshots from AvsPmod. This can be done via the Video menu / Save image as. Save an image before and after and compare (use # to comment functions in and out). Do not forget to press F5 before saving. Flickering at top/bottom Use the Border parameter in QTGMC: QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1,Border=True)

Keeping original frame rate QTGMC will normally double the framerate, which leads to a smoothing effect. The doubled frames are all of high quality, unlike interpolated frames from progressive material, which often look pretty bad. However if for some reason you want to keep the original framerate, change line 4 of script 1 to: QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1).SelectEven() This will keep only every other frame (counterintuitively the odd frames, as frame 1 is frame 0 in AviSynth).

Sharpening To sharpen the output image, you can adjust the Sharpness parameter for QTGMC. Usually it is 0.2 with the SourceMatch mode, 1.0 without. Be careful with this parameter to not induce over-sharpening artifacts like halos. Example: QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1, Sharpness=0.4) A better and more subtle way to introduce sharpening is the modified limited sharpen faster script (needs to be in the plugin folder). Add this to the end of your script (after resizing and cropping): LSFmod(defaults="slow",ss_x=2.0, ss_y=2.0, strength=50,Smode = 5) You can adjust the strength parameter to your liking, usually I use something between 40 and 80.

Adjusting the color balance Sometime when colors are washed out, this line can help: ColorYUV(levels="TV->PC") #Do before QTGMC! For more refined adjustments, use the Levels and Tweak commands (see AviSynth documentation, beyond the scope of this guide). Use any balancing refinements before QTGMC to get better color gradients / less banding.

21

Retaining more noise If QTGMC removes too much noise/grain for your liking, there is a quick and easy way to preserve it, just add the EZKeepGrain parameter to QTGMC: QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1, EZKeepGrain=2, NoisePreset="Slow") Adjust EZKeepGrain to your liking, the higher the number, the more noise is retained (which will of course increase the size of the encoded file). There are also much more refined noise parameters in QTGMC, but I have not found them to be decidedly better than the easy presets.

Removing noise While film grain often looks good, some sources have undesirable noise. To remove that, easy presets can also be used. If denoising is desired, it also makes no sense to use the Sourcematch and Lossless options. Here is how to use the EZDenoise parameter (cannot be used together with EZKeepGrain): QTGMC(preset="Slower", EdiThreads=1,EZDenoise=2.0, NoisePreset="Slow",NoiseRestore=0.0, GrainRestore=0.0,Border=True)

Using QTGMC with progressive material QTGMC can be used with progressive material – just the lossless parameter is unavailable, and frames are not doubled. With this, poorly deinterlaced material can often be rescued. The proper call for QTGMC on progressive material is: QTGMC(preset="Placebo", InputType=1, EdiThreads=1, SourceMatch=3) InputType for progressive material can be 1 or 2, 2 is better for noisier sources.

Detelecining/Inverse telecining Whenever the output of QTGMC does not look quite right, it is often that the DVD is not properly interlaced. To test this, comment out QTGMC and go through frames step by step and watch for interlacing artifacts. If there are none, the source is progressive, which sometimes happens. Ironically, a QTGMC treated interlaced source often looks better than an encode from a progressive encode. If you see a pattern of 3 progressive frames followed by 2 interlaced frames, then your source is telecined. This is a shitty method to adjust the framerate from 24 fps to 30/60 fps. QTGMC encodes from telecined sources might stutter slightly and not be fully anti-aliased, i.e. there will still be jagged edges. There are two ways to remove the telecining with QTGMC.

22

The precise way uses the TIVTC plugin with QTGMC as external deinterlacer. Here is an example script I used for Fashionistas: 1 MPEG2Source("Fash3.d2v", cpu=0) 2 ConvertToYV12()# Make sure color space is correct 3 AssumeTFF() # Check this manually with small samples for each file 4 deint=QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1).SelectEven() 5 TFM(order=1, mode=1, PP=1,clip2=deint,slow=2) #PP=1 otherwise QTGMC not used properly. Order=1 for TFF, 0 for BFF 6 tdecimate() 7 BilinearResize(720,540) # Does some AA as well 8 Crop(4,0,-4,-0) # Adjust to each file in AvsPmod 9 QTGMC(preset="Placebo", InputType=2, EdiThreads=1,Sharpness=0.0,EZKeepGrain=2,SourceMatch=3, MatchEnhance=0.3) Script 2 (AviSynth): Detelecining with TFM/tdecimate and QTGMC as external and secondary deinterlacer In line 4 we define QTGMC as an external deinterlacer. TFM in line 5 then undoes the telecining and leaves doubled frames behind. Tdecimate in line 6 removes the doubled frames. In line 9 we run QTGMC a second time in progressive mode to clean up the image. We do not add any further sharpness here, as the image has already been processed once, and instead keep all the details we can. Without the second run of QTGMC, not all aliasing is removed, as the TFM function is unfortunately not perfect and as it is sometimes not possible to automatically detelecine a movie perfectly. Sometimes this method does not produce watchable results (telecine is pure horror), in those cases I have had moderate success with this second method I came up with: 1 MPEG2Source("AT4.d2v", cpu=0) 2 ConvertToYV12() # Make sure color space is correct 3 AssumeBFF() # Check this manually with small samples for each file 4 QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1,sharpness=0.4, NoiseProcess=1, NoiseRestore=0.7, Sigma=1.5 ).selecteven() 5 Decimate(cycle=5, mode=0, threshold=0.0, threshold2=3.0, quality=2) 6 BilinearResize(720,540) # Does some AA as well 7 Crop(4,0,-4,-0) # Adjust to each file in AvsPmod 8 LSFmod(defaults="slow",ss_x=2.0, ss_y=2.0, strength=50,Smode = 5) Script 3 (AviSynth): Approximate detelecining with QTGMC Here we run QTGMC as usual, but without frame doubling. The result will not be perfect, but good enough. However we end up with doubled frames. To get rid of these, we use the Decimate function of the decomb package, as it can be convinced to remove doubled frames that are not exactly identical. The problems with telecine is another great argument for encoding scene by scene, as I have seen DVDs where parts were telecined and other parts were properly interlaced. Madness!

23

Final Checks before Release If you want to share your material with others, e.g. via torrent, here are some things I check before “publication”: • Check that all scene endings are on point, otherwise remove superfluous frames with Avidemux. The MKVToolnix treatment is necessary after Avidemux again. • Check if the audio is in sync. Jump to the final third of the file to see. Slaps are especially useful for determining synchronicity. If things are not in sync, adjust the delay parameter in MKVToolnix (Fig. 10) • Give your files decent filenames. Ideally include the title of the movie, scene number and performer names. • If you use seedbox: do a CRC check to see that the files in your seedbox are identical to your local copy.

Summary: Workflow and final words of wisdom • Isolate individual scenes as VOBs with DVDShrink join with VOBMerge if necessary • Generate d2vfiles and audio tracks with DGIndex • Generate and adjust AviSynth scrips for each file • Encode with FFmpeg • Mux the sound back in in and adjust the aspect ratio

QTGMC is very good and often looks significantly better than the source footage, due to temporal interpolation. But of course it cannot do miracles, and low-quality sources lead to only mediocre encodes. The best results are obtained from DVDs filmed with digital cameras, here the result can look almost as good as modern 540p HD encodes. If the DVD was originally shot on film, the results are much subtler and depend very strongly on the transfer quality from film to DVD. In the end, the only way to get the best possible encodes (by your tastes) is to do a lot of trial and error. Some scenes I have tried with over 50 different settings until I could decide for the best one. AvsPmod and short test encodes are your best friends. Finally, the intention of this guide is to make QTGMC more accessible and lead to more encodes. So if you have done a great encode, think about sharing it with the community.

24

Useful Batch Scripts and Commands Here are some scripts and commands I came up with when doing large batches of encodes. They are overkill for encoding one or two scenes, but very useful if you are encoding >10 scenes in parallel.

DGIndex_all: runs DGIndex on all vob files in the directory. Adjust path to DGIndex as necessary.

1 @echo off 2 if exist run_dgindex.bat del run_dgindex.bat 3 echo @echo off>>run_dgindex.bat 4 for %%A IN (*.VOB) do ( 5 echo "C:\DGIndex\DGIndex.exe" -i "%%A" -om 2 -o "%%~nA" -hide -exit >>run_dgindex.bat 6 echo del "%%~nA.log" >>run_dgindex.bat 7 ) 8 run_dgindex.bat Script 4: DGIndex_all.bat – Create d2v files and extract audio for each vob file

Create_avs: Creates avs files for each vob file in the directory based off a template (MASTER.avsmaster, script 5b). Required the installation of sed (see recommended software).

1 @echo off 2 echo Really Want to Create New AVS files? 3 pause 4 for %%A IN (*.VOB) do ( 5 "C:\Program Files (x86)\GnuWin32\bin\sed.exe" "s/MASTER.d2v/%%~nA.d2v/g" "MASTER.avsmaster">"%%~nA.avs" 6 ) Script 5a: create_avs.bat – Create avs files for each VOB file. Warning: existing avs files will be overwritten.

1 MPEG2Source("MASTER.d2v", cpu=0) 2 ConvertToYV12() # Make sure color space is correct 3 AssumeTFF() # Check this manually with small samples for each file 4 QTGMC(preset="Placebo", SourceMatch=3, Lossless=2, MatchEnhance=0.75, EdiThreads=1) 5 BilinearResize(720,540) # Does some AA as well 6 Crop(0,0,-0,-0) # Adjust to each file in AvsPmod Script 5b (AviSynth): MASTER.avsmaster – Variation of script 1 with MASTER.d2v as filename that gets replaced for each vob file by create_avs.bat. The master script can of course be adjusted to your personal preferences.

25

Masterbatch (test encodes): creates a batch file with instructions to make test encodes (15 seconds long, starting at the 1 minute mark) of all avs files in the directory. Just a single line: for %%A IN (*.avs) do echo ffmpeg -ss 00:01:00 –t 15 -i "%%A" -c:v libx264 - preset veryslow -vlevel 4.1 -me_range 32 -crf 17 -deblock -3:-3 "%%A.mkv">>testencode_all.bat Warning: if the scenes are shorter than the time specified with the -ss parameter, the script will hang.

Masterbatch: create a batch file with instructions to encode all avs files in the directory. Just a single line: for %%A IN (*.avs) do echo ffmpeg -i "%%A" -c:v libx264 -preset veryslow - vlevel 4.1 -me_range 32 -crf 17 -deblock -3:-3 "%%A.mkv">>encode_all.bat On a Quadcore, I recommend manually splitting up encode_all.bat to encode_all1.bat and encode_all2.bat of roughly similar sizes and running them in parallel. On 6 or 8-core systems, three parallel batch files might be necessary to reach 100% CPU utilization.

Make_mono_and_keep_AC3: Creates a mono AAC track as audio track 1 and keeps the original AC3 as track 2. Video is untouched. I have used this when the stereo mix on the AC3 was broken, e.g. sound only from the left speaker. Just a single line: ffmpeg -i "input.mkv" -map 0:v -c:v copy -map 0:a -c:a:0 aac -ac 1 -vbr 5 - map 0:a -c:a:1 copy "output.mkv"

mkvmerge_all_from_vob: I highly recommend doing the final muxing manually with MKVToolnix Gui as a final manual quality check. However if you must automate it, you can use this command (just a single line): for %%A IN (*.mkv) do "C:\Program Files\MKVToolNix\mkvmerge.exe" "%%A" -o "%%~nA.muxed.mkv" -D "%%~nA.vob" --aspect-ratio 1:4/3 Warning: this does not use the delay information from the audio files created by DGIndex and instead uses the VOB files as audio source. MKVmerge gives out a warning that the synchronization may have been lost. So far everything seemed alright in test scenarios (I do not use this for releases), but better triple check that audio is in sync after using this command.

26

Possible improvements and alternative routes to QTGMC This might never get implemented by myself: if it ain’t broke, don’t fix it. But you might be interested in testing these out: Multi-threading: QTGMC can be run in multi-threaded mode using a multithreaded AviSynth hack. I find this to be very unstable and have even discovered bad frames in encodes from multi-threaded QTGMC, so I am not using it. Instead, to use my CPU fully, I run two single-threaded QTGMC encodes at the same time (through 2 batch files).

Ripping scenes with DGindex: It is possible to extract individual scenes from DVDs via DGIndex with a larger, more comfortable preview window than in DVDShrink. This per default does not generate isolated VOB files, but d2v files referring to the original VOBs.

VapourSynth: this is a python-based and probably vastly superior rewrite of AviSynth. QTGMC has been ported for it as well. It might be much better than AviSynth, but I have not tested it yet. http://www.vapoursynth.com

meGUI: a software package many swear by that I find much harder to use than command line and scripts, although its intended purpose is probably the opposite. I am not really sure what it does, I would guess it helps with the AviSynth script generation and encoding. https://sourceforge.net/projects/megui

Staxrip: Staxrip is a big encoding package that apparently has QTGMC built in. Maybe you can do everything in this tutorial with a few clicks. I have not had time to test it. https://github.com/stax76/staxrip

Hybrid: Hybrid is another encoding package with QTGMC built in if I understand correctly. http://www.selur.de

Further reading QTGMC manual: http://avisynth.nl/index.php/QTGMC AviSynth main page: http://avisynth.nl/index.php/Main_Page AviSynth internal filters: http://avisynth.nl/index.php/Internal_filters AviSynth external filters: http://avisynth.nl/index.php/External_filters AviSynth.org.ru (Great English AviSynth Manual): http://avisynth.org.ru/docs/english/ FFmpeg wiki: https://trac.ffmpeg.org/wiki A Guide to x264, Detail Loss & Desperation (Mosc, February 2, 2016)

27

Acknowledgements I am very grateful to Andrew Swan who made a fantastic tutorial video titled “Deinterlacing and upscaling SD footage using QTGMC”: https://www.youtube.com/watch?v=Kqj87hg-7k8 I always thought AviSynth was complicated, but through his video learned it was easy to use, especially with AvsPmod. It was also the first understandable QTGMC tutorial I could find on the net (I hope to be number 2), and I had been looking for a year or so. I highly recommend you watch it, and without it I would have never embarked on this journey.

A very big “Thank You!” also goes to everybody who shares untouched DVD rips, especially Bootycollector and robbis.

Furthermore, I would like to thank pervernator for proofreading the first version of this guide as well as sharing some rare DVDs!

Of course I would also like to thank all the authors of the software and AviSynth scripts mentioned in this guide. It is fantastic that such a wealth of sometimes exotic software is provided free of charge. You are all wonderful people!

Last but not least I would like to thank the admins and staff as well as fellow members at Empornium for creating one of my favorite places on the internet, conducive to falling down rabbit holes such as this one.

28