PDA

View Full Version : New filter: AutoCrop


CropsyX
3rd November 2002, 06:15
AutoCrop is a simple AVISynth Filter that automatically crops the black borders from a
clip. It operates in either preview mode where it overlays the recommended cropping
information on the existing clip, or cropping mode where it really crops the clip. It can
also ensure width and height are multiples of specified numbers so the cropped clip can be
passed to the video compressor of your choice without problems.

This is the first release of this filter and also my first AviSynth filter, so there may
be some problems. Feedback about problems and suggestions for improvements are welcome.

It has occurred to me that this filter maybe to simplistic for AviSynth users who are
generally a pretty savvy lot but I've decided to release it anyway. Someone might find it
useful and I'd like to contribute something back to the AviSynth community whose tools I
use regularly.

http://www.videofringe.com/autocrop/autocrop.zip

FLeXO
3rd November 2002, 11:46
Wow,, this filter seems to work just fine here.. it saves alot of time.. :D thanx.

JohnMK
3rd November 2002, 12:47
How does aspect ratio factor into this? Typically I crop to preserve aspect ratio too.

Rrrough
3rd November 2002, 12:57
...and for future YV12-versions you should make it MOD 4-aware ;)
keep up the good work.

cheers

CropsyX
3rd November 2002, 14:38
Originally posted by JohnMK
How does aspect ratio factor into this? Typically I crop to preserve aspect ratio too.
At the moment it doesn't. I'm still trying to decide wether it would be better to throw away extra used lines to maintain the aspect ratio or include some blank lines. I don't usually crop to maintain aspect ratio so I'm open to suggestions.

Rrrough

I'll definitely need to do some research into YV12 in the not too distant future. At the moment I know as much about YV12 as did YUY2 a week ago ie. Nothing :)

I'd like to lock down the feature set of AutoCrop first though if possible.

Rrrough
3rd November 2002, 15:02
no need to rush. I think it's a good idea of making it MOD 4-aware anyway and it might assure you compatibility with future versions.
it's definetly a great filter-idea !

cheers

CropsyX
5th November 2002, 07:21
I've released version 0.3 which fixes the following problems.

Setting wMultOf=width now behaves correctly. ie. Just letterboxes the clip.

Debugging information no longer written to disk.

Thanks to Nesti for pointing out these problems.

It's available from

http://www.videofringe.com/autocrop/autocrop.zip

ldivx
11th November 2002, 19:11
Great work.
But when i use your autocrop
how can i resize in keep "aspect ratio" without know the autocrop value ???.

Can you put variable for know the crop value for make a good resize.


Sorry for the mistakes. i'm just a french.

In french :
Beau travail, mais comment peut t'on savoir quels sont les valeurs de l'auto-crop pour pouvoir redimmensionner le fichier vidéo en gardant l'aspect ratio. serait il possible d'implementer des variables pour faire un bon crop.

Exemples :

AutoCrop(preview=true,hMultOf=4,wMultOf=width)
# Resize
LanczosResize(AutoCropvalue)

If you have have beta version i can test it.
byebye.

CropsyX
13th November 2002, 08:48
ldivx

If you run AutoCrop with preview=false, then AviSynth will update it's built in width and height variables appropriately. Then you can use a function like the one below to set the new width and have the height calculated to main aspect ratio.

Sample Usage:

ResizeMaintainAspectWidth(384,"BiCubicResize")

That will call BiCubicResize with the width set to 384 and the height set to maintain aspect ratio.

function ResizeMaintainAspectWidth(clip c,int newwidth,string resizefn) {
nh=floor(eval(string(c.height)+". * "+string(newwidth)+". / "+string(c.width)+"."))
return eval(resizefn+"(c,"+string(newwidth)+","+string(nh)+")")
}

OUTPinged_
14th November 2002, 16:05
Cropsyx, how would it deal with a movie that has several "widescreen" scenes while the movie itself is 3:4?

Also, if a movie has a "space scene" with very very low luma values in the first minute of a movie?

A suggestion:

Maybe add "frame range" using which it would detect cropping values and then use them throughout the movie...

Also, when it finished detection it is supposed to act like a regular crop. There are Crop() sources. Maybe use that so it would be a bit faster solution.

CropsyX
14th November 2002, 16:12
OUTPinged_

The way the filter works is to sample frames evenly spaced throughout the movie. It then uses the least aggressive crop settings it finds from the frames sampled. This should in theory handle both your possible problem areas. If there is any evidence that it doesn't I'll look into possible alternatives.

With regards to speeding up the cropping I need to have a look at the how avisynth does it's cropping. That and aspect ratio's are the two main things I want to finish before a 1.0 release.

OUTPinged_
14th November 2002, 16:57
Can you still implement "manual" crop sample selection? It's not that complex and will be helpfull in "hard" cases(ie dark short clips).

It worked ok on my 2 test files but i am still afraid to use it blindly :-) The reason is, it is one more step for a fully automated and full proof encoding and i really want it to work best, it's a great idea.

OUTPinged_
14th November 2002, 16:59
Erm... more on that:

Can it calculate average brightness for a frame and, if all frames have av. brightness lower than threshold, increase "samples" value and recalc?

CropsyX
14th November 2002, 17:47
Can you still implement "manual" crop sample selection? It's not that complex and will be helpfull in "hard" cases(ie dark short clips).
I could, I'm not sure I see the point though :) By the time you have to manually specify a range of frames to sample it wouldn't be much more difficult to set the cropping information manually. If there's further demand for the feature I'll add it but I'm wary of adding to many parameters to AutoCrop (I'm up to 9 already).

Can it calculate average brightness for a frame and, if all frames have av. brightness lower than threshold, increase "samples" value and recalc?
Unless you specify a really high threshold it's unlikely that from 10 frames none of them will have a enough lines to achieve a crop.

I'm sure there will be problems with the way autocrop deals with various sources but until there are concrete examples I think it will be better to add needed features than try to avoid problems no one has encountered.

