Static background processor
A VirtualDub filter
by Krzysztof Wojdon, 2004
|Table of Contents||
1. WTF? (Why this filter?)
3. Configuration dialog box.
4. Short tutorial.
5. Script format definition.
6. Good things to come (but not yet, not yet).
8. Author and usual yadayada.
|1. WTF? (why this filter?)|
During my last project I had to change a lot of backgrounds in animations. However, I had no access to original projects with layered graphics, so changing backgrounds meant precise manual painting in background areas of the video (because objects moving in front of background cannot be affected). For example: I had a group of animated characters with waving baloons in the wind and all of it in front of "Happy Birthday" poster that I had to change. Painting a few dozens of frames with a new sentence in place of "Happy Birthday" (with care for all ballons, baloon's strings and moving characters) could make interesting entry in my CV, but definitely would seriously impact my brain cells.
Nevertheless, for the first (simplest) animation I used classic "convert to frames and repaint each frame" method. One hour later it became clear that I was not going to finish all the animations before deadline. Things get worse when a few minutes later I realised that I used a slightly too dark green and animation did not match rest of the game. So I had to... repaint all frames. It was only 40 or 50 frames of simple animation, but that was enough. By that time I was sure that I needed some kind of process automatisation. And I wrote this filter.
One picture stands for 1024 words, as programmers say, so here we go. Imagine changing both texts in animation like this:
But believe me, getting result like this:
*If you want to see above animation in full size, you have both of them in tutorial folder.
PESIMIST'S NOTE: Unfortunately this program does not make miracles like eg. automatical reconstruction of the background (I wish it did!). You have to do it manually from the original frames, using uncovered parts of the background in different frames (just like you would with classical frame-by-frame painting). Good side is that with this filter you paint once, not for each and every frame.
Please note, that though name of the filter implies that you can change only background, it is also true that you can change any part of the image. Program does not differentiate between planes in any mystical way, so any part of video that is identical to the compare pattern (ie. old background) will be replaced. So when you put foreground in the background pattern image, you will change also this part of the video.
As long as possible all my filters (and this one) will be kept at http://www.vander.prv.pl and this address will provide you with current builds. This .prv.pl domain is also quite useful, because it links dynamically to my current site, that can occasionaly move from one host to another. So if you want to link to my site, please use http://www.vander.prv.pl and not host address (like republika, onet, etc.).
|3. Configuration dialog box|
All filter parameteres are changed from the script file. There is only one option that can be changed from filter configuration window:
|4. Short tutorial|
Let's assume that you have filter installed (if not - install this filter by copying file StatBgProc.vdf into plugins folder of VirtualDub and restart VirtualDub. You should also have following files in the tutorial folder:
In this short tutorial I also assume that you are familiar with VirtualDub and general methods of image retouch and editing. If you do not know how to use clone tools or gradients to repaint images, you probably do not have to use this filter.
|5. Script format definition|
This filter is configured by the scripts. Script file is a text file in which user defines all the filter parameters. It is most versatile system and is most convenient (at least for me ;) ) when one is working with many parameters changing over time. But do not worry - script format is very simple. There is an example script in the tutorial folder - tut_script.txt. Please take a look at it, probably you will not have to read this paragraph when you see example script.
HINT: When you need a new script, do not write it from scratch. Use some other script (or tut_script.txt) as a template.
All empty lines and lines beggining with ';' character (comment lines) are skipped. Script is built from sections, section is called RANGE, because defines parameters for given frame range. Each range consist few lines of "KEYWORD=VALUE" syntax. Range definition ends with a "---" line. Each range describes (works on) frame range (from frame A to frame B) and filter parameters for all frames that are in this range. Below comes example of ONE range definition. This definition consists all possible keywords. There are only three keywords that are required in range definition: Frames, BGFile and BGFileNew are required, all other are optional.Example of range definition:
Frames = 0-6
Frames - defines frame range (start-end) for which following parameters are valid. This parameter must be declared in range definition.
BGFile - defines filename of original background file. Frame pixels identical to pixels from this image will be replaced. This file must be saved as uncompressed 24-bit Targa (TGA) file. This parameter must be declared in range definition. File path is relative to the script path. Eg. when script file is "c:\anim1\demo\script.txt", then image "bg\new1.tga" points to file "c:\anim1\demo\bg\new1.tga".
BGFileNew - filename of new (replacement) background. Path is relative to the script path. Pixels from this image will be put in place of old background. This file must be saved as uncompressed 24-bit Targa (TGA) file. This parameter must be declared in range definition.
KeyColor - RGB color definition of the color which will be painted, when key coloring mode is enabled in filter configuration. This parameter is optional; default key color is RGB = FF00FF.
Rect - Defines coordinates of the processing rectangle. Can be useful for speeding up operation, when only specified small parts of the video will be changed or when somebody does not want to reconstruct whole background. Coordinates are defined as: first pair is X,Y of top-left corner, and second pair is X,Y of bottom-right rectangle corner. This parameter is optional; default range is full frame. In tutorial animation, last part of animation is rendered with defined rectangle, so there is only small part of the background changed (see movie titles in the middle of the frame).
Threshold - Maximum difference below all pixel RGB comparisons are considered "these pixels are the same". This value is used during comparison between RGB of background and video pixels. We need this one, because in video processing signal is almost never stored with 100% precision (beside really small number of REALLY loseless compressors). So comparison would miss many pixels when comparing in strict arithmetical meaning. Setting this value too low will result in skipping pixels of the background that should be changed; going too high will start to paint over foreground layer. This parameter is optional; default threshold is 0.
|6. Things to do|
Currently there is one feature I would like to add.
Supplied bitmaps are verified if its size complies with video size.
This is first initial release. This filter was successfully used in real life project and whole filter idea worked well for me. The implementation may be slow (simple algorithm, no optimisations). This build may still have bugs, because some parts were added and/or fixed after project was finished (and as a result - those features are not tested).
|8. Author and yada yada|
This program was entirely written by Krzysztof Wojdon (that's me, yoohoo!) and all copyrights remain in ownership of the author (yes, that's also me). This program is freeware and can be used for all (non-commercial and commercial) purposes. The filter is given AS IS. Author does not guarantee that this program fits users purposes or works as expected (eg. sometimes it could look like space flight simulator, you never know). Also I do not take resposibility for your computer, hard drive, girlfriend, dog and cat if something goes wrong. However, I cannot see how this program could do anything like this. Side note: I also think this kind of disclaimers suck and mean anything only to lawyers (and I'd prefer not meet any in this life). Use common sense and make this world a better place.
As usual, BIG CREDITS go to Avery Lee for his excellent utility: VirtualDub.