PNG Overlay on top of embeddedvideoplayer? [VLCJ]

This forum is about all development around libVLC.
Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

PNG Overlay on top of embeddedvideoplayer? [VLCJ]

Postby Tyeo098 » 21 Jul 2011 15:55

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

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

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

Postby Rémi Denis-Courmont » 21 Jul 2011 16:18

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 21 Jul 2011 16:21

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.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

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

Postby sherington » 21 Jul 2011 17:34

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.

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 21 Jul 2011 18:49

So what youre saying is I'm screwed on this?

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

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

Postby sherington » 21 Jul 2011 21:14

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.

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 21 Jul 2011 23:00

That thread is about custom graphics. I just want to display an Image in transparent PNG format.
Im playing with setOverlay() now.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

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

Postby sherington » 21 Jul 2011 23:20

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.

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 25 Jul 2011 20:37

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) {} } }

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

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

Postby sherington » 25 Jul 2011 22:43

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?

shashaanktulsyan
New Cone
New Cone
Posts: 8
Joined: 10 Oct 2007 20:19
VLC version: 1.2
Operating System: Win7/KUbuntu/Mac10.5

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

Postby shashaanktulsyan » 26 Jul 2011 14:05

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.

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 26 Jul 2011 15:42

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.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

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

Postby sherington » 26 Jul 2011 17:29

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.)

Tyeo098
Blank Cone
Blank Cone
Posts: 14
Joined: 21 Jul 2011 15:50

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

Postby Tyeo098 » 26 Jul 2011 18:24

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 7 guests