It worked ok on my 2 test files but i am still afraid to use it blindly :-)
Good choice, I'd always advise looking at the output of AutoCrop before committing to an encode. Realistically if AutoCrop fails it's not the end of the world. It just adds a couple of minutes to the setup time for an encode.

OUTPinged_
14th November 2002, 20:44
Well if you would be able to make it's speed comparable to Crop(), i guess everyone here will use it :-)

Dont know about you guys, but i'm sick inputting crop values for 9999th time :/

jorel
25th November 2002, 06:07
i get a briliant thin line in the bottom!
(just like double line)
anyone get too?

neopholus
26th November 2002, 11:24
Hi,

if you want to use AutoCrop in DVD2SVCD have a look here (http://forum.doom9.org/showthread.php?s=&threadid=35746&pagenumber=2) or here (http://forum.doom9.org/showthread.php?s=&threadid=38419).

bilu
5th December 2002, 22:40
How about a YV12 version ? :D

CropsyX
11th December 2002, 07:50
Originally posted by bilu
How about a YV12 version ? :D

I do plan to write a YV12 version of the filter at some stage. However I
probably won't start on it until AviSynth 2.5 is released or is at least at
a relatively stable beta level. There will probably be one or two more
releases of AutoCrop for YUY before then. I have a few features I'm keen to implement before I tackle YV12.

wotef
7th January 2003, 23:20
cropsyx, i love this filter!

really looking forward to an avisynth 2.5 release! if you're still around!

ldivx
29th January 2003, 16:43
CropsyX

can you compile your filter for avysynth 2.5 ?
for use with YUY or yv12 ?
thank for your work.
i wait for your next release.

bilu
29th January 2003, 16:49
I haven't tried SansGrip RemoveBorders filter yet, but he promises YV12 on next release :D

For now I'm depending on your filter to make my AVS 2.5 transition ;)

Bilu

CropsyX
30th January 2003, 09:38
Laziness prevented me from actually releasing anything prior to AviSynth 2.5 going beta so I've decided to jump directly to AviSynth 2.5 and discontinue support for AviSynth 2.0x versions.

I'm finishing up work on the AviSynth 2.5 version of AutoCrop tonight. This version will NOT have YV12 support. For the time being you'll have to use ConvertToYUY2 first, if you're using preview mode this won't make any noticable difference.

On the brighter side I've finally added support for maintaining and specifying aspect ratios. I've also added the requested logging of cropping values to a file.

There will be a release late this evening Australian time.

RB
30th January 2003, 10:28
Thanks! I have made an extension to your previous release that makes it very easy to use it for preview mode in DVD2SVCD, optimized cropping and resizing is then done by integrating the FitCD program. It's now no longer a plugin that can be used in a real-life AVS script, only for DVD2SVCD preview. http://forum.doom9.org/showthread.php?s=&threadid=44445

CropsyX
30th January 2003, 10:46
RB

Thanks for posting about AutoFit CD here, I don't follow the DVD2SVCD forum so I was unaware that it existed until now. It's great to see someone else getting some use from the source.

All
Does anyone particularly need the planned new Aspect Ratio features ported back to AviSynth 2.07? I don't plan to maintain two versions in the long run but one more release would be easy enough if there is demand.

CropsyX
30th January 2003, 13:19
I've finished up the first AviSynth 2.5 version of AutoCrop. A change log is posted below. You can download the new version from

http://www.videofringe.com/autocrop/AutoCrop04.zip

Changes

This version of AutoCrop is compiled for AviSynth 2.5 it will not work with any of the 2.0 releases. If you need to use AviSynth 2.0 please download version from http://www.videofringe.com/autocrop

This filter does not yet support YV12, in the interim you will need to use ConvertToYUY2() before calling AutoCrop. I would strongly recommend using AutoCrop in preview mode to get the cropping settings then removing the call to AutoCrop if you are using YV12 sources.

The preview argument (which was a boolean) has been removed and replaced with the new mode arguement (which is an int) this was to allow for the implimentation of the logging mode and the future blanking mode.

Aspect Ratio support. Support for maintaining and setting aspect ratios is included.

Logging mode. Image is left untouched, cropping information is written to the file "AutoCrop.log" in the current directory.

wotef
1st February 2003, 22:33
hurrah! :D thanks for this filter, it extends the life of my mouse and keyboard

...did you ever think perhaps this functionality could make it into core?

CropsyX
2nd February 2003, 01:52
Wotef

I'm glad you're finding the filter useful.

As for making it into the core I don't think it's likely as it's not really essential to using AviSynth. Besides I can't imagine the AviSynth guys wanting some newbies code making a mess of the core :)

CropsyX
26th February 2003, 07:26
I've finished AutoCrop version 0.5. This version (finally) adds YV12 support. There aren't any other major changes as I'm keen to get make sure YV12 support is OK before starting on new features.

You can get the new version at

http://www.videofringe.com/autocrop/AutoCrop05.zip

Feedback on how well the YV12 cropping works is welcome.

I really only have blanking mode on my list of new features for 0.6 so if anyone has enhancement requests now would be a good time to share them.

I should note that this version and any subsequent versions won't be ported back to AviSynth 2.0x

bilu
26th February 2003, 10:32
Hurray :)))))

Now, for those of you who want AutoResize based on bpp, here's a function:

=========================
function ResizeARC(clip c,int bitrate,float compressibility,string resizefn) {
ratio=string(eval(string(c.width)+". /"+string(c.height)+"."))
res=string(floor(eval("("+string(bitrate)+"*1000)/("+string(compressibility)+"*"+string(c.framerate)+")")))
nhtemp=floor(sqrt(eval(res+"/"+ratio)))
nwtemp=floor(eval(string(nhtemp)+"*"+ratio))
nh=nhtemp - nhtemp%32
nw=nwtemp - nwtemp%32
return eval(resizefn+"(c,"+string(nw)+","+string(nh)+")")
}
==========================

Usage: ResizeARC(860,0.2,"FastBilinearResize")

It respects AR as possible mantaining MOD32 resolutions,uses bitrate, bpp and the resize function specified as parameters (to newbies, see doom9 divx5 gknot encoding guide for explanation on bpp)

