meguIV: The Official Akiba-Online DVD Encoder (v1.0.1.1)

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
The differences may be subtle to the untrained eye, that's for sure. I'm cursed with picky eyeballs, though. meguIV is a purely selfish endeavor on my part to get other people to encode videos the way I prefer, thus saving me the hassle and time of downloading DVDISOs.
:joker:

If you want to make a fair comparison between v0.05 and 1.0.1.1, you have to adjust the v0.05 CRF upwards to match the new smaller filesizes.
 

xater

Bibitur Semper
Jun 5, 2007
3,145
361
:hi:
I been a bit busy to test it with old files, so I got sofbert's latest Erika Yazawa video... I got about 35-40 percent faster speed during the avi creation... for a 1 hour video it turned out to be 1.15 GB. Dunno how that would compare as I had never enconded it before.

The thing is that I like to include the extra stuff so I would normally do an avs file with all that and run it instead of using the oneclick option, but when doing this, I got errors during encoding-dunno what it was as it just stopped and the log window just said error. So I used the oneclick option with the main movie and then with the extra movie and it worked, I joined 'em all at the end with mkvtools. I dunno if the quality got better since I'd need to watch it while sober... and that ain't happening... anytime soon... :joker:

Now I'll see how it goes with Rui Kiriyama's latest video... although it has even more extras...:tea:
 

no__One

Active Member
May 27, 2007
947
175
I've coded my own Avisynth script (use show/hide below) that you can add to a MeGUI/MeguIV profile to reduce the edge artifacts generated from TGMC. Probaby belongs on Doom9, but I don't live there.

This rip of Reina Yamada uses it - there are other encodes and an ISO to compare to. Quality / sharpness is good, edges are cleaner, and even at 60fps it's not much larger than a 30fps MeguIV rip. Edge cleaning has reduced noise, reducing filesize and allowing me to increase TGMC resharpening to 1.35 (from the 221 default of 0.75). I'm using TGMC beta 2 with the default 2,2,1 settings, which also reduces filesize and mo-co errors. The encoding is CRF 20.7 ("slower" preset), again helping with filesize. I've compared over and over, and I can't justify much higher bitrate x264 encoding given the file bloat - sure it changes the "grain", but tangible improvements seem rare and quite marginal. I've optimized the code, but the downside of edge cleaning = 15-30% increase in encoding time. Only for those with time / processor power to spare.

MeGUI / MeguIV Script
[HIDE]
You can add the EdgeClean line to any MeGUI/MeguIV script just after <crop>
Code:
SetMTMode(5)
<input>
SetMTMode(2)
TempGaussMC_beta2(2, 2, 1, EdiMode="NNEDI2", sharpness=1.35)
<crop>
EdgeClean()
<resize>
Distributor()
[/HIDE]
Edge cleaning script and usage details:
[HIDE]Go to your Avisynth plugins folder - if you're using MeguIV, find the executable and from there the plugin folder is:
Code:
 Sandbox\Megu IV (MeGUI Mod)\0.05\Virtual\MODIFIED\@SYSDRIVE@\MeguIV\Avisynth 2.5\plugins
Create the last couple of folders if this full path doesn't exist. You need to save the code below as "EdgeClean1.0.avsi" and put it together with the TUnsharp plugin (TUnsharp.dll) into the plugins folder. The script also uses RemoveGrain and MaskTools V2, but you will already have these since TGMC uses them too. The edge cleaning script has a range of adjustable parameters, documented in the source code. However, the default settings have been quite robust so far.
Code:
#----------------------------------------------------------------#
#                                                                #
#              EdgeClean v1.0, by Vitreous, 2010                 #
#                                                                #
# Avisynth script to clean up halos, ringing and noise at edges  #
# Written to clean up after TempGaussMC, but doesn't require it  #
#                                                                #
# Notes:                                                         #
#    - May blur fine detail near edges; measures edge density    #
#      and will reduce cleaning in complex areas for this reason #
#    - Will not remove thick rings/halos                         #
#                                                                #
#----------------------------------------------------------------#

