Log in

View Full Version : improve draft script 30-fps->25fps->PALDVD


hydra3333
2nd November 2009, 04:53
I have a 100Mb home video clip from a samsung s630 (a small stills camera that can also record video) and mediainfo tells me the clip is 30fps, 640x480, progressive mjpeg. Most of the clip is indoors with "moderate" lighting.

I'm looking to turn the clip into PAL DVD (ie the script is input to HC023) and so have cobbled together the draft script, with re-used code, below. Audio will be processed separately,

Can any suggest improvements (or replacement) to maximize quality ? Processing time is not an issue.

#loadplugin("C:\Program Files\Haali\MatroskaSplitter\avss.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-zzz\mt_masktools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-zzz\mvtools2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-zzz\Convolution3d.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-zzz\AGC.dll")

#dss2("c:\i\input.avi",fps=30) #DirectShowSource2
AVIsource("c:\i\input.avi",audio=false)
AssumeFPS(30)

global resizeWidth = 0
global resizeHeight = 0
global resizeBorderHalfHeight = 0
bh = zzzCalcResize(LAST, 720, 576)

super = last.MSuper(pel=2,sharp=2)
backward_vec = MAnalyse(super,isb=true,truemotion=true,delta=1,chroma=true,blksize=4,overlap=2)
forward_vec = MAnalyse(super,isb=false,truemotion=true,delta=1,chroma=true,blksize=4,overlap=2)
MFlowFps(super, backward_vec, forward_vec, num=25, den=1, ml=100)
AssumeFPS(25)

ConvertToYUY2(interlaced=FALSE)
Convolution3D(0, 6, 10, 6, 8, 2.8, 0)
# HDRAGC *can't* be used inside MT or AGC will be calculated differently in each slice
HDRAGC(coef_gain=0.1, min_gain=0.1, max_gain=0.5, coef_sat=1.0, corrector=0.8, reducer=2.0, black_clip=1.0)
lanczos4resize(resizeWidth,resizeHeight).LimitedSharpenFaster(smode=4,strength=100)
Addborders(0, resizeBorderHalfHeight, 0, resizeBorderHalfHeight)
Converttoyv12()

#-----------------------------------------------------------------------------------------------------------------------
# re-use old function to calculate resizing and border sizes
Function zzzCalcResize(clip c, int desiredWidth, int desiredHeight) {
global resizeWidth = 0
global resizeHeight = 0
global resizeBorderHalfHeight = 0
ratio=((c.width()+.0)/(c.height()+.0))+.0
ratio=(ratio<1.33333) ? 1.333333 : ratio

halfheight43=(round(c.width()/1.33333)-c.height())/2
#What would be the height keeping the aspect ratio if width was 640/320-NTSC or 768/384-PAL(4:3)
no_borders_height1=(c.height() < desiredHeight)? c.height() : desiredHeight
#4:3
no_borders_height1=(desiredHeight == 480) ? floor(640*(1/ratio)) : no_borders_height1
no_borders_height1=(desiredHeight == 240) ? floor(320*(1/ratio)) : no_borders_height1
no_borders_height1=(desiredHeight == 576) ? floor(768*(1/ratio)) : no_borders_height1
no_borders_height1=(desiredHeight == 288) ? floor(384*(1/ratio)) : no_borders_height1
#Now how much we have to shrink to make it fit inside a macroblock?
#mod16height=no_borders_height1 % 16
mod2height=no_borders_height1 % 2
#If the rest is <=8, subtracts the rest, else, completes to 16.
#completion= (mod16height <= 8) ? (-mod16height) : (16-mod16height)
#no_borders_height2=no_borders_height1+completion
no_borders_height2=no_borders_height1-mod2height
#finally Return resize parameters
global resizeWidth = desiredWidth
global resizeHeight = (c.width() == 704) && (desiredWidth == 704) ? c.height()-(c.height() % 2) : no_borders_height2
global resizeHeight = (c.width() == 720) && (desiredWidth == 720) ? c.height()-(c.height() % 2) : no_borders_height2
global resizeBorderHalfHeight = (desiredHeight-resizeHeight)/2
return resizeBorderHalfHeight
}
SetPlanarLegacyAlignment(True)