My current script in this thread (http://forum.doom9.org/showthread.php?threadid=47053) .


Bilu

seewen
26th February 2003, 18:45
For 0.6, you could maybe add an option, so that AutoCrop shows the values :

Crop(left, top, width, height )
or
Crop(+left, +top, -right, -bottom)

bilu
26th February 2003, 19:06
@seewen

I think it already has, I've been using Avisynth 2.5 with crop values taken from the preview mode from version 0.4

Best regards,
Bilu

bilu
27th February 2003, 01:47
@CropsyX

The MultOf parameters are not working on this new version, I only got a clip to work when the filter cropped MOD2 automatically. :(


Bilu

CropsyX
27th February 2003, 03:39
I'll take a look into the MultOf parameters not working. Assuming I can find the problem a new version will be released within 24 hours.

CropsyX
27th February 2003, 07:53
New version 0.51 with (hopefully) working wMultOf and hMultOf in YV12 mode.

http://www.videofringe.com/autocrop/AutoCrop051.zip

bilu
1st March 2003, 02:28
@CropsyX

It still doesn't work, alone or with other filters, get's wierd colors :confused:

Tried Autocrop(mode=0,wMultOf=16,hMultOf=16)

Bilu

CropsyX
3rd March 2003, 05:02
Could someone else post their experience with using AutoCrop in YV12 color.

I've been unable to reproduce Bilu's problem and it would be helpful to know how widespread the problem is.

bilu
3rd March 2003, 09:09
CropsyX,

Sorry for not posting before. Here it is.

Autocrop(mode=0,wMultOf=16,hMultOf=16,threshold=20)



Bilu

(attach waiting for approval)

ldivx
5th March 2003, 13:49
hello guys,
i confirm, i have the same bugs , i have got wierd colors.
with one or more filters.
But i love this filters
thanks

Defiler
5th March 2003, 14:35
On the other hand, it's working like a charm for me in YV12. Heh.

bilu
5th March 2003, 15:09
@Defiler

Are you using the MultOf options?

I'm using the last AVS 2.5 beta. (http://cultact-server.novi.dk/kpo/avisynth/avs_cvs.html)

Bilu

Defiler
5th March 2003, 15:32
Yes. Both MultOf options are set to 16. I'm using a recent Avisynth 2.5 beta, but I'm not sure if it's necessarily the latest anymore. I'd have to check when I get home.

CropsyX
5th March 2003, 15:48
OK this is really weird.

The best way I can see to move forward is for someone to post a small clip that produces a bad output when cropped along with the command they used.

With that we can see if the problem is dependent on the source file or not.

If not I guess the AviSynth version is a possibility and also the YV12 decompressor. For the record I'm using AviSynth 2.50 beta 28 Jan 2003 and the Divx 5.02 decompressor. Particularly for people who find autocrop doesn't work posting your AviSynth Version and YV12 decompressor would be useful.

CropsyX
5th March 2003, 16:03
Quick update I tried version "Avisynth 2.50 (Feb 27. 2003)" on my other PC with the same positive results.

I guess that suggests either I'm dealing badly with the source file or a different YV12 decompressor doesn't like the frames AutoCrop spits out.

bilu
5th March 2003, 17:18
@CropsyX

Are you using the crop values you get in Preview mode in the Avisynth crop function, or using your own crop function? If you are using your own crop, is that needed, given you want to implement new features?

Bilu

CropsyX
6th March 2003, 04:12
@Bilu

I'm using AutoCrop to do the cropping (ie mode=0).

I'm not sure what you mean by

"If you are using your own crop, is that needed, given you want to implement new features?"

My current plan is that other development will be put on hold until the YV12 issue is sorted out. It's fairly big problem when a program called AutoCrop can't actually crop properly :)

bilu
6th March 2003, 11:34
At the moment i'm recording the crop values in the Preview mode to use with Avisynth's crop. I was asking if there is any reason for you not doing the same? I mean, in mode 0, you could get the values and export them to Avisynth crop function ( I think :confused: ) and that would solve every crop problem. Better yet, if crop problems would arise, they would be resolved by the entire Asisynth community :D

Bilu

CropsyX
6th March 2003, 13:43
Originally posted by bilu
At the moment i'm recording the crop values in the Preview mode to use with Avisynth's crop. I was asking if there is any reason for you not doing the same? I mean, in mode 0, you could get the values and export them to Avisynth crop function ( I think :confused: ) and that would solve every crop problem. Better yet, if crop problems would arise, they would be resolved by the entire Asisynth community :D

Bilu

I couldn't work out a way to call the internal AviSynth crop filter. I'd like to but I don't know if it's possible, there is a bare minimum of programmers docs for 2.0x and less for 2.5 so I don't hold out much hope of getting it working.

In light of this my prefered solution is to fix the current cropping issue in YV12, however I won't be able to do this until someone provides a sample file that causes problems after cropping.

bilu
8th March 2003, 12:22
CropsyX,

I sent you a sample by e-mail. Now I answered something else on another thread (http://forum.doom9.org/showthread.php?s=&postid=275400#post275400) that could be related to this problem too. :confused:


Best regards,

Bilu

bilu
8th March 2003, 13:07
A workaround for using Avisynth's crop function ( you need the CALL filter):

Autocrop(mode=2,wMultOf=16,hMultOf=16,threshold=40)
Call("cmd /c copy D:\autocrop.log D:\crop.avs","-2")
import("D:\avs_filters\avs25\tests\analyse\crop.avs")

It seems that AutoCrop is not cropping by even numbers and by the info on my prior post you may have to do it.


Best regards,
Bilu

jarthel
10th March 2003, 01:17
how fast is autocrop compared to crop?

finding crop values (for built-in crop) takes around 30 seconds a minute for me which is not too bad.

CropsyX
11th March 2003, 04:52
@all

The YV12 cropping bug has been identified and fixed a new version will be released shortly.

@jarthel

Regarding cropping speeds. YUY2 cropping is pretty much the same speed as the inbuilt crop. YV12 cropping is slightly slower. With no other filters and using XVID's "Null - Speed Test" mode for the compressor the difference is around 3%. As you add other filters and actually compress the output I'd expect the amount of real world difference to be pretty much neglible.

The speed of autocrop finding the values to crop by is almost entirely related to the type of the source file. Huffy and MJPEG clips are several times faster to find the crop values of than MPEG2 clips.

Because the autocrop filter asks for a number of frames spread through out the clip it is much slower on sources where frame seeking is slow. If you reduce the samples parameter you should get an almost linear decrease in the amount of time taken to compute the autocrop values.

CropsyX
11th March 2003, 13:24
A new version of AutoCrop which solves the YV12 cropping problems found in version .51 is now available. Thanks to Bilu for his help tracking the problem down.

http://www.videofringe.com/autocrop/AutoCrop10.zip

I've skipped from version .51 to 1.0 to reflect the fact this project now has all the major require functionality present and (hopefully) working.

bilu
13th March 2003, 03:53
Works very well now. Tested on 3 clips from different movies with different settings.

Congratulations for your valuable filter!
Congratulations again since it is your first! :D

Best regards,
Bilu

TheUnforgiven
9th May 2003, 00:00
link for AutoCrop 1.0 down?

bilu
9th May 2003, 00:46
link is OK, I tested it now :confused:

TheUnforgiven
9th May 2003, 01:06
maybe the problem is the college internet connection (a lot of firewalls and stupid stuff) i'll try from outside later.
thanks

simon.mittag
30th May 2003, 05:58
Hi,

I recently tried AutoCrop within the new ffdshow source filter and it works now (with the new 25/05/03 ffdshow release).

However, when using AutoCrop on DVD sources that are passed through ffdshow, i noticed a strange behaviour of Autocrop.

At startup of DVD playback, the Autocrop filter seems to crop the entire picture instead of doing only the part defined through the threshold. Increasing the number of peek frames at the beginning of playback (to avoid trailing total blackness) to 50 or 100 frames didn't help, cropping leaves about 3*4 pixels of the pic untouched and crops the rest.

Autocrop does find the right cropping edges when applied through the ffdshow dialog directly once playback has started, just not when starting up playback with the dvd navigator.

Media files such as divx or even vobs that come from a file source worked fine, I have this only with DVDs and only when i start playback, any ideas? (starting playback of the main title, not menus of course)

CropsyX
30th May 2003, 09:06
First a disclaimer, I haven't used the ffdshow version with AviSynth support. That said I've got a pretty solid hunch as to what the problem is.

On startup Autocrop samples 10 (by default) frames at equal intervals from within the file to determine the cropping information. In passthrough mode the ffdshow probably can't deliver any of the frames AutoCrop wants. If ffdshow is doing the decoding itself it probably can deliver the frames needed.

My development box isn't set up to do DVD playback with ffdshow so I can test this theory out. If there's some documentation (that I couldn't find) about how AviSynth works from within ffdshow I might be able to code around the problem anyway.

simon.mittag
31st May 2003, 07:17
I haven't looked at how SourceFilters work in detail, but does it matter if it's a file based or stream based source? Meaning will AutoCrop only work when being able to poll frames as You described?

Milan Cutka added the avisynth plugin to ffdshow so he is the only person I know we could contact regarding that.

Autocrop works like a charm with my file based sources and does me good service as a positioning tool for my projector/big screen setup. Would be fantastic if it would work with DVDs that come through the RAW input of ffdshow as well.

What would be a solution given u can't request frames off a stream? can u listen to and cache the first x frames and start playback slightly delayed or would this cause side effects such as audio desynchronisation?

CropsyX
31st May 2003, 09:12
For DVD sources AutoCrop would work fine 90+ percent of the time based off one single non blank frame. The existing code tries to increase that percentage to close to 100% and also works with noisy VHS sources. However the first frame the current code asks for is 10% of the way through the file which is likely to be a problem in RAW mode.

Unless Milan fixes the problem of his own accord I'd need to get DVD playback running through ffdshow on my development box to have a decent shot at fixing the problem. At the moment I have some other projects I'm working on but I'll try to get to your problem ASAP.

bilu
31st May 2003, 09:56
I used FFDShow over DVD once on my laptop, it's great to use some noise on luma/chroma when I connect it to my TV because it has a composite TV output and composite signal makes some distortions over luma/chroma.

( I stopped using it because my laptop is a PIII-500 and I couldn't get decent playback :rolleyes: )

It seems to my that FFDShow under RAW mode grabs at the end of any DShow video decoder on the graph. If so it may not have capability to request frames by itself, it could be that it just accepts what is being delivered. :confused:

In that case you can only use AutoCrop sampling over one of the frames, or consecutive frames.



Bilu

simon.mittag
31st May 2003, 12:20
Originally posted by CropsyX

Unless Milan fixes the problem of his own accord I'd need to get DVD playback running through ffdshow on my development box to have a decent shot at fixing the problem. At the moment I have some other projects I'm working on but I'll try to get to your problem ASAP.

i am unsure what to ask him to do??...he provides a working source filter now, so autocrop is loading and isnt even crashing - as well as that media files that come through ffdshow work, just not dvds.

what do you reckon is the problem? can we at least narrow it?

you can't seek in a dvd playback stream, is that it?

CropsyX
31st May 2003, 15:55
Bilu
Thanks for educated guess as to how ffdshow works in RAW mode. It makes sense that it would be done that way.

Originally posted by simon.mittag

what do you reckon is the problem? can we at least narrow it?

you can't seek in a dvd playback stream, is that it?
The problem is that ffdshow in RAW mode can't provide the frames Autocrop asks for. I don't see anyway you could get ffdshow to provide AutoCrop the data it wants.

It *might* be possible to modify AutoCrop so that it only asks for frames ffdshow can provide in RAW mode. However autocrop decides it's cropping information the first time it's called so if the start of the video is black it still won't help.

I've taken a brief look into getting ffdshow + dvd setup on my PC but I couldn't find any documentation that suggests how to install it without ZP3/Windvd or the Cinemaster filters. I don't have either. You're probably better off looking for an alternate solution as I'm unlikely to be in a position to get to do any testing in the near future.

The source to AutoCrop is available so if anyone else is interested they're welcome to look into the problem.

Blankman
2nd June 2003, 23:43
Originally posted by CropsyX
For DVD sources AutoCrop would work fine 90+ percent of the time based off one single non blank frame. The existing code tries to increase that percentage to close to 100% and also works with noisy VHS sources. However the first frame the current code asks for is 10% of the way through the file which is likely to be a problem in RAW mode.


I wish it could be that easy. My average project is much more complicated. For a typical anime episode, I used:

Trim(00000,02200).LanczosResize(dim_x,dim_y,06,08,696,464)
\ + Trim(02201,12512).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(12513,12668).LanczosResize(dim_x,dim_y,14,16,696,464)
\ + Trim(12669,16244).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(16245,16352).LanczosResize(dim_x,dim_y,14,16,696,464)
\ + Trim(16353,18530).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(18531,18771).LanczosResize(dim_x,dim_y,06,06,702,468)
\ + Trim(18772,18811).LanczosResize(dim_x,dim_y,04,08,696,464)
\ + Trim(18812,18906).LanczosResize(dim_x,dim_y,06,06,702,468)
\ + Trim(18907,19085).LanczosResize(dim_x,dim_y,06,08,696,464)
\ + Trim(19086,19128).LanczosResize(dim_x,dim_y,06,06,702,468)
\ + Trim(19129,21179).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(21180,21212).LanczosResize(dim_x,dim_y,14,16,696,464)
\ + Trim(21213,23161).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(23163,23163).LanczosResize(dim_x,dim_y,26,16,672,448)
\ + Trim(23163,23607).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(23609,23609).LanczosResize(dim_x,dim_y,26,16,672,448)
\ + Trim(23609,25513).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(25515,25515).LanczosResize(dim_x,dim_y,26,16,672,448)
\ + Trim(25515,26134).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(26136,26136).LanczosResize(dim_x,dim_y,26,16,672,448)
\ + Trim(26136,30180).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(30181,32230).LanczosResize(dim_x,dim_y,06,06,702,468)
\ + Trim(32231,00000).LanczosResize(dim_x,dim_y,14,08,696,464)

Defiler
2nd June 2003, 23:52
Why would you need to "pan and scan" the cropping around during the video like that? Just curious.

Blankman
4th June 2003, 15:21
Originally posted by Defiler
Why would you need to "pan and scan" the cropping around during the video like that? Just curious.

To clean up the material as mush as possible before applying any noise filters. The cleaner the source the less aggressive noise filtering is needed, the shorter it takes to encode the material, and the better the resulting encode.

With the material I work with, I do this to correct two main problems:

1) The image does not fill out the entire width (480 pixels) and the positioning of the image center wanders during some scene changes. I see this a lot with anime material converted from Film to NTSC.

2) The first frame after a scene change may be really bad, and it becomes highly noticeable when the frame rate is dropped from 29.970 to 23.976. Very often I can zoom in on a nearby frame or layer selected pixels from a nearby frame to replace the bad pixels. (I look forward to a YV12 version of layer. To avoid performance penalties, I'm doing the latter outside of the AVS script.)

Defiler
4th June 2003, 15:25
Interesting. Thanks.

Wilbert
4th June 2003, 15:31
I look forward to a YV12 version of layer.
Layer itself seems to work in YV12, it is mask that doesn't work in YUV.

simon.mittag
6th June 2003, 00:44
Originally posted by CropsyX
Bilu
The problem is that ffdshow in RAW mode can't provide the frames Autocrop asks for. I don't see anyway you could get ffdshow to provide AutoCrop the data it wants.

It *might* be possible to modify AutoCrop so that it only asks for frames ffdshow can provide in RAW mode. However autocrop decides it's cropping information the first time it's called so if the start of the video is black it still won't help.


what about making the number of frames and their position AutoCrop is peeking for configurable through a parameter?

Wouldn't that solve the problem or at least find people settings that work for them?

CropsyX
6th June 2003, 07:10
Originally posted by simon.mittag
what about making the number of frames and their position AutoCrop is peeking for configurable through a parameter?

Wouldn't that solve the problem or at least find people settings that work for them?
I've done some experiments using RAW mode (on Avi files rather than DVD's) and ffdshow does infact pass the current frame to AviSynth regardless of what frame is asked for. For this reason adding new parameters to AutoCrop won't solve the problem.

Basically if you start AviSynth from within FFDShow when the screen display is black (as it typically is at the beginning of a movie)AutoCrop won't work and can't be modified to work. The only solution would be to wait until the movie itself starts and then turn autocrop on.

CropsyX
17th June 2003, 09:38
I've released version 1.1 of AutoCrop which you download from
http://www.videofringe.com/autocrop/AutoCrop11.zip

I've received some feedback about the large amount of time AutoCrop takes to startup so I decided to look into possible optimisations. As it turns out 99% or more of the time taken by AutoCrop when using XVid,divx and MPEG2 sources is used by AviSynth's GetFrame function. Unsurprisingly fetching an arbitary frame especially if it's a non key frame takes a long time.

In the absence of being able to make any worthwhile optimisations I've reduced the default number of frames to sample from 10 to 5. The change should halve the startup time of the filter and for DVD and other relatively clean sources the results are likely to be exactly the same.

I've also added the requested feature of being able to specify a range of frames that AutoCrop looks at when determining cropping information.

Finally I lowered the default threshold from 40 to 30 which should give better performance on dark DVD's. If you're working from VHS you may need to change the default now.

john blox
23rd June 2003, 12:56
Is there any possibility you would be able to make a version of your autocrop filter to work as a 'native' virtualdub filter? an all-in-one auto-crop/resize filter seems to be severly missing. If your filter could be converted to work with that it would make virtualdub awesome. I'd like to find a way to auto-convert digital-tv mpeg2's to divx with auto cropping & resizing with no human intervention.

CropsyX
23rd June 2003, 14:58
I don't think it would be possible to convert AutoCrop in it's current form to run in VirtualDub. According to the VirtualDub filter docs future frames cannot be accessed. AutoCrop access frames throughout the video so that limitation is enough to stop a VirtualDub version.

john blox
23rd June 2003, 23:56
OK - thanks for your reply.

Blankman
25th June 2003, 18:34
I guess what I can use now is an "AutoCenter", to help shorten the amount of time it takes me to produce something like this:

Trim(00000,02200).LanczosResize(dim_x,dim_y,04,08,702,468)
\ + Trim(02201,10339).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(10341,10341).LanczosResize(dim_x,dim_y,14,16,696,464)
\ + Trim(10341,16507).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(16508,16748).LanczosResize(dim_x,dim_y,08,06,702,468)
\ + Trim(16749,16789).LanczosResize(dim_x,dim_y,04,08,696,464)
\ + Trim(16790,16884).LanczosResize(dim_x,dim_y,10,06,702,468)
\ + Trim(16885,17063).LanczosResize(dim_x,dim_y,06,08,696,464)
\ + Trim(17064,17106).LanczosResize(dim_x,dim_y,08,06,702,468)
\ + Trim(17107,26058).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(26061,26061).LanczosResize(dim_x,dim_y,20,12,684,456)
\ + Trim(26060,28327).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(28329,28329).LanczosResize(dim_x,dim_y,20,12,684,456)
\ + Trim(28329,29976).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(29978,29978).LanczosResize(dim_x,dim_y,20,12,684,456)
\ + Trim(29978,30200).LanczosResize(dim_x,dim_y,14,08,696,464)
\ + Trim(30201,32250).LanczosResize(dim_x,dim_y,08,06,702,468)
\ + Trim(32251,00000).LanczosResize(dim_x,dim_y,10,06,702,468)

which simply crops out wandering boarders. I find this type of behavior very common with film.

oddball
15th August 2003, 19:19
AutoCrop does not work with overlay it would seem. It crops the image but does not crop the overlay. I tried to use it in conjunction with ffdshow and it outputs all material within a 4/3 box (Tried fiddling with AutoCrop aspect settings it made no difference).

I was hopeing to use it as a replacement for DiVXG400 which has an AutoCrop mode of it's own. However you have to switch it on for black bar material (Usefull for outputting widescreen SVCD material with a fake anamorphic squeeze) and turn it off again for stuff that's already cropped (Like DiVX movies).

But AutoCrop used as a filter in ffdshow just crops before the overlay. :(

RathO
17th August 2003, 05:31
Wow, nice work for this filter!
I just tried it but have a little problem with the AR even with this script:

Autocrop(mode=1,aspect=-1)

I think im suppose to keep the source AR (4/3 in my case) with the -1 value...

What am i doing wrong? :confused:

Regards

piscator
10th October 2003, 00:11
Great filter, I just found one minor bug/setback.
If you want to log the crop (mode=2), and thereafter want to apply the crop, the results are not always exactly the same.

For Example, the following .avs script.
AutoCrop(mode=2,samples=10,samplestartframe=5000)
AutoCrop(mode=1,samples=10,samplestartframe=5000)

Line 1 logs Crop(0,70,720,438) in AutoCrop.log
Line 2 logs Crop(4,70,716,428) in preview

I would expect the results would always be the same for the same parameters.

greetz,
Piscator

CropsyX
10th October 2003, 10:35
Sorry I missed the last couple of comments in this thread.

Oddball
As described earlier in this thread AutoCrop has problems when used within ffdshow. Unfortunately there isn't really anything I can do about them.

Ratho & piscator
In brief testing I can't reproduce your problems. If you can make a small sample (less than 5mb) that demonstrates the problem and your full script available to me I'll try fix your problems.

You can PM me with a link to the file or for an email address if you'd prefer to send the files by email.

len0x
1st January 2005, 21:06
Time to bring this thread up :)
I found the bug and fixed it: if no cropping is necessary then -1 AR parameter very often doesn't preserve input AR properly. Basically if AR cannot be represented as float with limited number of decimals digits (like 4/3=1.33333...) then rounding error makes it impossible to keep AR as presize as possible (you loose just 1 pixel but as its usually mod4 then you loose 3 others as well).

I contacted CropsyX, but if he's not around then I'll release a new version myself.

piscator
2nd January 2005, 16:43
Originally posted by len0x
Time to bring this thread up :)
I contacted CropsyX, but if he's not around then I'll release a new version myself.

len0x/CropsyX, if you release a new version, please add the following too.

1) Cropping and logging the crop at the same time (behavior of mode=0 and mode=2). E.g. introduce a mode=3 or perhaps better a separate parameter for logging. I still have the problem that doing consecutive crops (first mode=2 to log, then mode=0 or mode=1) doesn't always yield the same results.
2) Allow a wMultOf=2 instead of current minimum of wMultOf=4.