# Requires:
# 	MaskTools V2
#	RemoveGrain
#	TUnsharp

# Strength   (0-255) : Overall strength of cleaning effect
# Radius     (1-...) : Radius outside edge within which to reduce noise / halos / ghosts
# Resharpen  (0-512) : Used for strength parameter to TUnsharp - how much to resharpen cleaned areas
# DensityThr (0-511) : Amount of cleaning reduction in areas of high edge density
# DensityDS  (1-...) : Downsampling factor for edge density calculation
# EdgeLoThr  (0-255) : Low edge detection threshold for detecting larger set of edges used in hysteresis
# EdgeHiThr  (0-255) : High edge detection threshold for detecting smaller set of edges used in hysteresis
# Chroma     (bool)  : Whether to process chroma as well as luma
# ViewMask   (0,1,2) : Debugging: 1 = Show cleaning mask, 2 = Show edge density mask (set Strength=255 for mode 2)


function EdgeClean( clip Input, int "Strength", int "Radius", int "Resharpen", int "DensityThr", int "DensityDS", \
                    int "EdgeLoThr", int "EdgeHiThr", bool "Chroma", int "ViewMask" )
{
	Strength   = default( Strength,   255  )
	Radius     = default( Radius,     3    )
	Resharpen  = default( Resharpen,  200  )
	DensityThr = default( DensityThr, 448  )
	DensityDS  = default( DensityDS,  22   )
	EdgeLoThr  = default( EdgeLoThr,  120  )
	EdgeHiThr  = default( EdgeHiThr,  240  )
	Chroma     = default( Chroma,     true )
	ViewMask   = default( ViewMask,   0    )

	w = Input.width()
	h = Input.height()
	wd = m4( w / DensityDS )
	hd = m4( h / DensityDS )
	Black = BlankClip(Input)
	OuputChroma = (ViewMask == 0) ? (Chroma?3:2) : -128

	# Create edge masks (one binary, one with gradient)
	Prewitt = Input.mt_edge( "prewitt", 0,255, 0,255 )
	Edge = mt_hysteresis( Prewitt.mt_binarize(EdgeHiThr), Prewitt.mt_binarize(EdgeLoThr))
	EdgeGrad = mt_merge( Black, Prewitt, Edge, U=1,V=1 ).Levels( EdgeLoThr,1,255 ,0,255, false )

	# Create cleaning mask around edges - subtract edge from expanded edge with some blurring
	EdgeInner = Edge.mt_inflate().RemoveGrain( 20, -1 )
	EdgeOuter = EdgeGrad.mt_expand( mode=mt_square(Radius) ).RemoveGrain( 20, -1 ).RemoveGrain( 20, -1 )
	EdgeClean = mt_merge( EdgeOuter, Black, EdgeInner, U=1,V=1 )

	# Weaken mask in areas of high edge density
	DLo = (DensityThr >= 256) ? DensityThr - 256 : 0
	DHi = (DensityThr < 256) ? DensityThr : 255
	EdgeDensity = EdgeGrad.BicubicResize( wd,hd ).LanczosResize( w,h ).mt_invert().Levels( DLo,1,DHi, 0,Strength, false )
	Mask = (ViewMask == 2) ? EdgeDensity.mt_invert( U=0,V=0 ) : mt_merge( Black, EdgeClean, EdgeDensity, U=0,V=0 )

	# Clean / resharpen input within mask
	Clean = Input.RemoveGrain( 19, Chroma?19:0 ).TUnsharp( Resharpen, type=2 )
	Output = mt_merge( Input, (ViewMask != 0) ? Mask : Clean, Mask, luma=true )

	return Output
}

function m4( float x ) { return (x < 16 ? 16 : x - (x % 4)) }
[/HIDE]

