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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 3rd May 2019, 03:29   #1  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Transparent overlay on VapourSynth?

I am using vsutils.py to try to overlay a sequence of transparent-background PNG visual effects on top of an opaque PNG logo screen:
Code:
from vapoursynth import core
import vsutils as vsu
import functools
import sys
vsufuncs = vsu.vsutils()

# Background logo
# 24-bit RGB (RGB888); using most recent version of FFMS2 to open PNG image
rawlogo = core.ffms2.Source(r'logo.png')
rawlogoframe = rawlogo.std.AssumeFPS(fpsnum=60000,fpsden=1001)
blackframe = rawlogoframe.std.BlankClip()
blackframeseq1 = blackframe*150
rawlogoseq = rawlogoframe*339
blackframeseq2 = blackframe*20
fadeinlogo = vsufuncs.FadeIn(rawlogoseq,1.685)
fadeoutlogo = vsufuncs.FadeOut(fadeinlogo,0.25)
logo = blackframeseq1+fadeoutlogo+blackframeseq2

# Overlaid VFX; 32-bit RGB+alpha (ARGB8888)
vfx00 = core.ffms2.Source(r'VFX__000.PNG')*118
vfx01 = core.ffms2.Source(r'VFX__118.PNG')*8
vfx02 = core.ffms2.Source(r'VFX__126.PNG')*18
vfx03 = core.ffms2.Source(r'VFX__144.PNG')*2
vfx04 = core.ffms2.Source(r'VFX__146.PNG')*2
vfx05 = core.ffms2.Source(r'VFX__148.PNG')*2
vfx06 = core.ffms2.Source(r'VFX__150.PNG')*2
vfx07 = core.ffms2.Source(r'VFX__152.PNG')*2
vfx08 = core.ffms2.Source(r'VFX__154.PNG')*2
vfx09 = core.ffms2.Source(r'VFX__156.PNG')*2
vfx10 = core.ffms2.Source(r'VFX__158.PNG')*2
vfx11 = core.ffms2.Source(r'VFX__160.PNG')*4
vfx12 = core.ffms2.Source(r'VFX__164.PNG')*2
vfx13 = core.ffms2.Source(r'VFX__166.PNG')*2
vfx14 = core.ffms2.Source(r'VFX__168.PNG')*2
vfx15 = core.ffms2.Source(r'VFX__170.PNG')*2
vfx16 = core.ffms2.Source(r'VFX__172.PNG')*2
vfx17 = core.ffms2.Source(r'VFX__174.PNG')*2
vfx18 = core.ffms2.Source(r'VFX__176.PNG')*2
vfx19 = core.ffms2.Source(r'VFX__178.PNG')*2
vfx20 = core.ffms2.Source(r'VFX__180.PNG')*2
vfx21 = core.ffms2.Source(r'VFX__182.PNG')*2
vfx22 = core.ffms2.Source(r'VFX__184.PNG')*2
vfx23 = core.ffms2.Source(r'VFX__186.PNG')*2
vfx24 = core.ffms2.Source(r'VFX__188.PNG')*2
vfx25 = core.ffms2.Source(r'VFX__190.PNG')*2
vfx26 = core.ffms2.Source(r'VFX__192.PNG')*4
vfx27 = core.ffms2.Source(r'VFX__196.PNG')*2
vfx28 = core.ffms2.Source(r'VFX__198.PNG')*2
vfx29 = core.ffms2.Source(r'VFX__200.PNG')*2
vfx30 = core.ffms2.Source(r'VFX__202.PNG')*2
vfx31 = core.ffms2.Source(r'VFX__204.PNG')*2
vfx32 = core.ffms2.Source(r'VFX__206.PNG')*3
vfx33 = core.ffms2.Source(r'VFX__210.PNG')*2
vfx34 = core.ffms2.Source(r'VFX__211.PNG')*2
vfx35 = core.ffms2.Source(r'VFX__213.PNG')*2
vfx36 = core.ffms2.Source(r'VFX__215.PNG')*4
vfx37 = core.ffms2.Source(r'VFX__219.PNG')*2
vfx38 = core.ffms2.Source(r'VFX__221.PNG')*4
vfx39 = core.ffms2.Source(r'VFX__225.PNG')*2
vfx40 = core.ffms2.Source(r'VFX__227.PNG')*2
vfx41 = core.ffms2.Source(r'VFX__229.PNG')*2
vfx42 = core.ffms2.Source(r'VFX__231.PNG')*2
vfx43 = core.ffms2.Source(r'VFX__233.PNG')*4
vfx44 = core.ffms2.Source(r'VFX__237.PNG')*2
vfx45 = core.ffms2.Source(r'VFX__239.PNG')*2
vfx46 = core.ffms2.Source(r'VFX__242.PNG')*2
vfx47 = core.ffms2.Source(r'VFX__243.PNG')*2
vfx48 = core.ffms2.Source(r'VFX__245.PNG')*2
vfx49 = core.ffms2.Source(r'VFX__247.PNG')*4
vfx50 = core.ffms2.Source(r'VFX__251.PNG')*2
vfx51 = core.ffms2.Source(r'VFX__253.PNG')*2
vfx52 = core.ffms2.Source(r'VFX__255.PNG')*2
vfx53 = core.ffms2.Source(r'VFX__257.PNG')*2
vfx54 = core.ffms2.Source(r'VFX__259.PNG')*2
vfx55 = core.ffms2.Source(r'VFX__261.PNG')*2
vfx56 = core.ffms2.Source(r'VFX__263.PNG')*4
vfx57 = core.ffms2.Source(r'VFX__267.PNG')*2
vfx58 = core.ffms2.Source(r'VFX__269.PNG')*2
vfx59 = core.ffms2.Source(r'VFX__271.PNG')*2
vfx60 = core.ffms2.Source(r'VFX__273.PNG')*2
vfx61 = core.ffms2.Source(r'VFX__275.PNG')*2
vfx62 = core.ffms2.Source(r'VFX__277.PNG')*2
vfx63 = core.ffms2.Source(r'VFX__279.PNG')*4
vfx64 = core.ffms2.Source(r'VFX__283.PNG')*4
vfx65 = core.ffms2.Source(r'VFX__287.PNG')*2
vfx66 = core.ffms2.Source(r'VFX__289.PNG')*2
vfx67 = core.ffms2.Source(r'VFX__291.PNG')*2
vfx68 = core.ffms2.Source(r'VFX__293.PNG')*2
vfx69 = core.ffms2.Source(r'VFX__295.PNG')*2
vfx70 = core.ffms2.Source(r'VFX__297.PNG')*2
vfx71 = core.ffms2.Source(r'VFX__299.PNG')*3
vfx72 = core.ffms2.Source(r'VFX__302.PNG')*3
vfx73 = core.ffms2.Source(r'VFX__305.PNG')*2
vfx74 = core.ffms2.Source(r'VFX__307.PNG')*3
vfx75 = core.ffms2.Source(r'VFX__310.PNG')*2
vfx76 = core.ffms2.Source(r'VFX__312.PNG')*2
vfx77 = core.ffms2.Source(r'VFX__314.PNG')*2
vfx78 = core.ffms2.Source(r'VFX__316.PNG')*2
vfx79 = core.ffms2.Source(r'VFX__318.PNG')*4
vfx80 = core.ffms2.Source(r'VFX__322.PNG')*2
vfx81 = core.ffms2.Source(r'VFX__324.PNG')*2
vfx82 = core.ffms2.Source(r'VFX__326.PNG')*4
vfx83 = core.ffms2.Source(r'VFX__330.PNG')*2
vfx84 = core.ffms2.Source(r'VFX__332.PNG')*2
vfx85 = core.ffms2.Source(r'VFX__334.PNG')*4
vfx86 = core.ffms2.Source(r'VFX__338.PNG')*2
vfx87 = core.ffms2.Source(r'VFX__000.PNG')*169
vfxseq = vfx00+vfx01+vfx02+vfx03+vfx04+vfx05+vfx06+vfx07+vfx08+vfx09+ \
	 vfx10+vfx11+vfx12+vfx13+vfx14+vfx15+vfx16+vfx17+vfx18+vfx19+ \
	 vfx20+vfx21+vfx22+vfx23+vfx24+vfx25+vfx26+vfx27+vfx28+vfx29+ \
	 vfx30+vfx31+vfx32+vfx33+vfx34+vfx35+vfx36+vfx37+vfx38+vfx39+ \
	 vfx40+vfx41+vfx42+vfx43+vfx44+vfx45+vfx46+vfx47+vfx48+vfx49+ \
	 vfx50+vfx51+vfx52+vfx53+vfx54+vfx55+vfx56+vfx57+vfx58+vfx59+ \
	 vfx60+vfx61+vfx62+vfx63+vfx64+vfx65+vfx66+vfx67+vfx68+vfx69+ \
	 vfx70+vfx71+vfx72+vfx73+vfx74+vfx75+vfx76+vfx77+vfx78+vfx79+ \
	 vfx80+vfx81+vfx82+vfx83+vfx84+vfx85+vfx86+vfx87