If you want the source code for this, PM me. But I guess it's pretty straight-forward.

greetz,
Piscator

len0x
2nd January 2005, 17:03
Seems CropsyX is not around...

Current compiled version of Autocrop seems kinda borked to me as it crops more then required in lots of cases (for instance I have xvid sources feeded into script via directshowsource that do not require crop at all, but somehow I get 2 pixels cropped from left and right). Now, when i compiled my version without changing anything in the source code - autocrop behaves properly

@piscator

1) that should be doable
2) YV12 requires mod4 width, so its better to leave it as it is (in fact if you have YUY2 then its mod2 actually in the source code)

len0x
2nd January 2005, 17:33
OK here is a test version:

http://len0x.leffe.dnsalias.com/autocrop12.zip

that corrects the problems mentioned by me plus mode=3 added from piscator's suggestion.

piscator
2nd January 2005, 18:20
Originally posted by len0x
Current compiled version of Autocrop seems kinda borked to me as it crops more then required in lots of cases (for instance I have xvid sources feeded into script via directshowsource that do not require crop at all, but somehow I get 2 pixels cropped from left and right). Now, when i compiled my version without changing anything in the source code - autocrop behaves properly


Yes, I noticed the problem with cropping from the left and right too. In fact, if you did autocrop on the same source multiple times, you would have this problem sometimes.

