View Full Version : Automatic/Generic addBorder function ?
squadjot
16th November 2010, 23:25
Hi, my mediaserver supports AVI synth at transcoding.. i want the script to add black borders if necesary (i want to end up with 16:9)
Does such thing exist?
Motenai Yoda
17th November 2010, 02:13
there is an AddBorders(clip, int left, int top, int right, int bottom, int "color") function, color is default black :) so u must only check the video's aspect ratio and use the right parameters.
eg
e=last
oldWidth=e.width.float
oldHeight=e.height.float
tooNarrow=Round((((oldHeight/9.0)*16.0)-oldWidth)/2.0)
tooWide=Round((((oldWidth/16.0)*9.0)-oldHeight)/2.0)
(oldWidth/oldHeight<=16.0/9.0)? AddBorders(e, tooNarrow, 0, tooNarrow, 0) : AddBorders(e, 0, tooWide, 0, tooWide)
but u should control the mod of res too, should be at least mod1/mod2 for yuy2, mod2 for yv12, mod4/mod2 for x264 and mod16 for xvid/other codecs...
squadjot
17th November 2010, 02:30
Hey thanks.. how would you do the last thing youre talking about?
This should just work for "everything" on my mediaserver.. =)
I tried it with ColorBars(), and seems to work.. but with my clip wich is 1280x536 it wont play :S
Video
ID : 2
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings, CABAC : Yes
Format settings, ReFrames : 5 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 2h 28mn
Bit rate : 4 821 Kbps
Width : 1 280 pixels
Height : 536 pixels
Display aspect ratio : 2.35:1
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.293
Stream size : 4.86 GiB (74%)
Writing library : x264 core 107 r1766 f9f0035
Encoding settings : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=umh / subme=7 / psy=1 / psy_rd=1.00:0.15 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-3 / threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=2pass / mbtree=1 / bitrate=4821 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:1.00
Language : English
squadjot
17th November 2010, 02:41
Sorry.. it works like a charm..
Still you were saying something about mod?.. i dont' know what you mean, but if you have some tweaks to optimize compability..please let me know =)
THANKS so far, now i'll try put it in my mediaserver/transcoder
Motenai Yoda
17th November 2010, 15:36
depends on what kind of codec u use to trascoding for, and if the source res has the right mod.
e=last
modX=4
modY=2
oldWidth=e.width.float
oldHeight=e.height.float
roundedWidth=oldWidth-(oldWidth%modX)
roundedHeight=oldHeight-(oldHeight%modY)
eResized=e.Spline36Resize(roundedWidth,roundedHeight)
tooNarrow=Round((((roundedHeight*(16.0/9.0))-roundedWidth)/(2.0*modX))*modX
tooWide=Round((((roundedWidth/(16.0/9.0))-roundedHeight)/(2.0*modY))*modY
(roundedWidth/roundedHeight<=16.0/9.0)? AddBorders(eResized, tooNarrow, 0, tooNarrow, 0) : AddBorders(eResized, 0, tooWide, 0, tooWide)
but if u know the native res of your tv, (eg 1024x768, 1280x720, 1366x768, 1920x1080 ecc)
e=last
oldWidth=e.width.float
oldHeight=e.height.float
oldAR=oldWidth/oldHeight
newWidth=1280
newHeight=720
eResized=(oldAR <= 16.0/9.0) ? Spline36Resize(2*floor(newHeight.float*oldAR/2.0),newHeight) : Spline36Resize(newWidth,2*floor(newWidth.float/(oldAR*2.0)))
tooNarrowLeft=floor((newWidth-eResized.width)/2.0)
tooNarrowRight=ceil((newWidth-eResized.width)/2.0)
tooWideTop=floor((newHeight-e.Resized.height)/2.0)
tooWideBottom=ceil((newHeight-e.Resized.height)/2.0)
AddBorders(eResized, tooNarrowLeft, tooWideTop, tooNarrowRight, tooWideBottom)
squadjot
21st November 2010, 18:11
Thank's alot.. i have been away for a couple of days, but i'll check this out now.
Thanks you so much for helping, much apreciated
squadjot
21st November 2010, 18:31
Ok i got it working like this..
I have to return "clip" for media server to accept it..
clip = DirectShowSource("<filename>")
e=clip
oldWidth=e.width.float
oldHeight=e.height.float
oldAR=oldWidth/oldHeight
newWidth=1280
newHeight=720
eResized=(oldAR <= 16.0/9.0) ? Spline36Resize(clip,2*floor(newHeight.float*oldAR/2.0),newHeight) : Spline36Resize(clip,newWidth,2*floor(newWidth.float/(oldAR*2.0)))
tooNarrowLeft=floor((newWidth-eResized.width)/2.0)
tooNarrowRight=ceil((newWidth-eResized.width)/2.0)
tooWideTop=floor((newHeight-eResized.height)/2.0)
tooWideBottom=ceil((newHeight-eResized.height)/2.0)
clip = AddBorders(eResized, tooNarrowLeft, tooWideTop, tooNarrowRight, tooWideBottom)
return clip.SSRC(48000)
Is the amended script correct?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.