vfx = vfxseq.std.AssumeFPS(fpsnum=60000,fpsden=1001)

# Overlay VFX on top of background logo
finallogo = vsufuncs.Overlay(logo,vfx,0,0)

finallogo.set_output()
But rather than seeing the logo behind the VFX, I only see the VFX alone, as if the VFX’s transparent background were converted to black.

Any insights on this? Maybe shall I use raw code rather than Overlay() and extract different mask data for the VFX overlay?
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 03:50   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
I don't know about vsutils' Overlay , but havsfunc's Overlay works like this (basically the same as avisynth's Overlay):

Overlay using transparency requires you to specify the alpha channel mask

But in vapoursynth for RGBA , the [0] is for the RGB channels , [1] is for the alpha (different than avisynth)

Overlay order is the base layer first , then the overlay on top ie. overlay(base, top) .

Code:
.
.
.
import havsfunc as haf
.
.
.

final = haf.Overlay( logo, vfx[0], mask=vfx[1])

final.set_output()

Last edited by poisondeathray; 3rd May 2019 at 03:58.
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:00   #3  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
I don't know about vsutils' Overlay , but havsfunc's Overlay works like this (basically the same as avisynth's Overlay):

Overlay using transparency requires you to specify the alpha channel mask

But in vapoursynth for RGBA , the [0] is for the RGB channels , [1] is for the alpha (different than avisynth)