Originally posted by piscator
For Example, the following .avs script.
AutoCrop(mode=2,samples=10,samplestartframe=5000)
AutoCrop(mode=1,samples=10,samplestartframe=5000)

Line 1 logs Crop(0,70,720,438) in AutoCrop.log
Line 2 logs Crop(4,70,716,428) in preview


btw, my own compile had the same problem as CropsyX. I had a discussion with him last year about this but we couldn't figure out the problem and left with the notion that it was perhaps AviSynth related.

I think also top and bottom are a bit *undercropped*. To generate the same crop as GKnot I use:
AutoCrop(mode=2,samples=50,wmultof=2,hmultof=4,rightadd=1,topadd=2,bottomadd=2)
(I use batchscripts/avisynth scripts to do auto compressability checks for gknot). Somehow, I needed to use wmultof=2 also for YV12. Perhaps, GKnot at that time (1 year plus ago) always used a wmultof=2, but I can't remember that and of course didn't write a note about that :rolleyes:

Anyway, I'll give your test version a shot.

greetz,
Piscator

len0x
2nd January 2005, 18:46
Originally posted by piscator
I think also top and bottom are a bit overcropped. To generate the same crop as GKnot I use:
AutoCrop(mode=2,samples=50,wmultof=2,hmultof=4,rightadd=1,topadd=2,bottomadd=2)