EDIT1: Hmm error "could not locate decompressor for MJPG" ... ?
EDIT2: ffdshow fixed that. Now "Error in MVFLOWFPS: mvbw's overlap size is incorrect" ?
EDIT3: typo mvanalyse -> manalyze

2Bdecided
2nd November 2009, 13:31
For PAL DVD, I'd strongly suggest going to 50fps and interlacing.

Also, depending on the content, you might find motion interpolation breaks down completely (giving horrible artefacts) and you'd be better off using the simple convertfps() or even changefps().

Simple (no motion interpolation):
directshowsource("edit.avi")

# Fix levels (codec issue on my machine, YMMV!)
levels(0,1.0,255,16,235,coring=false)

convertfps(50)

spline36resize(704,576)

assumetff()
separatefields()
selectevery(4,0,3)
weave()



Simple-ish (with motion interpolation):
directshowsource("edit.avi")

# Fix levels (codec issue on my machine, YMMV!)
levels(0,1.0,255,16,235,coring=false)

source=last

super = source.MSuper(pel=1, sharp=1)
backward_vec1 = MAnalyse(super, isb = true, delta = 1, overlap=0, search=3)
forward_vec1 = MAnalyse(super, isb = false, delta = 1, overlap=0, search=3)

source.MFlowFps(super, backward_vec1, blend=false, forward_vec1, num=50, den=1)

spline36resize(704,576)

assumetff()
separatefields()
selectevery(4,0,3)
weave()

Complicated (smarter resize, stabilise etc - also various things commented out that you can try if you want):
directshowsource("edit.avi")
assumeframebased()

# Fix levels (codec issue on my machine, YMMV!)
levels(0,1.0,255,16,235,coring=false)

nnedi(field=0,dh=true).turnleft().nnedi(field=0,dh=true).turnright()

vf=last.mvanalyse(idx=1,pel=1,isb=false,blksize=16, truemotion=true)
vb=last.mvanalyse(idx=1,pel=1,isb=true,blksize=16, truemotion=true)

xf=last.mvflow(idx=1,vf)
xb=last.mvflow(idx=1,vb)

interleave(xf,last,xb)
temporalsoften(1,20,20,mode=2)
selectevery(3,1)

spline36resize(960,720)

maxstab=60 #maximum values for the stabiliser (in pixels) 20 is a good start value

est_left=20 est_top=20 est_right=20 est_bottom=20 est_cont=0.8 #crop values for special Estimate clip

CLeft=16 CTop=16 CRight=16 CBottom=16 #crop values after Depan and before final resizing

stab_reference=last.tweak(cont=est_cont).levels(79,1.0,81,255,0,coring=false).greyscale().invert()

mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstab,dymax=maxstab)
stab=DePanStabilize(last,data=mdata,cutoff=0.5,dxmax=maxstab,dymax=maxstab,method=1,mirror=15)
#stab2= stab.crop(CLeft,CTop,-CRight,-CBottom)
#stab3=DePanStabilize(last,data=mdata,cutoff=0.5,dxmax=maxstab,dymax=maxstab,method=1,info=true)

source=stab

super = source.MSuper(pel=1, sharp=1)
#backward_vec3 = MAnalyse(super, isb = true, delta = 3, overlap=0)
#backward_vec2 = MAnalyse(super, isb = true, delta = 2, overlap=0)
backward_vec1 = MAnalyse(super, isb = true, delta = 1, overlap=0, search=3)
forward_vec1 = MAnalyse(super, isb = false, delta = 1, overlap=0, search=3)
#forward_vec2 = MAnalyse(super, isb = false, delta = 2, overlap=0)
#forward_vec3 = MAnalyse(super, isb = false, delta = 3, overlap=0)
#source.MDegrain2(super, backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=400)
#source.MDegrain3(super, backward_vec1,forward_vec1,backward_vec2,forward_vec2,backward_vec3,forward_vec3,thSAD=400)

