PDA

View Full Version : resize border only


Kumo
13th February 2008, 02:38
i'm trying to encode a video to x264 via megui.the frame is 720x480 ,2/4 black pixels borders on left-right sides, and 4 on top side.to keep a mod16 encoding, i should overcrop to 704x464,loosing 8 horizontal pixels and 12 vertical pixels.i'd like to know if there's a way to resize just the borders,like last 12 top pixels to 16 and 4 sides pixels to 8 (or something like that).that way i'd leave most of the frame untouched without loosing any pixel,i think that stretched sides wouldn't be noticeable.

neuron2
13th February 2008, 03:10
Use Crop() to remove the existing borders, then add them back as needed with AddBorders().

Kumo
13th February 2008, 10:44
but in that way i'll have black borders around the frame.i'd like to get my encoded picture without any black border,mod16 and not overcropped.the only way i figured to reach that goal is to resize just a portion of the frame(close to black border) to have a mod16 res.if i have to crop 4 pixels,then i'd like to resize(stretching) the closest remaining 12 pixels to 16 pixels,so i restore the mod16 giving back that 4 pixels cropped.there's a way to do that?there are any alternatives without adding black borders?
p.s.:i'm really sorry for my bad english,if i wasn't clear please ask

G_M_C
13th February 2008, 12:39
but in that way i'll have black borders around the frame.i'd like to get my encoded picture without any black border,mod16 and not overcropped.the only way i figured to reach that goal is to resize just a portion of the frame(close to black border) to have a mod16 res.if i have to crop 4 pixels,then i'd like to resize(stretching) the closest remaining 12 pixels to 16 pixels,so i restore the mod16 giving back that 4 pixels cropped.there's a way to do that?there are any alternatives without adding black borders?
p.s.:i'm really sorry for my bad english,if i wasn't clear please ask


Use Crop() to remove the existing borders, then add them back as needed with AddBorders().

What Neuro2 says, only in stead of adding new borders resize ?

So: Crop 2/4 px left/right and 4 px above/under, and than resize back to 720x480 ?? It's only 2 script commando's.

Didée
13th February 2008, 13:08
For the specific case here (crop @ left/top/right, not at bottom):

o = last
ox = o.width()
oy = o.height()

crop_L = 2
area_L = 24

crop_T = 4
area_T = 32

crop_R = 4
area_R = 32

crop_B = 0
area_B = 0

stackvertical(
\ stackhorizontal(
\ o.spline16resize(area_L,area_T,crop_L, crop_T,area_L-crop_L,area_T-crop_T),
\ o.spline16resize(ox-area_L-area_R,area_T, area_L,crop_T,ox-area_L-area_R,area_T-crop_T),
\ o.spline16resize(area_R,area_T,ox-area_R,crop_T,area_R-crop_R,area_T-crop_T) ),
\ stackhorizontal(
\ o.spline16resize(area_L,oy-area_T-area_B, crop_L,area_T,area_L-crop_L,oy-area_T-area_B),
\ o.crop(area_L,area_T,-area_R,-area_B),
\ o.spline16resize(area_R,oy-area_T-area_B, ox-area_R,area_T,area_R-crop_R,oy-area_T-area_B) ) )


I ever wanted to make a custom function for this operation, but ... it's a bit boring to figure out all possible special cases and make it fail-safe, and so it never happened ...

Notes:
- The 'area_X' values specify the sizes of the border stripes that will be processed. Ideally, those values should be mod8.
- For each border stripe, the 'area' size must be set big enough, in respect to the cropping size. It's a matter of persoal opinion, but 'area_X' probably should be at least 10*crop_X, otherwise there's too much distortion.

Kumo
13th February 2008, 15:44
first of all thanks for being so fast.this script works perfectly by itself, but if i try to combine with others filters i'm using, i get weird borders(green on the right and missed up on others sides).i'll post my script just in case you want to check it
DGDecode_mpeg2source("E:\kor\VTS_01.d2v",info=3)
ColorMatrix(hints=true)
o = last
ox = o.width()
oy = o.height()

