Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th August 2007, 22:34   #1  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
New filter: Autolevels

Hi,
some time ago I needed an autogain/autolevels filter and was unsatisfied with what ColorYUV had to offer, so I wrote my own. The main improvement over ColorYUV(autogain=true) is that the amount of gain is averaged over a number of frames which helps with scenes that have flashing lights etc.
This filter was useful for a VHS transfer I had to do recently. Maybe somebody else will find it useful, too.
The parameters are explained on the web page and in the readme file.

URL: http://ta41.zendurl.com/autolevels_en.php

Comments are always welcome, of course.
T. Anschütz is offline   Reply With Quote
Old 5th August 2007, 02:32   #2  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Any source code ?

Yes snapping the gain on a frame by frame basis, as ColorYUV does, sucks!
IanB is offline   Reply With Quote
Old 5th August 2007, 04:30   #3  |  Link
TheRyuu
warpsharpened
 
Join Date: Feb 2007
Posts: 787
How does it compare to HDRAGC?
(not at home otherwise I would try it)

I'll have to test this one out since I got a few bad sources that could use some gain.
TheRyuu is offline   Reply With Quote
Old 5th August 2007, 18:18   #4  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
Quote:
Originally Posted by IanB View Post
Any source code ?
I re-uploaded the zip file with the source code. This is my first c++ program, so apologies if the code is awkward to read. Also, I haven't translated the comments, so they are all in German.

As for HDRAGC, I tried it out but it didn't seem suited well for my purposes. I think it uses a more complex algorithm, where my plugin basically just stretches the luma histogram and applies some averaging, but it was exactly what I needed.
T. Anschütz is offline   Reply With Quote
Old 6th August 2007, 00:20   #5  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Thanks for the source code.

As your filter make very heavy use of the cache you may wish to use the NewVideoFrame model for this filter instead of the MakeWriteable model for your output frame. This will avoid possibly needing to rerender the middle frame on subsequent calls.

Leak has brought to my attention some weaknesses in my algorithm for MakeWriteable VFB protection. It may be better not to depend on avisynth internals to defend against extreme cases of cache usage.
IanB is offline   Reply With Quote
Old 10th September 2007, 04:55   #6  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
Quote:
Originally Posted by IanB View Post
Thanks for the source code.

As your filter make very heavy use of the cache you may wish to use the NewVideoFrame model for this filter instead of the MakeWriteable model for your output frame. This will avoid possibly needing to rerender the middle frame on subsequent calls.

Leak has brought to my attention some weaknesses in my algorithm for MakeWriteable VFB protection. It may be better not to depend on avisynth internals to defend against extreme cases of cache usage.
Sorry for the late reply... I finally got around to looking at my code again. I noticed I was calling child->GetFrame() even for frames whose min / max / isSceneChange values were already known, which is of course silly, so I fixed that. It should call child->GetFrame() only once per frame now, at least for consecutive frames.

As for creating a new frame rather than modifying the original frame object, I see your point, but I'm assuming this isn't an issue any more, now that I'm doing my own caching (of the frame parameters), so I'm not calling GetFrame n times for each frame any more.
But maybe I'm wrong and using NewVideoFrame would still make things more efficient. If so, let me know.

Version 0.3 of the filter is up on my website.
T. Anschütz is offline   Reply With Quote
Old 11th September 2007, 00:29   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
boolean Autolevels::isSceneStart(int frameno, IScriptEnvironment* env) {
...
    if (frameno > 1) {
      PVideoFrame frame = child->GetFrame(frameno, env);
      PVideoFrame prevframe = child->GetFrame(frameno-1, env);
frame and prevframe are still fetched but are no longer used?
Code:
IntPair Autolevels::getMinMax(int frameno, IScriptEnvironment* env) {
  PVideoFrame frame = child->GetFrame(frameno, env);
  const unsigned char* pY = frame->GetReadPtr(PLANAR_Y);
...
  hash_map<int, IntPair>::const_iterator mmIter = MinMaxCache.find(frameno);
You still fetch the frames before checking you MinMaxCache, you probably only need to fetch it if there is no cache entry.

If you adjust your code to only fetch the "new" frame for the MinMaxCache and the "current" frame for outputing then the MakeWriteable model will be appropriate.

Also check on the libraries implementation of hash_map you may need to manually clear them in your destructor code.
IanB is offline   Reply With Quote
Old 11th September 2007, 07:55   #8  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
You are absolutely right, I don't know what I was thinking. Thanks for spotting this!
I uploaded the fixed version, it is still v0.3, same filename.

With the unnecessary GetFrame calls are gone, the filter is a lot faster

I tried calling the hash_map destructor in the Autolevels destructor, but that crashed VDub, so I left it out for now. I need to actually read the documentation when I have some time.
T. Anschütz is offline   Reply With Quote
Old 11th September 2007, 08:16   #9  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Yes, it should be very much faster

The short coming with some hash_map implementations is that it forgets the memory allocated to elements when it destructs.

As a workaround you may need to do a MinMaxCache.clear(), etc, somewhere in your code, Autolevels::~Autolevels might be a good place.
IanB is offline   Reply With Quote
Old 19th September 2007, 12:57   #10  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
Make Level Changes Slowly

This is by far the best "autolevels" filter. It does get fooled on rare occasions in changing low light conditions, snapping quickly up and down a couples of levels. What you might do is to have it fade up or down slowly in low light so not to be noticed.

Excellent filter,

Richard
photorecall.net
rfmmars is offline   Reply With Quote
Old 20th September 2007, 13:15   #11  |  Link
RickA
Registered User
 
Join Date: May 2004
Posts: 89
Very nice. Will have to give this a try later on. Also, always good to see another Anschutz about. ;-)

Cheers,
Rick
RickA is offline   Reply With Quote
Old 21st September 2007, 06:56   #12  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
Quote:
Originally Posted by RickA View Post
Very nice. Will have to give this a try later on. Also, always good to see another Anschutz about. ;-)

Cheers,
Rick
T. Anschütz is offline   Reply With Quote
Old 21st September 2007, 07:00   #13  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
Quote:
Originally Posted by rfmmars View Post
This is by far the best "autolevels" filter. It does get fooled on rare occasions in changing low light conditions, snapping quickly up and down a couples of levels. What you might do is to have it fade up or down slowly in low light so not to be noticed.

Excellent filter,

Richard
photorecall.net
Thank you, I'm glad you like it.
What you are seeing is the filter "detecting" a scene change when there is none. To get rid of this, you can set sceneChgThresh to a higher value. At sceneChgThresh >= 256, scene change detection is effectively disabled and the "snapping" effect should be completely gone.

Of course, with scene change detection turned off, you may get undesirable effects at actual scene changes where the luma values change abruptly from one frame to the next. In these cases you don't want any fading to occur. So just try different values for sceneChgThresh to find out what works best in your situation.

Possibly, maybe, you will find that fades around scene changes aren't a problem and that sceneChgThresh = 256 is the way to go for you.

If you are a perfectionist, you can also deal with the false positives / false negatives by using the frameOverrides parameter, manually overriding the frames it falsely detects as scene changes or when it fails to detect one.

Even better would be a more intelligent scene change algorithm. Right now it looks at the maximum and minimum luma values of consecutive frames.
If someone knows a better algorithm that is not too complicated to implement, let me know.
T. Anschütz is offline   Reply With Quote
Old 6th October 2007, 08:48   #14  |  Link
plane
Registered User
 
Join Date: Aug 2006
Location: Hong Kong
Posts: 44
The link seems dead?
plane is offline   Reply With Quote
Old 7th October 2007, 17:18   #15  |  Link
T. Anschütz
Registered User
 
Join Date: May 2007
Posts: 7
You are right, ZendURL is having problems. This link works for me:

http://www.zendurl.com/t/ta41/autolevels_en.php
T. Anschütz is offline   Reply With Quote
Old 25th October 2007, 01:46   #16  |  Link
thymej
Registered User
 
Join Date: Oct 2007
Posts: 26
Sorry thanks
thymej is offline   Reply With Quote
Old 26th October 2007, 01:03   #17  |  Link
superuser
Registered User
 
Join Date: Sep 2006
Posts: 84
thanks for the filter, will try it out.
superuser is offline   Reply With Quote
Old 29th October 2007, 06:58   #18  |  Link
superuser
Registered User
 
Join Date: Sep 2006
Posts: 84
thanks T. Anschütz for the filter. works gr8. If possible can you spin out a version say simple levels and provide more control to the user by input paramaters for the filters such as:

- gain to be achieved
- control for color control, if any, in luma and chroma plains (sorry this too much but thought may be will ask )

even in its native form filter is cool. thnxs again.
superuser is offline   Reply With Quote
Old 13th January 2008, 17:58   #19  |  Link
AlanHK
Registered User
 
Join Date: May 2006
Posts: 237
Quote:
Originally Posted by T. Anschütz View Post
You are right, ZendURL is having problems. This link works for me:

http://www.zendurl.com/t/ta41/autolevels_en.php
I can't get this filter to work.

If I try to load the dll
LoadPlugin("p:\autolevels.dll")
I get an error message with some gibberish, as below.

I'm using Avisynth 2.57 on Win2k.

Also I note that the web page mentioned above has some problems, as the angle brackets used to indicate frame ranges are interpreted as HTML and thus invisible.
Attached Images
 
AlanHK is offline   Reply With Quote
Old 11th May 2008, 20:34   #20  |  Link
unskinnyboy
Registered User
 
unskinnyboy's Avatar
 
Join Date: Feb 2004
Location: NTSC R1
Posts: 2,046
Does anyone have a working version of the latest version of Autolevels? If so, can they upload it somewhere, please? The previous URL is dead, and this don't seem to be hosted anywhere else.
__________________
unskinnyboy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.