Page 1 of 1

PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 15:55
by Tyeo098
The PNG is transparent over the space where a video isnt bing played, but when I translate the image over an active video, the transparent background turns white.
I'm using a JLabel with an Imageicon to create the image component, and vlcJ to initialize the video.

Any ideas? Should I use something else to create the image?


Here is a screenshot of what is happening.
Image

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 16:18
by RĂ©mi Denis-Courmont
I would disable the video overlay, but it will burn a lot more CPU cycles. Better option would be to use the OpenGL video output, but it requires good drivers.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 16:21
by Tyeo098
Thanks for the reply, I'm not sure what you mean by disable the overlay?
You want me to turn off the image? But I need it there!

Also, how would I go about switching to OpenGL?

Sorry, I'm still new to this.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 17:34
by sherington
I don't know about the OpenGL suggestion, but to answer your original post: for some explanation as to why it doesn't work like you expect in Java...

http://today.java.net/article/2009/11/0 ... components
http://java.sun.com/developer/technical ... index.html

Even if you follow what's in those links, you won't be able to use per-pixel translucency or anti-aliasing.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 18:49
by Tyeo098
So what youre saying is I'm screwed on this?

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 21:14
by sherington
So what youre saying is I'm screwed on this?
Only you know whether you're screwed or not.

Your best option is probably to look at embeddedMediaPlayer.setOverlay(). This is the solution I use. But make sure you understand the limitations of it as it is not a perfect solution. There's a long thread on this subject on the vlcj google group - search there for "per-pixel translucency" for more information.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 23:00
by Tyeo098
That thread is about custom graphics. I just want to display an Image in transparent PNG format.
Im playing with setOverlay() now.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 21 Jul 2011 23:20
by sherington
That thread is about custom graphics. I just want to display an Image in transparent PNG format.
Im playing with setOverlay() now.
I know what that thread is about thanks, I wrote half of it. You can use custom graphics to paint your transparent PNG and even blend it with the video if you use the approach described in that thread, you know about graphics.drawImage() right?. You can even add your JLabel with your icon to the overlay Window that is described in that thread, and it will be properly transparent.

Or if like you say you just want to display an image, maybe the the logo functionality exposed by libvlc and wrapped by vlcj is all you need:

Code: Select all

mediaPlayer.setLogoFile("mylogo.png"); mediaPlayer.setLogoOpacity(25); mediaPlayer.setLogoLocation(10, 10); mediaPlayer.enableLogo(true);
Logo seems to work well with vlc 1.1.x, but I've seen problems with it on vlc 1.2-git.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 25 Jul 2011 20:37
by Tyeo098
Ok, I solved the transparency overlay problem. I used a separate overlay window, that was untied from the media player.

But now I'm having trouble with too much transparency! The images should be solid, not transparent like this... The "banner" on the opposite side is a static JPG image made from an imageicon.

See attached image. Thanks guys for all your help!

Image

Heres the relevant code...

Code: Select all

public class Overlay extends Window { private String overlayFile; private static final long serialVersionUID = 1L; public Overlay(Window owner, String o) { super(owner, WindowUtils.getAlphaCompatibleGraphicsConfiguration()); setLayout(null); overlayFile = o; } public void paint(Graphics g) { super.paint(g); try {g.drawImage(ImageIO.read(new File(overlayFile)), 0, 0, null);} catch (IOException e) {} } }

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 25 Jul 2011 22:43
by sherington
Are you using jpeg for your "too much transparency" image? jpeg doesn't support transparency and it goes a bit weird when you paint one in a transparent window, as you've seen.

I just tried painting a partially transparent PNG image to my own overlay and it worked just fine.

You also know you shouldn't be using ImageIO inside that paint method?

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 26 Jul 2011 14:05
by shashaanktulsyan
Even if you follow what's in those links, you won't be able to use per-pixel translucency or anti-aliasing.
Java 6 supports per pixel translucency in private com.sun.awt.AWTUtilities class ; unfortunately this doesn't seem to work only on windows.
Java 7, which is going to be released in a few days, supports this.
http://download.oracle.com/javase/tutor ... ndows.html

I am sorry but I'm not sure if this was helpful.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 26 Jul 2011 15:42
by Tyeo098
Sherrington-

No, I had gimp output me a PNG file.

I had changed it to a GIF file for shits and giggles, because GIF also supports the alpha layer, and it works!

But the GIF color palette is kind of... limited.

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 26 Jul 2011 17:29
by sherington
Hmm... PNGs should work. I also used gimp to create a PNG and it was fine for me. It depends exactly on what you're trying to achieve - if you just have a transparent background with your PNG it should work, but if your image contains translucent pixels then of course the video will show through those pixels to some degree and look a bit like your screenshot.

I guess by changing your image to a GIF, you basically got only one transparent colour and every other colour in the palette was made fully opaque.

(I'm not an image expert so I'm just supposing.)

Re: PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Posted: 26 Jul 2011 18:24
by Tyeo098
Its odd with the PNGs, but you're right about the GIFs. I tried to do a gradient to transparent, and it ended up cut off.

Ill try playing with the export settings for the PNGs.