Overlay order is the base layer first , then the overlay on top ie. overlay(base, top) .
I tried this other Overlay with your suggestion and still I get the same result: the VFX’s transparent background turning into black and completely hiding the logo behind it. Is there something I am missing (like changing the assumed colorspace)?
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:02   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
This works on standard RGBA and RGB images or video (8bit)

It might be an alpha interpretation issue for you

Can you see the alpha channel when you return [1] ? It should be black/white

This should show the alpha
vfx[1].set_output()

This should show the RGB as what you see normally, but without transparency (black where transparent should be)
vfx[0].set_output()



Upload 1 image of each, logo.png, and VFX__118.PNG (or choose one that you can see something)

Last edited by poisondeathray; 3rd May 2019 at 04:06.
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:06   #5  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
This works on standard RGBA and RGB images or video (8bit)

It might be an alpha interpretation issue for you

Upload 1 image of each, logo.png, and VFX__118.PNG (or choose one that you can see something)
Done. As a side note, after you edited your reply and reversed the order, I got instead the logo but no VFX showing up
Attached Images
  
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:08   #6  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by SilSinn9801 View Post
Done. As a side note, after you edited your reply and reversed the order, I got instead the logo but no VFX showing up
Upload it somewhere else , such as zippyshare.com, mediafire.com . Attachments can take long time to get approved