I don't get it - you mean undercropped? (since you do more cropping than required). You should e able to use threshold to do that in a generic way...

len0x
2nd January 2005, 20:07
I'm reading the code for getting actual cropping values and it seems to me that it always crops too much. It looks for a row/column with average luminance above threshold but not the first - third in a row and then stops. So basically 2 more row/columns are always cropped unnecessary... (unless I'm missing something)

*Edit* scrap all that and read my next post :)

len0x
2nd January 2005, 20:52
I found the reason preview and actual crop are different - its because filter is working in different modes: YV12 for crop, YUY2 for preview. and the only difference is:


if (yuy2) {
leftAdd = (_leftAdd + (leftAdd%2))*2;
rightAdd = (_rightAdd + (rightAdd%2))*2;
} else {
leftAdd= _leftAdd;
rightAdd = _rightAdd;
}


leftAdd and rightAdd are not initialized in YUY2 mode, so it might be garbage in which case additional cropping will be done. I don't quite understand why special processing for YUY2 is needed anyway (if someone knows what code above actually does please shout). For now I just made it for YUY2:

leftAdd = (_leftAdd )*2;
rightAdd = (_rightAdd )*2;

P.S. I also modified some code to make sure that threshold=0 always disables autocrop (previously it didn't guarantee that). The link in my first post is updated, btw, with current version.

piscator
2nd January 2005, 23:33
Originally posted by len0x
I don't get it - you mean undercropped? (since you do more cropping than required). You should e able to use threshold to do that in a generic way...

Yes, I mean *undercropped*. Apparently the effects of the New Years party didn't wear off yet :o. And I used the topAdd,BottomAdd because I saw blacklines on top and bottom sometimes. Playing around with threshold doesn't help much in this case. Besides, some trial and error gave me with these settings almost always the same result as cropping in gknot.

Originally posted by len0x
I found the reason preview and actual crop are different - its because filter is working in different modes: YV12 for crop, YUY2 for preview. and the only difference is:

[code]
if (yuy2) {
leftAdd = (_leftAdd + (leftAdd%2))*2;
<snip>


Looking more closely at the code yuy2 is also not properly initialized. I guess it should be replaced with: vi.IsYUY2(). Actually, I think the datamember yuy2 can be removed entirely and replace it everywhere with vi.IsYUY2(). leftAdd and rightAdd were also not properly initialized, as you stated (probably the cause of my problem too).

Out of my memory (as far as it is working today...):
1) the yuy2 format (or yuyv format) denotes a time multiplexed signal YU|YV|YU|YV. This is just a byte-order reversed from the (more familiar) uyvy format which has the form UY|VY|UY|VY. (Y=luminance, U/V=chrominance, |=separator to indicate next sample from signal)
2) the yv2 format, or more accurate the YVU 4:2:2 fomat, denotes a time multiplexed signal YVU|YVU but Y takes as much bits as VU. Roughly said, it divides the chroma/color plane by 2.