#backward_vec = MAnalyse(super, blksize=8, overlap=0, isb = true, search=3)
#forward_vec = MAnalyse(super, blksize=8, overlap=0, isb = false, search=3)
source.MFlowFps(super, backward_vec1, blend=false, forward_vec1, num=50, den=1)

#spline36resize(640,524)
#addborders(32,26,32,26)

spline36resize(704,576)

#grainfactory3(g1str=5, g2str=5, g3str=5)
##addgrainc(0,2)

#limitedsharpenfaster(strength=50)

assumetff()
separatefields()
selectevery(4,0,3)
weave()

(stabiliser code adapted from VideoFred - you might prefer to uncomment and subsequently use stab2)

Hope this helps.

Cheers,
David.

thewebchat
2nd November 2009, 21:39
Solution: Don't master to "25fps" which involves decimation, blending, PAL, and other useless garbage which makes it impossible to "maximize quality." Instead, go out and purchase an NTSC television, which can usually be acquired for less than 100 euro.

hydra3333
3rd November 2009, 11:13
Oh joy, some magic there 2Bdecided ! Thanks.

thewebchat, NTSC tv ? I guess you mean ntsc capable dvd too. Hmm, 30fps is what is reported by mediainfo so if I assumefps(29.97) and resize to 704x480 4:3 etc then won't the audio progressively go more out of sync ? I use ffmpeg to convert audio from the AVI into AC3 or MP2, and then separately mux then author/burn.

2Bdecided
3rd November 2009, 14:05
You can easily do "proper" NTSC. From memory, it's something like...

avisource("blah.avi")
spline36resize(704,480)
assumefps(30000, 1001,sync_audio=true)
#ssrc(48000)
ResampleAudio(48000)

SSRC supposedly gets upset by some resampling ratios, but is higher quality. ResampleAudio is probably more than good enough.


Probably no need to "purchase an NTSC television" - most "PAL" TVs will display NTSC DVDs just fine - use an RGB SCART lead if you're in Europe - otherwise composite can require some messing around to get a compatible colour format. Note that your DVD player has to be set to NTSC or Multi/Auto; setting it to PAL will just cause the DVD player itself to perform an NTSC>PAL conversion - probably worse than AVIsynth.


I convert to "PAL" when I need to mix footage from various sources into a single compilation. My digital still camera shoots 30fps or 60fps, while my camcorder is "PAL" (50i). Also some relatives have TVs which will not display NTSC - best to stick with PAL for maximum compatibility.

The worst thing about the converted NTSC>PAL is that the convertfps() version looks awful on a PC with all that frame blending - far worse than on a TV. The mflowfps version is at least consistent - it either has artefacts, or it doesn't (if you're lucky!) - whatever you watch it on.

Hope this helps.

Cheers,
David.

hydra3333
4th November 2009, 10:08
Thanks yes it does. I use HCenc to poke the avs into ... what do you use to receive and process the audio .avs ? ffmpeg ? btw, aus so hdmi connection dvdplayer<->tv.

2Bdecided
4th November 2009, 11:32
Not sure what the most convenient way to do it is, as I still use an old (legal!) version of TMPGenc for audio (and muxing, when needed). Not a recommendation. Recent-ish toolame based stuff is probably better.

I often need to source the audio from an .avs file (e.g. when I've trimmed, resampled, or re-timed) and process it further - so I just drop it into VirtualDub, save a .wav file, and process that using an audio editor.

Cheers,
David.

hydra3333
4th November 2009, 12:47
OK, the venerable vdub it is then.