This discussion is archived
8 Replies Latest reply: Nov 27, 2012 9:12 AM by jsmith RSS

JavaFX transparent video ( grenbox ) , possible?

915360 Newbie
Currently Being Moderated
Hello , i want to mix my gui with some video animations on adobe aftereffects.
I want to make videos transparent on some pixels and mix with my gui.

For example i put black color as transparency color key for alpha.
so on gui , black pixels on video wont be shown and completely transparent.

is it possible?

i heard about setBlend method , maybe it could be trick to do but i donno how to solve that problem.
Someone know how to do ?
  • 1. Re: JavaFX transparent video ( grenbox ) , possible?
    jsmith Guru
    Currently Being Moderated
    The BlendEffect an accomplish a chromakeyed video overlay. I don't have the exact code for it at the moment.

    http://docs.oracle.com/javafx/2/api/javafx/scene/effect/Blend.html
  • 2. Re: JavaFX transparent video ( grenbox ) , possible?
    915360 Newbie
    Currently Being Moderated
    chromakeyed video overlay ?
    i mean i want per pixel transluency for javafx videos
  • 3. Re: JavaFX transparent video ( grenbox ) , possible?
    jsmith Guru
    Currently Being Moderated
    chromakey is just the technical name for what you describe when you say:
    For example i put black color as transparency color key for alpha.
    so on gui , black pixels on video wont be shown and completely transparent.
    http://en.wikipedia.org/wiki/Chroma_key
  • 4. Re: JavaFX transparent video ( grenbox ) , possible?
    jsmith Guru
    Currently Being Moderated
    The BlendEffect an accomplish a chromakeyed video overlay. I don't have the exact code for it at the moment.
    I tried using blend effects to accomplish this and failed pretty miserably at it. I thought I would be able to use the BlendEffects to create a stencil of the video which could be used to either selectively add alpha in to the areas required or be used as a binary image mask (http://en.wikipedia.org/wiki/Image_mask#Image_masks). But the Blends did not seem to support the range of operations required to do this. Not all of the awt alpha compsiting operations are available as blend modes in JavaFX http://docs.oracle.com/javase/7/docs/api/java/awt/AlphaComposite.html.

    If the transparent area is static, then you can blend over a predefined alpha texture similar to the texture transition example here: http://www.ogre3d.org/tikiwiki/Materials#Simple_texture_transition

    I also thought perhaps the ColorAdjust effect might be able to make certain colors or portions of the video transparent or translucent by setting an alpha value for those colors, but it can't adjust alpha, nor produce an appropriate mask without alpha for bit masking.

    If your input video can be preprocessed in an external tool to include an alpha channel on the areas where you want it to be transparent, then I think it should be trivial, just play your video using the MediaPlayer and the background should show through the transparent or translucent pixels in the video.

    Note an alternate way to accomplish this would be to use something like the technique here but using a JavaFX canvas or writableimage instead of a html5 convas, then manipulating video image and pixel alpha values in offscreen buffers on a pixel by pixel basis: http://stackoverflow.com/questions/5055962/how-to-create-an-h264-video-with-an-alpha-channel-for-use-with-html5-canvas but pre-encoding the video with an alpha channel is probably best for most situations.
  • 5. Re: JavaFX transparent video ( grenbox ) , possible?
    jsmith Guru
    Currently Being Moderated
    If your input video can be preprocessed in an external tool to include an alpha channel on the areas where you want it to be transparent, then I think it should be trivial, just play your video using the MediaPlayer and the background should show through the transparent or translucent pixels in the video.
    So I tried this and it worked :-)

    The tricks involved were:
    - The video format used needed to be a VP6 encoded FLV with alpha channel enabled (h.264 doesn't support alpha channel encoding).
    - The video had to be produced with an alpha channel showing through parts of it.
    - Care needed to be maintained during the video production to ensure alpha encoding formats were the only ones used for intermediate saves (e.g. uncompressed avi with alpha channel encoding of VP6 with alpha channel encoding).

    I really like this effect because it means you can do things like training applications where you record a chromakeyed video of a real person or a cell animation and superimpose it over your various items rendered in JavaFX canvases or scenegraphs. The person or animated character can enter an animated stage and explain stuff about different items on it by walking over to them and pointing at them. The effect also works with transparent stages, so you can overlay the video over desktop and native apps. Because it is straight alpha blending, various degrees of translucency are supported from fully opaque video sections through mixed video and background animations and fully transparent video sections.
  • 6. Re: JavaFX transparent video ( grenbox ) , possible?
    915360 Newbie
    Currently Being Moderated
    can you give sample application as a zip file ? with source if possible?
  • 7. Re: JavaFX transparent video ( grenbox ) , possible?
    Marcello Newbie
    Currently Being Moderated
    Thanks for your work on this. Which video tool did you use for adding the alpha channel ?
  • 8. Re: JavaFX transparent video ( grenbox ) , possible?
    jsmith Guru
    Currently Being Moderated
    I used a combination of Sony Vegas and Adobe After Effects. I used Vegas to produce the alpha channel video as an uncompressed video and then After Effects to convert the uncompressed video to a VP6 flv format with alpha channel enabled. They were both in free trial mode at the time. The free trial expired so I can't reproduce the exact steps right now to document them here. Probably it could all be done in After Effects.

    I noticed yesterday that if you run the Ensemble sample app, there is an advanced Media sample in it which demonstrates playing back flvs with encoded alpha channels, the same as I created to answer this question.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points