crop_L = 4
area_L = 32

crop_T = 4
area_T = 32

crop_R = 4
area_R = 32

crop_B = 0
area_B = 0

stackvertical(
\ stackhorizontal(
\ o.spline16resize(area_L,area_T,crop_L, crop_T,area_L-crop_L,area_T-crop_T),
\ o.spline16resize(ox-area_L-area_R,area_T, area_L,crop_T,ox-area_L-area_R,area_T-crop_T),
\ o.spline16resize(area_R,area_T,ox-area_R,crop_T,area_R-crop_R,area_T-crop_T) ),
\ stackhorizontal(
\ o.spline16resize(area_L,oy-area_T-area_B, crop_L,area_T,area_L-crop_L,oy-area_T-area_B),
\ o.crop(area_L,area_T,-area_R,-area_B),
\ o.spline16resize(area_R,oy-area_T-area_B, ox-area_R,area_T,area_R-crop_R,oy-area_T-area_B) ) )

source = last
backward_vec3 = source.MVAnalyse(isb = true, delta = 3, pel = 2, overlap=4, sharp=1, idx = 1)
backward_vec2 = source.MVAnalyse(isb = true, delta = 2, pel = 2, overlap=4, sharp=1, idx = 1)
backward_vec1 = source.MVAnalyse(isb = true, delta = 1, pel = 2, overlap=4, sharp=1, idx = 1)
forward_vec1 = source.MVAnalyse(isb = false, delta = 1, pel = 2, overlap=4, sharp=1, idx = 1)
forward_vec2 = source.MVAnalyse(isb = false, delta = 2, pel = 2, overlap=4, sharp=1, idx = 1)
forward_vec3 = source.MVAnalyse(isb = false, delta = 3, pel = 2, overlap=4, sharp=1, idx = 1)
source.MVDegrain3(backward_vec1,forward_vec1,backward_vec2,forward_vec2,backward_vec3,forward_vec3,thSAD=400,idx=1)
dfttest(sigma= 0.8)

LimitedSharpenFaster(ss_x=1.1, ss_y=1.1, smode=4, strength=150,undershoot=10,overshoot=10)
i'm pretty sure the issue is "source" in mvdegrain, but i don't know ho to fix it. should i put the resize sript before or after others filters?there's a way to split the ammount of pixels to be resized between top and bottom borders even if i don't crop anything on the bottom border(resize area 16 on top and bottom but i crop 4 pixels just on top)?

Didée
13th February 2008, 15:58
Hmmh... not quite sure, but it could be an issue with frame pitch. Poking in the blue, try the following:

Replace "source = last" with

"source = blankclip(last).merge(last,0.999)"

This often does the trick, perhaps here too?

Kumo
13th February 2008, 16:26
sorry,maybe it was just an AvsP issue,cause i restarted it and now the script works fine even in the first way.just 2 last question,than i'll stop bothering you :) . can i split on both top and bottom borders the 32 pixels i have to vertically resize if i don't crop anything on bottom(resize 16 top pixels and 16 bottom pixels)?in my limitedsharpenfaster settings, how would be a safe range for "undershoot" parameter(1-255)?

Didée
13th February 2008, 17:01
OK, now I've had a chance to actually try something.

The funny news is: I can't find a problem. Using your script (exactly like you posted it) gives me "perfect" output. No weird artefacts at all.

Seems something's going wrong on your side ...

Kumo
13th February 2008, 17:12
yes you're right,i edited my post too late.now everything is perfetct.
If you still have patience, i left u a couple of questions in my last edited post.i really appreciate your help,thank you so muh.

foxyshadis
14th February 2008, 08:39
You might check your versions of avisynth, masktools, & mvtools. Some versions didn't do pitch quite right, but those would be pretty old versions.

Don't mess with undershoot much, it'll cause dark halos. If you change the cropping, just change how much you resize (use more of the source, or make a smaller result) so that it still adds up to 720x480.