Is your avisynth script already in meguIV (v1.0.1.1) or Have I manualy to add it ?

Thanks for your time and answer.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
Is your avisynth script already in meguIV (v1.0.1.1) or Have I manualy to add it ?
No, that script is not part of MeguIV - which is Rollyco's baby. I provided it for interest more than anything - the idea of using additional post-processing to clean up remaining artefacts after TGMC. The instructions you need to add it are in the show/hide blocks in the original post (just updated). You must be comfortable with manipulating the Avisynth scripts in MeguIV and adding plugins to the MeguIV sandbox. If you're not then I strongly suggest you just do straight MeguIV rips. They are quicker and already very high quality. If you want the single best tweak - make a 60fps rip following the instructions in this post. Will take twice as long to encode though...

For the record, I'm using an updated version of my script now. I've updated the original post.
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
The settings in meguIV 1.0.1.1 are not that suitable for additional edge cleaning. I would remove the 'sharpness' parameter from the call to TGMC() before you add denoising to the equation.

By the way, TGMC() has some pretty decent dehalo'ing already, it's the 'pel2hr' parameter. 6% slow-down in encoding time, which is why it's not enabled in meguIV.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
The pel2hr setting is buggy (look how cy3 is initialised) unless its been updated recently. Fixed and tried it anyway - it has little effect as far as I can see. Tried Dehalo_alpha on its own - too strong. FFT3DFilter's dehalo similar. That was when I decided to code my own. Still not satisfied with my code yet either, working on detecting false halos.

Actually I was puzzled about your sharpness setting - when I last looked, you had reduced sharpness to 0.4 from the default sharpness (which is 1.16 for 2,1,1 settings - wow, the TGMC code is quite a mess now - means my 1.35 is actually low!)
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
By Jove you're right, pel2hr is bugged.

Not sure where you got 1.16 from, the default sharpness for TGMCb2(2,1,1) is 0.25+(1+1)/6 = 0.58. I found 0.40 keeps enough detail when compensated with psy-rd and lowers the filesizes substantially.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
You've missed the second line that refines the parameters:
sharpness = default(sharpness, (SLmode==1||SLmode==3) ? sharp0 : 2*sharp0 )​
Where sharp0 is the 0.58 already calculated, and SLmode is whether to limit resharpening with a spatial or temporal comparison - default being 2 (temporal). I missed it too for a while - that's what I meant about TGMC's messy code, it's been accreted rather than developed. Especially bad is the comment that suggests the normal sharpness range is 0.0 to 1.0

So I'm not surprised 0.4 reduces filesizes. TGMC slightly temporally Gaussian blurs the image to help with motion analysis of the interpolated frames, then resharpens back to the original. You've effectively softened the image by resharpening so little. psy-rdo works by comparing the complexity of uncompressed and compressed images and adjusts compression accordingly. In your case the uncompressed image is already softened - psy-rdo will only try to restore to the complexity level of softened frame. TGMC can perform better resharpening with the original source and temporal information.

All that is irrelevant if you like the slightly softened look. In fact deinterlacing developers bemoan the fact that good deinterlacing inevitably causes softening.

