Cropping Certain Areas

This forum is for questions and discussion of all the aspects of handling and cleaning up your footage with Avisynth.
-MajinLink-
Joined: Sun May 30, 2004 6:32 pm
Org Profile

Cropping Certain Areas

Post by -MajinLink- » Tue Jul 01, 2008 1:47 pm

Let's say I wanted to crop at frame 100 to 200. Can this be done? If so, how? :?

Thanks.

User avatar
EvaFan
Joined: Sun Mar 21, 2004 10:25 pm
Status: (*゚▽゚)o旦~ ー乾杯ー♪
Location: Somerset, KY
Org Profile

Post by EvaFan » Tue Jul 01, 2008 4:59 pm

Copied and pasted from:
http://avisynth.org/mediawiki/ApplyRange

ApplyRange is a special case of Animate where start_args = end_args, and present in v2.51. It can be used when you want to apply a certain filter on certain range of frames of a clip. Another difference with Animate is that args can't contain a clip. Starting from v2.53 it supports audio, and start_frame can be equal to end_frame (such that only one frame is processed).

Scroll down to the bottom and you see this:
ApplyRange(0,149,"Crop", 158,0,64,32)

Replace the first 0 with your start frame and 149 with your end frame. Then replace all the crop amounts with the amounts you desire.

KEEP IN MIND THAT IT SAYS YOU NEED V2.51 TO USE IT AND 2.53 OR HIGHER TO USE IT ON AUDIO.
"The people cannot be [...] always, well informed. The part which is wrong will be discontented, in proportion to [...] the facts they misconceive. If they remain quiet under such misconceptions, it is lethargy, the forerunner of death to public liberty. What country can preserve its liberties, if it's rulers are not warned [...] that this people preserve the spirit of resistance? The tree of liberty must be refreshed from time to time, with the blood of patriots and tyrants."-Thomas Jefferson

-MajinLink-
Joined: Sun May 30, 2004 6:32 pm
Org Profile

Post by -MajinLink- » Wed Jul 02, 2008 1:16 pm

Thanks, but I keep getting this VirtualDub error:

Avisynth open failure:
ApplyRange: Filtered and unfiltered video frame sizes must match


What's going on here? :?

User avatar
EvaFan
Joined: Sun Mar 21, 2004 10:25 pm
Status: (*゚▽゚)o旦~ ー乾杯ー♪
Location: Somerset, KY
Org Profile

Post by EvaFan » Wed Jul 02, 2008 5:01 pm

The portion that you cropped has a different size than the rest of the video after cropping.

I've never used an applyrange before to crop a portion of the video. I'm guessing putting a LancsozResize(width,height) at the end of your script would fix it all. If not your gonna have to do another apply range after your first one:

ApplyRange(startframe,endframe,"LancsozResize", width,height)

Replace the the start and endframe with your desired frames and replace width and height with the #'s for the size you desire everything to be.

One of those should give you an end resulting video where everything is the same size. Obviously the portion that you cropped will have been stretched to fit the rest of the video's size. There is another Option if you don't want to stretch it.

ApplyRange(startframe,endframe,"Addborders", left,top,right,bottom)

The left top right and bottom will be the same numbers you cropped. Basically the video wont be stretched in this case it will just have the part where you cropped filled with black video.

If any of this is confusing to you then you need to give me the amounts you want to crop from left,top,right,bottom and the frames you want to change so I can make you a script. The stuff above isn't that confusing tho >_>.
"The people cannot be [...] always, well informed. The part which is wrong will be discontented, in proportion to [...] the facts they misconceive. If they remain quiet under such misconceptions, it is lethargy, the forerunner of death to public liberty. What country can preserve its liberties, if it's rulers are not warned [...] that this people preserve the spirit of resistance? The tree of liberty must be refreshed from time to time, with the blood of patriots and tyrants."-Thomas Jefferson

User avatar
Jnzk
Artsy Bastid
Joined: Tue Jan 28, 2003 5:30 pm
Location: Finland
Org Profile

Post by Jnzk » Thu Jul 03, 2008 9:41 am

And if by "cropping" you meant trimming, Trim(100,200) should do the trick.

-MajinLink-
Joined: Sun May 30, 2004 6:32 pm
Org Profile

Post by -MajinLink- » Sun Jul 13, 2008 7:40 pm

Sorry for the delayed reply, Eva-Fan. Yeah, I just can't get this to work... Would you mind helping? :oops:

- Crop(4,2,-4,-0) for frames 1 to 32965.

- Crop an additional (2,0,-2,-0) off of frames 32966 to 33686.

I know I could just go Crop(6,2,-6,-0), but I really don't want to be croppin' off anymore from frames 1 to 32965. Frames 32966 to 33686 still show black bars that I would like to get rid of.

User avatar
EvaFan
Joined: Sun Mar 21, 2004 10:25 pm
Status: (*゚▽゚)o旦~ ー乾杯ー♪
Location: Somerset, KY
Org Profile

Post by EvaFan » Mon Jul 14, 2008 5:19 pm

-MajinLink- wrote:Sorry for the delayed reply, Eva-Fan. Yeah, I just can't get this to work... Would you mind helping? :oops:

- Crop(4,2,-4,-0) for frames 1 to 32965.

- Crop an additional (2,0,-2,-0) off of frames 32966 to 33686.

I know I could just go Crop(6,2,-6,-0), but I really don't want to be croppin' off anymore from frames 1 to 32965. Frames 32966 to 33686 still show black bars that I would like to get rid of.
From what I read you dont want black bars so we wont use addborders. Lanczosresize is a sharp resizer that preserves a pictures sharpness, However my personal favorite, BilinearResize. Sometimes lanczosresize can break edges when resizing. Bilinearresize can too but chances are it wont, it smoothes the image slightly as well.

I will assume the size of your video is 640x480 since you havent told me. If it isn't you need to replace the numbers with the size of the video before any cropping.

ApplyRange(0,32965,"Crop", 4,2,-4,-0)
ApplyRange(0,32965,"Bilinearresize", 640,480)
ApplyRange(32966,33686,"Crop", 2,0,-2,-0)
ApplyRange(32966,33686,"Bilinearresize", 640,480)

You could probably do it all with 1 applyrange and a hell of alot of complicated coding and commas... but i figured this would be easier for you to understand. Remember the 640x480 I'm putting in may not be what the size of your video is... I just assumed it's what it was since you never told me. Input the correct width,height if its not right.
"The people cannot be [...] always, well informed. The part which is wrong will be discontented, in proportion to [...] the facts they misconceive. If they remain quiet under such misconceptions, it is lethargy, the forerunner of death to public liberty. What country can preserve its liberties, if it's rulers are not warned [...] that this people preserve the spirit of resistance? The tree of liberty must be refreshed from time to time, with the blood of patriots and tyrants."-Thomas Jefferson

-MajinLink-
Joined: Sun May 30, 2004 6:32 pm
Org Profile

Post by -MajinLink- » Mon Jul 14, 2008 9:34 pm

-MajinLink- wrote:Thanks, but I keep getting this VirtualDub error:

Avisynth open failure:
ApplyRange: Filtered and unfiltered video frame sizes must match


What's going on here? :?
I'm still getting this error. And will ApplyRange only work with v2.51? :?

User avatar
EvaFan
Joined: Sun Mar 21, 2004 10:25 pm
Status: (*゚▽゚)o旦~ ー乾杯ー♪
Location: Somerset, KY
Org Profile

Post by EvaFan » Mon Jul 14, 2008 10:45 pm

-MajinLink- wrote:
-MajinLink- wrote:Thanks, but I keep getting this VirtualDub error:

Avisynth open failure:
ApplyRange: Filtered and unfiltered video frame sizes must match


What's going on here? :?
I'm still getting this error. And will ApplyRange only work with v2.51? :?
Yes it works with 2.51 and above. I just tried it for the first time on a script of mine and it looks like the first applyrange cannot be completed without ouputting the same frame size as the rest of the video. Basically the script is failing before it gets to the other applyrange's and it wont continue that way. I'll toy with it after work tomorrow to see If I can get you a solution. I'm actually very interested in learning if there is a solution myself now.
"The people cannot be [...] always, well informed. The part which is wrong will be discontented, in proportion to [...] the facts they misconceive. If they remain quiet under such misconceptions, it is lethargy, the forerunner of death to public liberty. What country can preserve its liberties, if it's rulers are not warned [...] that this people preserve the spirit of resistance? The tree of liberty must be refreshed from time to time, with the blood of patriots and tyrants."-Thomas Jefferson

User avatar
dokidoki
c0d3 m0nk3y
Joined: Tue Dec 19, 2000 7:42 pm
Status: BLEEP BLOOP!
Location: doki doki space
Contact:
Org Profile

Post by dokidoki » Mon Jul 14, 2008 11:51 pm

-MajinLink- wrote:Sorry for the delayed reply, Eva-Fan. Yeah, I just can't get this to work... Would you mind helping? :oops:
- Crop(4,2,-4,-0) for frames 1 to 32965.
- Crop an additional (2,0,-2,-0) off of frames 32966 to 33686.
I know I could just go Crop(6,2,-6,-0), but I really don't want to be croppin' off anymore from frames 1 to 32965. Frames 32966 to 33686 still show black bars that I would like to get rid of.
Note that the framecount starts at 0, but anyway...

a=[source]
b=a.Trim(1,32965).Crop(4,2,-4,-0).BilinearResize(640,480)
c=a.Trim(32966,33686).Crop(6,2,-6,-0).BilinearResize(640,480)
b+c
Image Image Image
"Comedy is a dying breed." -- kisanzi // "Comedy. Serious business." -- dokidoki

Locked

Return to “AviSynth Help”