As you can see method 1 requires twice the amount of samples to construct a pixel. That's why you want mod 2 and mul 2 calculations for yuy2 format.

Hope I said it right, it's a while ago that I worked on video signals and the *wonderful* amount of different formats (imo wonderful can be replaced with redundant, but I'm not supposed to say that ;))

greetz,
Piscator

Wilbert
2nd January 2005, 23:44
2) the yv2 format, or more accurate the YVU 4:2:2 fomat, denotes a time multiplexed signal YVU|YVU but Y takes as much bits as VU. Roughly said, it divides the chroma/color plane by 2.
Huh, two bytes are used for Y? Any reference?


if (yuy2) {
leftAdd = (_leftAdd + (leftAdd%2))*2;
rightAdd = (_rightAdd + (rightAdd%2))*2;
} else {
leftAdd= _leftAdd;
rightAdd = _rightAdd;
}
1) What's difference between _leftAdd and leftAdd? If they are the same and denote the number of pixels to be added on the left and right, then each of them should be even (chroma is shared between two pixels as piscator explained).

2) The else case is that rgb?

piscator
3rd January 2005, 00:22
Originally posted by Wilbert
Huh, two bytes are used for Y? Any reference?

Actually, half the bytes are used for the U-plane and V-plane.
Reference by google: YUV Formats (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/YUVFormats.asp), figure 12. (though I would rather prefer the term 'increasing time' instead of 'increasing memory addresses').


1) What's difference between _leftAdd and leftAdd? If they are the same and denote the number of pixels to be added on the left and right, then each of them should be even (chroma is shared between two pixels as piscator explained).

2) The else case is that rgb?

1) _leftAdd is the parameter for the method. leftAdd is a datamember. Just some source code stuff. Both denote the number of pixels to be added to the crop (and taken from the frame). Chroma is only shared for method 1 (yuy2), not method 2 (yv12). Thus, multiplying by 2 makes sure an even number of samples is taken.

2) The case for anything not yuy2, also yv12 and rgb. Though I doubt rgb is used much, since you want to have y (luminance) and uv (chrominance) in separate signals for mpeg stuff (to do the fourrier transformations on).

greetz,
Piscator

Wilbert
3rd January 2005, 00:42
Actually, half the bytes are used for the U-plane and V-plane.
Reference by google: YUV Formats, figure 12. (though I would rather prefer the term 'increasing time' instead of 'increasing memory addresses').
That's YV12 which is 4:2:0, ie UV shared by four (2x2) pixels. Thus for four pixels you need four bytes for the luma values, one byte for U and one byte for V (= total of 6 bytes). This is all covered at www.avisynth.org.

Chroma is only shared for method 1 (yuy2), not method 2 (yv12)
The latter is wrong. See above.

So the code should be
if (YUY2||YV12) {
leftAdd = (_leftAdd + (leftAdd%2))*2;
rightAdd = (_rightAdd + (rightAdd%2))*2;
} else { // RGB
leftAdd = _leftAdd;
rightAdd = _rightAdd;
}


But, I haven't seen the code, so I don't really know ...

len0x
3rd January 2005, 00:49
OK, we're getting somewhere. Indeed YUY2 class variable can be replaced as piscator suggested and therefore it solves the problem with preview being in YUY2 instead of YV12. Now about leftAdd and rightAdd for YUY2 - if its supposed to be even (although I thought mod2 is forced later on anyway) then code should be:

leftAdd = _leftAdd + _leftAdd%2;

P.S. filter only supports YV12 and YUY2, not RGB.

P.P.S I cannot believe that this plugin actually has so many bugs :)

Wilbert
3rd January 2005, 01:07
Ok, agreed.

Btw, note that for interlaced YV12 topAdd and bottomAdd both needs to be divisible by four.

len0x
3rd January 2005, 01:16
OK, for some unknown reasons YUY2 requires mod4 for cropping on the left/right and this code apparently ensures it (its probably used somewhere later in the code):


if (vi.IsYUY2()) {
leftAdd = (_leftAdd + _leftAdd%2)*2;
rightAdd = (_rightAdd + _rightAdd%2)*2;
} else {
leftAdd= _leftAdd;
rightAdd = _rightAdd;
}


Anyway, final corrected version is as usual here:
http://len0x.leffe.dnsalias.com/autocrop12.zip
If nothing wrong found in it I'll release it.

*Edit* Actually mod4 is enforced because of the parameter, not because of the code above. Its just if you want to have mod4 and to crop at least 1 pixel from the left (i.e. _addLeft=1) then in YUY2 left crop will be 4 and in YV12 it'll be 2 plus 2 on the right (code is different).

len0x
3rd January 2005, 15:33
I released version 1.2 in this thread: http://forum.doom9.org/showthread.php?s=&threadid=87602

saibo
18th January 2006, 23:06
HI! I am a Newbie. :) I have the following problem. After installing the AutoCrop Filter I get the this message during opening my avs script: "avisynth open failure:Script error:there is no function named GripCrop (F:\der untergang\untergang.avs , line4"

Here is my script:
LoadPlugin("c:\Programme\DGMPGDec\dgdecode.dll")
LoadPlugin("C:\Programme\AviSynth\plugins\AutoCrop.dll")
mpeg2source("F:\Der Untergang\untergang.d2v")
GripCrop(704, 576, source_anamorphic=true)
GripSize("Lanczosresize")
ReduceBy2()
ReduceBy2()


I use avisynth 2.5.6 Is that the reason?:(

buzzqw
19th January 2006, 08:19
if you want to use gripcrop the dll to load ins't autocrop but "GripFit_YV12" (iirc)

tips: try a search for gripcrop ;)

BHH

saibo
19th January 2006, 15:05
Thank your for your quick reply. I will try it.

Delta2
3rd March 2006, 10:01
CropsyX

Many thanks for your filter, works great, very good job

StainlessS
19th October 2012, 17:55
Find temp link below to a readable version of the AutoCrop source code.

EDIT: DELETED


AutoCrop source is excruciating to read and I gave up the first few times I looked at it.
A few months ago, I did a 90% conversion to something readable, and thought I better finish and put it
up so as to avoid a similar harrowing experience for others, so, here it is.
It compiles (no dll supplied) and seems to work OK, but has not undergone much testing. Idea being just
to understand how it works. If someone else wants to take this and do a mod, great but I will not be
supporting this source in any way, (I'm doing my own Auto Cropping alternative right now, RoboCrop).

Hope someone finds a use for it, it will NOT be on-line @ above link for long, I will leave for perhaps a month
and then delete the link and file.

EDIT: Contains original source too.

SassBot
19th October 2012, 18:05
Thanks. I was going to port this next for Vapoursynth since I use it quite a bit. Your source looks much easier to work with and hundreds of lines shorter to boot.

StainlessS
19th October 2012, 18:13
Arh good, that last 10% was worth the bother after all.
You're are a bit quick, I've only just posted 10 mins before your reply.
I really have to take a look at Vapoursynth one day, and also Python.
good luck with the mod.

SassBot
19th October 2012, 18:23
Yeah, you definitely should. After working with it for a couple of days I like it a lot especially on the plugin development side. It may not be as comprehensive as Avisynth, which is not necessarily a bad thing as feature creep in an API leads to major mess, but it's a nice and very lean, uncrufty re-imagining. Myrsloik deserves major props.

StainlessS
19th October 2012, 18:31
Hopefully the bitblit part near the end of file should be pretty much ready for 2.6+ colorspaces,
untested but I think should be OK.

EDIT: IIRC, fixed about 4 maybe 5 bugs in original source.

StainlessS
27th December 2012, 11:29
Warning, the link to AutoCrop Readable source posted 5 posts prior to this one, will be deleted at the weekend coming.
This is your last chance to get a copy if you want it. (You could always PM me for a copy in future).

EDIT: DELETED