(Yes , I got the wrong order first, because usually "logo" is on top,like you know...a logo... but you're actually using it as the background)

Check my edit above with viewing the alpha channel directly
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:11   #7  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
Upload it somewhere else , such as zippyshare.com, mediafire.com . Attachments can take long time to get approved

(Yes , I got the wrong order first, because usually "logo" is on top,like you know...a logo... but you're actually using it as the background)

Check my edit above with viewing the alpha channel directly
Is Google Drive acceptable?

Also, trying vfx[1].set_output() got me a single solid-black frame (rather than a sequence of frames). Trying vfx[0].set_output() also got me a single solid-black frame.
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:13   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by SilSinn9801 View Post
Is Google Drive acceptable?

Also, trying vfx[1].set_output() got me a single solid-black frame (rather than a sequence of frames). Trying vfx[0].set_output() also got me a single solid-black frame.
Yes google drive is ok

This means you don't have a valid alpha channel. Perhaps that version of ffms2 isn't reading it correctly
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:15   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
For example, newer ffms2 versions do not read the alpha correctly in PNG or MOV
eg. ffms2-20190326 from WolfBerry does not work here on my local test with different images

But really old versions work, such as ffms2-2.23-clang , or ImageMagick for PNG RGBA sequences
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:16   #10  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
Yes google drive is ok

This means you don't have a valid alpha channel. Perhaps that version of ffms2 isn't reading it correctly
Here you go:
https://drive.google.com/open?id=1m_...0Kdx1a6MAjOXCI
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:19   #11  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
For example, newer ffms2 versions do not read the alpha correctly in PNG or MOV
eg. ffms2-20190326 from WolfBerry does not work here on my local test with different images

But really old versions work, such as ffms2-2.23-clang , or ImageMagick for PNG RGBA sequences
Older versions of FFMS2 don't work with me because they cannot open PNG files (as per an older thread of mine: https://forum.doom9.org/showthread.php?t=176223 ). And ImageMagick does not work with international filepaths.
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:24   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Works ok with old ffms2 (ffms2-2.23-clang)

Code:
vfx = core.ffms2.Source(r'VFX__172.PNG')
logo = core.ffms2.Source(r'Logo.png')

o = haf.Overlay(logo[0], vfx[0], mask=vfx[1])
o.set_output()

(This is why I keep like 20 ffms2 versions around)
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:31   #13  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
Works ok with old ffms2 (ffms2-2.23-clang)

Code:
vfx = core.ffms2.Source(r'VFX__172.PNG')
logo = core.ffms2.Source(r'Logo.png')

o = haf.Overlay(logo[0], vfx[0], mask=vfx[1])
o.set_output()
Do you have a link to that old ffms2? The latest ffms2 version just posted by Wolfberry crashes my VirtualDub2 x64.
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:43   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Each version has various quirks. About 19 other ffms2 versions don't work correctly with PNG or MOV RGBA

I can't find the original github release from way back . Looks like it was taken down and replaced with ffms2-2.23.1-msvc (which doesn't work here either) . But it might mean there are other issues with that build
https://github.com/FFMS/ffms2/releases

Lucky for you I have them saved on a HDD somewhere for exactly these scenarios
https://www.mediafire.com/file/ug0mq...-clang.7z/file
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 04:51   #15  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
I am trying that old ffms2 and now I get some errors:
Quote:
Avisynth open failure:
Python exception: 'list' object has no attribute 'std'

Traceback (most recent call last):
File "src\cython\vapoursynth.pyx", line 1927, in vapoursynth.vpy_evaluateScript
File "src\cython\vapoursynth.pyx", line 1928, in vapoursynth.vpy_evaluateScript
File "C:\(fakepath)\Script.vpy", line 11, in <module>
rawlogoframe = rawlogo.std.AssumeFPS(fpsnum=60000,fpsden=1001)
AttributeError: 'list' object has no attribute 'std'
What do I do?
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 04:54   #16  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by SilSinn9801 View Post
I am trying that old ffms2 and now I get some errors:

Avisynth open failure:
Python exception: 'list' object has no attribute 'std'

Traceback (most recent call last):
File "src\cython\vapoursynth.pyx", line 1927, in vapoursynth.vpy_evaluateScript
File "src\cython\vapoursynth.pyx", line 1928, in vapoursynth.vpy_evaluateScript
File "C:\(fakepath)\Script.vpy", line 11, in <module>
rawlogoframe = rawlogo.std.AssumeFPS(fpsnum=60000,fpsden=1001)
AttributeError: 'list' object has no attribute 'std'

What do I do?

try core.std.AssumeFPS

eg.
rawlogoframe = core.std.AssumeFPS(rawlogo, fpsnum=60000,fpsden=1001)


Did you try the 2 test image simple script above first ? Does it look like what you expect ?
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 05:04   #17  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by poisondeathray View Post
try core.std.AssumeFPS

eg.
rawlogoframe = core.std.AssumeFPS(rawlogo, fpsnum=60000,fpsden=1001)
I now get this new error:
Quote:
Avisynth open failure:
Python exception: AssumeFPS: argument clip is not of array type but more than one value was supplied

Traceback (most recent call last):
File "src\cython\vapoursynth.pyx", line 1927, in vapoursynth.vpy_evaluateScript
File "src\cython\vapoursynth.pyx", line 1928, in vapoursynth.vpy_evaluateScript
File "C:\(fakepath)\Script.vpy", line 11, in <module>
rawlogoframe = core.std.AssumeFPS(rawlogo,fpsnum=60000,fpsden=1001)
File "src\cython\vapoursynth.pyx", line 1833, in vapoursynth.Function.__call__
vapoursynth.Error: AssumeFPS: argument clip is not of array type but more than one value was supplied
I also get this error with the Wolfberry version with the alpha=TRUE edit by HolyWu.

Quote:
Originally Posted by poisondeathray View Post
Did you try the 2 test image simple script above first ? Does it look like what you expect ?
The two-test script worked fine, with vfx[0] giving me the normal image and vfx[1] giving me the alpha represented as black.

Last edited by SilSinn9801; 3rd May 2019 at 05:16. Reason: I get the same error even with the alpha=TRUE edit on Wolfberry version (re: HolyWu)
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 05:06   #18  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by HolyWu View Post
Also works ok with the latest ffms2 here, albeit you need to specify the alpha argument.
Code:
logo = core.ffms2.Source(r'Logo.png')
vfx = core.ffms2.Source(r'VFX__172.PNG', alpha=True)
clip = haf.Overlay(logo, vfx[0], mask=vfx[1])
Nice.

Confirmed for ffms2-20190326 from WolfBerry (not sure if it's the "newest")
poisondeathray is offline   Reply With Quote
Old 3rd May 2019, 05:06   #19  |  Link
SilSinn9801
Chiptuner & VapourSynther
 
SilSinn9801's Avatar
 
Join Date: Mar 2019
Location: Scarlet Devil Mansion, Gensōkyō
Posts: 52
Quote:
Originally Posted by HolyWu View Post
Also works ok with the latest ffms2 here, albeit you need to specify the alpha argument.
Code:
logo = core.ffms2.Source(r'Logo.png')
vfx = core.ffms2.Source(r'VFX__172.PNG', alpha=True)
clip = haf.Overlay(logo, vfx[0], mask=vfx[1])
Which of the Wolfberry versions, the one released on March 23 or 26, or the one released now on April 27? Because the April release is crashing my VirtualBox2 setup; the March release ran fine for me.
SilSinn9801 is offline   Reply With Quote
Old 3rd May 2019, 05:11   #20  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by SilSinn9801 View Post
The two-test script worked fine, with vfx[0] giving me the normal image and vfx[1] giving me the alpha represented as black.
vfx[1] should be black and white

Quote:
I now get this new error:
If you're loading as an array of RGB + alpha, you need to specify if it's using [0] or [1] . Those newer versions require alpha = True to load the alpha. So just omit that for the RGB background

If you're loading both (it will be a "dummy" alpha) . Since you want the RGB background, it should be [0]

rawlogoframe = core.std.AssumeFPS(rawlogo[0],fpsnum=60000,fpsden=1001)
poisondeathray is offline   Reply With Quote
Reply

Tags
overlay, transparency, transparent, vapoursynth, vsutils

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 15:16.


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