Author Topic: [script] apply partial filters based on [A B] markers  (Read 644 times)

p3trus

  • Newbie
  • *
  • Posts: 36
[script] apply partial filters based on [A B] markers
« on: April 26, 2017, 03:02:06 PM »
Hi there,

I coded a tiny script to help you adding partial filters; just set up the range where the filter should be applied with the [A & B] markers and run the script.
(Please note that B is is inclusive contrary to ADMs normal behaviour!)



Standard behaviour is to reset the markers afterwards (ie whole video selected again), but you can untick that checkbox (or change the code if you never want it)

Right now, only my four 'favorites' are included: Fade in/ out from/ to black, Replace by solid black & DeLogo as a partial filter.
But you can add any other (which ADM allows to be partial) yourself, see inline comments; or ask me to add it ;)

Attention! Due to a bug in ADM use the script only once per session, otherwise ADM will crash.
If you need it a second time, either on the same video or a new one, you have to close & restart ADM (save your work in progress project script first, if needed).
I hope the bug will get extinguished soon ^^

Code: [Select]
#PY
# adds partial filters based on [A B] markers


# basic setup
adm=Avidemux()
gui=Gui()

# helper function to forge the comand to add a filter
def add_filter(f, a, b):
    c = filters[f]
    out = [c['name'],
           c['a'] + '=' + str(a),
           c['b'] + '=' + str(b)
    ]
    out.extend(c['opt'])
    adm.addVideoFilter(*out)

# get marker positions (typecast since // seems broken)
ts_a = int(adm.markerA / 1000)
ts_b = int(adm.markerB / 1000)

# since I wanted to have a custom area as preset for the delogo filter (1/3 of video dimensions)
# I set up those options separately
delogo_opt = ["filterName=mpdelogo2",
    "xoff=0", "yoff=0",
    "lw=" + str(int(adm.getWidth() / 3)),
    "lh=" + str(int(adm.getHeight() / 3)),
    "band=4", "show=False"
]

### filter list - extend to your needs ###
#       desc:   shows up in the menu
#       name:   the actual filter name
#       a, b:   parameter names for start and end frames
#       opt:    additional parameters for the filter
#  >>   take the values from a saved project with your desired filter

filters = [
    {'desc': 'Fade in from black', 'name': 'fadeToBlack', 'a': 'startFade', 'b': 'endFade',
    'opt': ["inOut=True", "toBlack=True"]},
   
    {'desc': 'Fade out to black', 'name': 'fadeToBlack', 'a': 'startFade', 'b': 'endFade',
    'opt': ["inOut=False", "toBlack=True"]},
   
    {'desc': 'Black', 'name': 'black', 'a': 'startBlack', 'b': 'endBlack', 'opt': []},
   
    {'desc': 'DeLogo', 'name': 'partial', 'a': 'startBlack', 'b': 'endBlack',
    'opt': delogo_opt}
]

mnu_filters = DFMenu("Filter to add:")
for filt in filters:
    mnu_filters.addItem(filt['desc'])
   
toggle_reset = DFToggle("Reset markers afterwards")
toggle_reset.value = True

dlg = DialogFactory("Partial filter helper")
dlg.addControl(mnu_filters)
dlg.addControl(toggle_reset)

res=dlg.show()
if res == 1:
    filt = mnu_filters.index
    add_filter(filt, ts_a, ts_b)
    if toggle_reset.value:
        adm.markerA = 0
        adm.markerB = Editor().getVideoDuration()

Usage: save that code as .py file (eg autopartial.py) in either
  • the custom script folder (Help > Advanced > Open Apllication Data Folder)
  • the Auto scripts folder (\plugins\autoScripts in ADM's application folder)
  • just anywhere & run it by File > Project Script > Run Project...

Please note that you can only add filters, not change an existing one, since there is no script access to the current filter list (at least I haven't found one).

If you have any problems or just find it useful, let me know! ;)

mean

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10946
Re: [script] apply partial filters based on [A B] markers
« Reply #1 on: April 27, 2017, 08:36:33 AM »
Nice!

hiro

  • Newbie
  • *
  • Posts: 21
Re: [script] apply partial filters based on [A B] markers
« Reply #2 on: October 02, 2017, 12:28:42 PM »
Hi, thanks for that interesting script

April to October 2017... / hope I'm not appending too late.


So, I happen to find it VERY useful: among other cases, I apply the script (named "autopartial.py" & pasted into "autoscripts" subfolder, as suggested) to the

Add logo (addLogo) filter,

as I've been wondering how to TITLE the few 1st seconds of videos — very simply (& in a snap!) —, using a transparent background .PNG to overlay whatever image, such as "text" etc., directly onto the video

— and BTW, like so:

once the "Add logo" filter set & ready, right click on the line (on right column: "Active filters" of the "Video Filter Manager") > select Make partial. THEN double click the line, to display the "Partial Filter" settings, in order to set start & end time stamps;

that works perfectly.



Therefore, I feel 90% happy — so far:

———— (but, to fill in the remaining 10%) Now:


would there be a way to add a "fade-in + fade-out" effect, to the overlaid .png?

More precisely: fade-in from full transparency + fade-out to full transparency.


Note: I don't mean and overall level of (alpha ch.) transparency but, again, "all" I'd like would be the very usual / classical effect: titles (images in my case) appearing + then disappearing gradually, i.e.:

say... in a 1-second fade-in, + full opacity for 2 to 4 seconds, then a 1-second fade-out.


[ ... as a previous request of mine http://avidemux.org/smif/index.php/topic,17974.0.html got no answer... ]

_________________

[EDIT]   Oops! Just noticed: the way I use it, "Make partial" is not due to "autopartial.py", I guess, but to the new "Make partial" option (announced April 2017).

Anyway, I still wonder how to add a fade-in/out effect to an overlaid image
— and tried to modify "autopartial.py"... to no avail: its dropdown list displays "Add logo" OK, but the option does not work (I'm unable to "program" anything).



« Last Edit: October 02, 2017, 12:52:19 PM by hiro »