Log in

View Full Version : New filter: AutoCrop


Pages : [1] 2 3

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