My approach has been to allow TGMC to do it's resharpening thing, then fix the artefacts. I know that sounds wrong - surely I should just sharpen less. However:
- Sharpening is not being used to artificially enhance the image, it's being used to restore the original. Any reduction in sharpness setting will soften everything. My post-process tries very hard not to soften (only high contrast edges affected, high complexity areas affected less), although it still needs work in this area.
- It would be better to incorporate better edge-cleaning into TGMC itself. I started with that, but TGMC is a mess (if you think that sharpness parameter is confused - see if you can work out the meaning of, and valid ranges for rep0-2 - no wonder they're not documented)
- I am now also trying to repair sharpening artefacts in the source. These often occur in high contrast scenes in idol videos. Shots of distant objects are particularly badly affected. Changing TGMC settings can't really help here.​
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
Well, as far as what value is passed to the TGMC() function call you match the defaults by passing 0.58, not 1.16.

In my estimation 0.58 is a little too sharp for poor quality DV footage. 0.40 'takes the edge off', and that's good enough for me since processing speed is also a major concern.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
Well, as far as what value is passed to the TGMC() function call you match the defaults by passing 0.58, not 1.16.

I thought that at first - it is incorrect.

There are two lines in the script, separated, but with no other relevant lines in between:
Code:
sharp0    = default( sharpness, 0.25+(tr1+tr2)/6.) # strength of sharpening, 0.0 to 1.0, or more if you like
sharpness = default(sharpness, (SLmode==1||SLmode==3) ? sharp0 : 2*sharp0 ) # temporal limiting can afford more than spatial limiting

The variable sharp0 certainly gets the value 0.58 as you showed earlier. But sharp0 is only ever used in that second line - it is not used for the actual sharpening. The second line creates the actually used sharpness - if you've provided a value (as you have with 0.4), then it uses that. Otherwise it uses sharp0 for SLmode 1 or 3, and 2*sharp0 for other SLmode values. SLmode defaults to 2. So the value used for sharpness in the main body of the code is 2*0.58=1.16 in the absence of a specific value.

You can confirm all this by adding this line to TGMC by the comment "Let's start doing something", then view the avs with and without setting sharpness to 0.4:
clp = clp.Subtitle(string (sharpness))​
...Or make two tiny rips with these two lines - the output will be binary identical:
TempGaussMC_beta2( 2,1,1, EdiMode="nnedi2", Sbb=0, SVthin=0.0 )
TempGaussMC_beta2( 2,1,1, EdiMode="nnedi2", sharpness=2*(0.25+(2.0/6.0)), Sbb=0, SVthin=0.0 )​

Point taken about DV footage though. By selecting 0.4 you're retaining more of TGMCs blur to 'take the edge off', which makes sense.
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
Yeah you're absolutely right. In any case, 0.40 was arrived at through visual comparisons so I don't need to release a new version.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
Yeah you're absolutely right. In any case, 0.40 was arrived at through visual comparisons so I don't need to release a new version.

Oh no, I wasn't suggesting you should change anything. :donotwant:
I use MeguIV rips as a visual benchmark when I update my scripts - it's good to have a different refined approach to compare against. It's all pretty subjective at this level of detail (without going into PSNR or SSIM measures or whatever).
 

no__One

Active Member
May 27, 2007
947
175
Hi All,

I have "played" a little with MeguIV and I'm stuck :puzzled:

My DVD source vid has AC3 5.1 audio, maybe that's the problem, but in the audio config box "Downmix to stereo..." is selected (by default).

I always get "Bad/wrong number channels..."

Then what's wrong? I have tried AAC or MP3 combination / Bit rates and so... :exhausted:

If you please could help... :please: I really want to progress :study:
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
1) Close and re-open meguIV.
2) Do whatever you have to do to get that Bad/wrong number channels" error.
3) Go to the "Log" tab of the main window, right-click on the uppermost entry, and select "Save > Log".
4) Attach the log to a new post or paste it to http://pastebin.com.
 

no__One

Active Member
May 27, 2007
947
175
Thanks a lot for your fast answer :hi:

The error is: "Unsupported number of channels: 3"

I have added .txt to the log file else, couldn't upload it.

Thanks a lot for your time and help. :please:
 

Rollyco

Team Tomoe
Oct 4, 2007
3,556
34
I don't have a 3-channel AC3 stream I can test. Can you upload "VTS 01 1 T80 3_0ch 448Kbps DELAY 0ms.ac3" to Hotfile.com or other filesharing website?

meguIV certainly works with 5.1 channel streams, though.
 

no__One

Active Member
May 27, 2007
947
175
Thanks a lot.

Then we could only wait and see for a fix. :tea: