Log in

View Full Version : premultiply (alpha channel) for avisynth ?


poisondeathray
29th December 2017, 18:28
Is there an avisynth equivalent of premultiply ? I can find an unpremultiply plugin

Background: certain programs might not have the ability to interpret certain types of alpha channel or premultiply on the fly - in those cases you can apply the filter externally

eg . ffmpeg has it
https://ffmpeg.org/ffmpeg-filters.html#premultiply

eg. vapoursynth has it
http://www.vapoursynth.com/doc/functions/premultiply.html

Both work in my tests

wonkey_monkey
29th December 2017, 19:52
I think you can use Layer onto a blankclip (might have to merge the alpha back in afterwards).

poisondeathray
29th December 2017, 20:14
I think you can use Layer onto a blankclip (might have to merge the alpha back in afterwards).


Thanks David.

I tried some layer() combos, op="mul" , etc..., no luck and my google and avisynth kung fu isn't that great . I think I'm missing something simple


Perhaps a test example - Here is simple animation exported from aviutl (lagarith, RGBA, 3.2MB)
http://www.mediafire.com/file/9pjqh87a9stt9sq/aviutl.avi

Programs like vdub, avspmod , a handful of others may interpret the alpha channel incorrectly, as a result you get "ratty", aliased edges. There are no other export options for the alpha in aviutl

On import, other programs like AE can interpret with premultipled black, or ffmpeg or vapoursynth can apply the premultiply so it can be interpreted correctly and look correct

eg.
ffmpeg premultiply

ffmpeg -i aviutl.avi -vf premultiply=inplace=1 -an -c:v png ffmpeg_premultiply_png.mov


vpy premultiply

import vapoursynth as vs
core = vs.get_core()
video = core.avisource.AVISource(r'F:\aviutl.avi', alpha=True)
p = core.std.PreMultiply(video[0], video[1])
p.set_output()

wonkey_monkey
29th December 2017, 20:24
avisource("aviutl.avi")

layer(blankclip(last),last,op="add")

Looks like it preserves alpha.

poisondeathray
29th December 2017, 20:27
^ ahhh it's "add". Yes it works . Thanks