The big problems with badly degraded video are the extra filtering and the processing time they consume. Then there is the fact that the results can't look as good as a source that's more or less intact to begin with. A lot of damage just can't be repaired. On other hand, even a so-called "clean" analog source still needs some work, and one still needs a toolbox of effective filters to get improved results. The difference between a poor source and a good source is the vast difference in the quality of the results.
Below are script and filter details for the script in the preceding post:
Import("D:\Avisynth 2.5\plugins\MDG2.avs")
It happens that the MDG2 plugin is a script-coded .avs file. Avisynth plugins come in three formats:
.dll,
.avsi, and
.avs. A .dll and an .avsi plugin load automatically when a script calls for them. An .avs is a plain text file whose coded text must be explicitly imported into your script using the
Import() function. You could also copy the text yourself into the bottom of your script, but it's a pain and some of the .avs filters have hundreds of lines of code.
Import():
http://avisynth.nl/index.php/Internal_functions#Import.
AviSource ("J:\forum\faq\nai1ed\A\sample1.avi")
The
AviSource() function open and decodes many video codecs if the codec is installed on your PC. Once decoded, the file as AVisynth delivers it is uncompressed. If you want compressed output, you'll have to recompreess it yourself, for instance by telling
VirtualDub to do it.
AviSource():
http://avisynth.nl/index.php/AviSource.
ColorYUV(cont_y=-25)
Levels(16,0.90,255,16,245,dither=true,coring=false )
Tweak(sat=0.6,StartHue=275,EndHue=340,dither=true, coring=false)
Tweak(sat=0.75,StartHue=160,EndHue=275,dither=true ,coring=false)
Tweak(sat=1.3,StartHue=60,EndHue=160,dither=true,c oring=false)
ColorYUV() is a multi-faceted builtin function that works on contrast, gamma, high end extension, black levels, and so forth. Its wiki page gives you a whole catalog of things it can adjust. Here, it's used to lower contrast. There are different kinds of contrast controls; with ColorYUV, contrast expands pixel values (luminance) from the center outward in each direction or, with negative values it shrinks pixel values toward the middle. Because a histogram showed luminance extending outside safe values at both ends of the dark-to-bright spectrum,
cont_y was used to shrink the response curve toward the middle of the spectrum. As you can guess by its name, it works only in YUV colorspaces.
ColorYUV():
http://avisynth.nl/index.php/ColorYUV
The builtin
Levels() function works on luminance pixel values and on gamma (midtone response). Here, it adjusts luminance levels to stay within the range y=16-235. RGB display will expand YUV from 16-235 to 0-255. If the YUV range is already darker than 16 or brighter than 235, an RGB display or process will destroy the out of range values (aka "clipping"). The numbers in the
Levels() command indicate the following values, in this order: input dark values, desired gamma, input bright values, desired dark output adjust, desired bright output adjust.
Dither and
coring are explained on the Levels() wiki page (
http://avisynth.nl/index.php/Levels).
The
Tweak() statements (
http://avisynth.nl/index.php/Tweak) adjust saturation in the YUV color range shown by the numbers in the startHue and endhue values. The numbers reflect the positions of colors in degrees around the YUV color wheel:
The images below are YUV vectorscopes that display measured saturation values. The vectorscope on the left shows the original saturation pattern before filtering. The pattern indicates an oversupply of saturation in the blue-cyan and green-yellow areas, and a deficit in red. The vectorscope on the right shows the more evenly balanced result of the Tweak and ColorYUV statements with reduced blue-cyan/yellow levels and more populated reds.
Avisynth histograms/vectorscopes:
http://avisynth.nl/index.php/Histogram
AssumeTFF()
SeparateFields()
FixVHSOversharp(20,16,12)
FixVHSOversharpL(20,12,8)
CNR2(mode="ooo", scdthr=255.0, ln=255, lm=222, un=255, um=255, vn=255, vm=255)
Weave()
Avisynth's default field order priority for interlaced or telecined video is Bottom Field First (BFF). But most of the time you'll encounter Top Field First (TFF).
AssumeTFF() informs Avisynth that the current video's field order is TFF. Then,
SeparateFields() breaks apart each interlaced frame into its two half-height image fields. This is a non-destructive form of deinterlace, which will be required by the Avisynth filters that immediately follow.
AssumeTFF():
http://avisynth.nl/index.php/Parity
SeparateFields():
http://avisynth.nl/index.php/SeparateFields
FixVHSOversharp(20,16,12) and
FixVHSOversharpL(20,12,8) go after edge halos and ghosting on right and left edges respectively. These two filters aren't enough to completely fix the ugly edge halos in the clip, and in fact will simply soften edge halos a bit -- which is what is desired here because of the over-sharpened halos themselves. The numeric values in the syntax for the two FixVHSOversharp commands are explained in the help file that comes with the filter and are actually copied from the documented samples. FixVHSOversharp works only in a YUY2 colorspace.
CNR2 is a chroma filter that helps neutralize color streaks and blotches. The values that follow the CNR2 command are actually defaults except for "
mode="ooo" which activates a "wide" disturbance detection for Y (luma), U (yellow-blue), and V (red-green) channels. The
scdthr,
ln,
lm,
un,
um,
vn, and
vm set luminance and chroma filtering limits for scene changes, luma, U, and V channels. The numbers shown are defaults except for the "222" which tends to reflect an average peak value for luminance "hot spots" in VHS video. You could probably use all values at default 255 with no problems.
FixVHSOvershartp.dll:
http://www.digitalfaq.com/forum/atta...ll_20030723zip.
CNR2.dll is at
http://www.digitalfaq.com/forum/atta...d-cnr2_v261zip.
Weave() is the function that puts all the separated fields back into their original order and position in the interlaced frames.
http://avisynth.nl/index.php/Weave.
ConvertToYV12(interlaced=true)
QTGMC(preset="medium",FPSdivisor=2,ChromaMotion=tr ue,border=true,\
ChromaNoise=true,GrainRestore=0.3,sharpness=0.7)
Your sample clip used YUY2 color, preferred because it's more like the YPbPr color in VHS, but the filters that follow require YV12 color. Leave these conversions to Avisynth, which does it with great precision (many editors make a mess of YV12 conversions). For any colorspace conversion you must tell Avisynth whether or not the video is interlaced. Note that telecined video, the conversion of film speed to 29.97fps by inserted qdditional fields, is considered a form of interlace. Other conversion function parameters can be used, but usually you'll just ignore them and use defaults.
ConvertToYV12():
http://avisynth.nl/index.php/Convert
With
QTGMC you come to one of the heavy-hitters. This is a deinterlacer. In using complex motion-compensated algorithms and additional support filters to deinterlace as cleanly as possible (something most deinterlacers
don't do), one side effect of QTGMC is that it also denoises in several ways. It reduces grain, cleans edges, and smooths uneven motion to a certain extent. The
preset="medium" parameter sets up a reasonably efficient denoising level (there are faster presets and slower ones).
FPSdivisor=2 is a special parameter that discards alternate fields and maintains the original 29.97fps framerate. This is a decision you'll have to make: field decimation can make for less smooth motion that interlaced or double-rate video. If you retained all fields, interlacing would play at 59.94
fields per second. if you double-rate interlace, the video would play at 59.94
frames per second. But there's not that much motion in your clip. Sports video would be a different story. I decided to discard fields because of all the interlace damage and noise inflicted on this tape. The normal way would be to retain all fields, run special filters to calm buzzing edges and combing, and re-interlace after filtering -- but with this damaged video the edge noise and excessive combing would be intolerable.
The extra cleanup parameters that are activated in the QTGMC statement are
ChromaMotion (consider chroma, not just luma, when analyzing motion),
border (pad a little vertically to avoid top or bottom border flutter),
ChromaNoise (clean color noise as well as luma noise (grain)),
Grainrestore (restore a very small amount of original grain to avoid a plastic over-filtered look), and reduce
Sharpness a little so sharpened halos won't look worse.
QTGMC and its pile of support files and extra filters come as a 32-bit package. The .zip file contains all updates as of November 2017 (subsequent updates require a different version of QTGMC that you won't need for a long while, if ever). Most of the support files are popular standalone filters in their own right. The .zip also has links to required Microsoft VisualC++ runtimes if you don't have them. There are quick read-me files in the zip, as well as all of the original documentation that comes with the support files. READ the READ-ME's first! Ignore them at your peril. The3 complete QTGMC .zip package and all its subfolders is at:
http://www.digitalfaq.com/forum/atta...g-qtgmc_newzip
MDG2()
BiFrost(interlaced=false)
MergeChroma(aWarpSharp2(depth=20).aWarpSharp2(dept h=10))
AddGrainC(1.25,1.25)
MDG2.avs is a packaged version of the MDegrain2 function that comes with MVTools2.dll. It's a degrainer that also helps to smooth buzzy edges. It requires MVTools2, which comes with QTGMC. it also requires aWarpSharp.dll (see remarks, 2 paragraphs below).
Bifrost is another color and stain cleaner. You have to tell it whether or not your video is interlaced. At this point in the script, your video isn't interlaced. You can get Bifrost_v2.zip at
http://www.digitalfaq.com/forum/atta...-bifrost_v2zip.
MergeChroma(aWarpSharp2(depth=20).aWarpSharp2(dept h=10)) combines the results of chroma-only sharpening with luma from previous statements. In short, this tells aWarpSharp2 to sharpen only the color channels, not the luma channel, because luma is already oversharpened. This tends to "tighten" colors closer around the edges they belong to. It won't clean up the chroma smearing mess entirely, but it helps. Get aWarpSharp2_2015.zip at
http://www.digitalfaq.com/forum/atta...sharp2_2015zip. It also requires the Microsoft VisualC++ runtime 2013 (which you will need for some other filters later), and you can get it at
http://www.microsoft.com/en-us/downl....aspx?id=40784.
MergeChroma:
http://avisynth.nl/index.php/Merge
AddGrainC is an old standby used by dozens of more complex filters. It adds a small amount of very fine film-like grain to mask hard macroblock edges and to avoid an over-filtered or posterized look. AddGrainC.dll and the 2012 VisualC++ runtime installs with the QTGMC package. Or get AddGrainC and the 2012 runtime separately at
http://avisynth.nl/index.php/AddGrainC.
Crop(4,0,0,-12).AddBorders(2,6,2,6)
These two commands remove unwanted border pixels and replace them with new black ones.
Crop() removes edge pixels in this order: 4 left border pixels, zero top border pixels, zero right border pixels, and 12 bottom border pixels. The bottom pixels are head-switching noise. Cropping might seem simple, but there are very stringent rules. You can see the rules in a small grid near the bottom of Crop's wiki page, linked below. Next,
AddBorders() gives you brand-new black border pixels in the same order processing order but it attempts to center the original image in the frame: add 2 left border pixels, 6 top border pixels, 2 right border pixels, and 6 bottom border pixels. The default border color is black but you can choose many other colors.
Crop():
http://avisynth.nl/index.php/Crop
AddBorders():
http://avisynth.nl/index.php/AddBorders
ConvertToRGB32(matrix="Rec601",interlaced=false) is another colorspace conversion, this time for use by the
VirtualDub filters that will be applied to the script's output. As usual, you must tell conversion functions whether or not your video is interlaced (at this point, it isn't) -- not making this clear can screw up your colors. The color matrix used for standard definition video is "Rec601", which is a flavor of RGB that VirtualDub will use. VirtualDub filters run in RGB color. if you don't make the conversion here, VirtualDub will do it when you load its filters. But Avisynth can usually do it more cleanly.
Without this conversion, your output at the end of this script is YV12 color. If you want to save the script as YV12 at this point, you'll need a lossless compressor other than
huffyuv, which can't compress YV12. I suggest Lagarith, since it's mainstreamn, recognized by media players and editors, and makes slightly smaller files than
huffyuv. Here's Lagarith's link again:
https://lags.leetcode.net/codec.html.
Using the Virtualdub filters:
The Avisynth script makes some initial levels and color corrections in YUV color. These were basic adjustments that are easier in the original colorspace, and are often not possible after conversion to other color systems. This particular video sample required work in the saturation department that would have been difficult in other software. Fortunately most videos don't require a bunch of Tweak statements as tricky as those used in the script.
After the basic corrections in YUV, color controls in VirtualDub can tweak the results and target certain areas more specifically. Shadows in bright objects still looked a little blue-green (those would be the midtone range centered at about RGB 128 in the middle of the spectrum). Flesh tones weren't quite right (rather orange-y, often grayed out, and very badly smeared), so adding a little warmth with Colormill and reducing cyan with gradation curves helped somewhat.
The image below shows the Red, Green, and Blue adjustment panes in the Gradation Curve plugin, as used in processing the sample clip.
Red is at the far left. The diagonal line for Red is curved upward, which increases the brightness of reds from the darkest values (at the bottom) to the brightest vales (at the top). There's a kink in the curve near the top of Red's vertical line intended to calm a slight red peak in the brighter reds. In the Green and Blue panes, both colors are lowered slightly across most of the range, but Green are lowered a little more at the high end to correct whites that were too green, and both Green and Blue vertical lines are raised somewhat in the darks (at the bottom) to correct darker colors that were too red. The curves plugin is similar to curves in Adobe Photoshop, Premiere Pro, and other high-end apps. Its .zip package comes with documentation.
The adjustments needed to correct whites, grays, and other areas of the spectrum were determined by using the
Csamp pixel reader to analyze pixels that were supposed to be whites, grays, or blacks. the RGB values shown by Csamp would indicate why those pixel colors were "off'. If a supposedly white pixel measured R185 G210 B213, it would indicate that those pixels didn't look white because there was too much green and blue and not enough red. So the bright colors would be manipulated to make Red, Green and Blue have similar values such as R200, G200 B200. Those values would equal white with about the same brightness as before.
The filters and settings ultimately used were saved in the .vcf file attached to the preceding post.
Speeding up Avisynth scripts for testing VirtualDub filters:
If you're running a script in VirtualDub and adding VDub filters at the same time, a slow Avisynth script can make scrolling thru the video very difficult while trying to adjust filters. Plugins like QTGMC can be very slow at certan settings and with very noisy video. You can temporarily make the script run faster if you comment-out some statements to prevent their execution. For example you can use Avisynth's comment in this statement:
Code:
QTGMC(preset="medium",FPSdivisor=2,ChromaMotion=true,border=true,\
ChromaNoise=true,GrainRestore=0.3,sharpness=0.7)
and change it into this statement, which prevents QTGMC fromn running:
Code:
# QTGMC(preset="medium",FPSdivisor=2,ChromaMotion=true,border=true,\
# ChromaNoise=true,GrainRestore=0.3,sharpness=0.7)
Any text that follows the cross-hatch or pound character (#) is converted to a comment, which is ignored by Avisynth. After making this change, in VirtualDub hit the F2 key (or click "File..." -> "Reopen video file") to reload the script at the point where you stopped scrolling. And don't forget to remove the comment marks when you're ready to save the file!
All I can add at this point is that I hope your other videos are in much better shape. If you wish you can submit a better sample from a workout tape to see how much better things can look.