Log in or register to post comments

Playing a video with alpha channel in the VideoSample demo project

July 10, 2012 - 4:03pm #1

Hi all,

 

Is it possible to play on a marker a video with alpha channel transpacency?

Which formats with alpha does Android support and do I need to set any parameters in the application?

 

Thanks.

Max. 

Playing a video with alpha channel in the VideoSample demo project

June 14, 2017 - 5:16pm #69

Playing a transparent mobile video of reality augmented with Unity and Vuforia.

The video (http://www.erasmito.com/ra/ASound.mp4) plays the graph of the waves of an audio recognizing a marker and is inspired by soundwave augmented reality (http://www.designboom.com/technology/skin-motion-soundwave-tattoos-05-09-2017/).

In an editor, the graph is separated into sections. The sections are placed inside a rectangle with green fill. Immediately

with an editor like Gimp, each section is pasted as a new image to add an alpha channel in a transparent layer is saved in PNG

format (http://www.erasmito.com/ra/Leo29.png) and a mp4 video is elaborated.

To play the previous video in video playback of vuforia in a transparent way it is necessary to separate the alpha channel

(background) for it to see a video tutorial of how to create an alpha channel of video (https://www.youtube.com/watch?v=qOhDErn36J0).

The shader used was Custom/alpha1 described at: http://answers.unity3d.com/questions/833537/how-to-play-alpha-video-in- unity.html#answer-1094012 .

Playing a video with alpha channel in the VideoSample demo project

December 30, 2016 - 6:44am #68

Hi mrkco,

I am doing the same thing.

Were you able to play the transparant video successfully using  android and vuforia?

 

Playing a video with alpha channel in the VideoSample demo proje

May 5, 2016 - 1:28am #67

One important question ?!

Green screen mode work in default mode but in full screen mode not work and show all green color

How to render shader (green screen) in full screen mode ?

[need to edit : 

   VideoPlaybackRenderer.java 

& 

   FullscreenPlayback.java ]

Thanks for helps .

Playing a video with alpha channel in the VideoSample demo proje

May 5, 2016 - 1:00am #66

Hi Developers,

After some days (maybe 3) googling, finally I found out "how to do alpha-channel in vuforia" and implemented that !

So, just googling "green screen" then do it (Android/iOS/Unity)

Thats worked like a charm

Enjoy ;-)

Playing a video with alpha channel in the VideoSample demo proje

April 25, 2016 - 12:14pm #65

My post it´s unity+vuforia for android/ios deployment. This is not an "easy to do, learn stuff", it took me quite a bit of time to solve it and learn ir well.... take a look at my post about how footage must be post produced for the shader (my custom shader) to work fine.

Playing a video with alpha channel in the VideoSample demo proje

April 25, 2016 - 12:11pm #64

#number post below ?

you say about android or unity ?

 

I want to know, how to do "step by step"

can u help me ?

:)

Playing a video with alpha channel in the VideoSample demo proje

April 25, 2016 - 7:45am #63

Hi, take a look at my posts below.

I suggest buy easy movie texture plugin, and then apply the custom shader shown on my posts to the material used by videomanager prefab.

Cheers!

 

Playing a video with alpha channel in the VideoSample demo proje

April 24, 2016 - 11:35am #62

Hi, I using Android + vuforia.

in videoplayback sample

now i want to use animation with alpha

so found this links :

custom shader

glsl plugin

how to

but how to use shader in videoplayback sample ? [to achieve animation with alpha-channel (transparency) in android]

or any idea ?

im confused !

tnx

Playing a video with alpha channel in the VideoSample demo proje

April 19, 2016 - 10:30am #61

Hi, I succed using unity + vuforia. Hereunder in this post you have everything to get it working.

If you are on a commercial project I can help you for a little fee. There´s a lot of little tricks to know/learn before succed.

Regards!

Playing a video with alpha channel in the VideoSample demo proje

April 19, 2016 - 10:22am #60

Hi Dears,

I am using Android SDK.

I wanna play transparent animation in Vuforia Target

So ,

I try gif transparent but Vuforia not supported gif in target.

I am using VideoPlayback Sample on Android SDK

I want to use alpha-channel video format : h.264/mpeg-4(m4v/mp4) for Transparency video showing

but converters just send me FLV or AVI format in alpha-channel who not supported in Vuforia

now I wanna any help to me for codding in my project

How to Implementation shader in my code ? or how to use VideoPlaybackShaders.java 
(then use normal video or transparent video in project?)

 

Thanks for help

Playing a video with alpha channel in the VideoSample demo proje

April 16, 2016 - 5:56am #59
I'm following lucas7cl's steps and make the video  transparent with color, (except the bug that I have to re-enter the app or the video will show black screen )
 could you please send me your video, so I can test it on iOS.

Playing a video with alpha channel in the VideoSample demo proje

April 15, 2016 - 10:00pm #58

Did you use the ios patch of the plugin? Try another encoding of media, and/or make a delay after init()

Playing a video with alpha channel in the VideoSample demo proje

April 15, 2016 - 9:42pm #57
I tested it on Android, it all running good, no black screen, but for iOS, the video will play black screen at the first time, if I press Home button return to the Home screen, then re-enter the app, the video plays normally, no black screen any more. 
 
So maybe it's a bug for Easy Movie Texture in iOS? anyone succeed in iOS?

Playing a video with alpha channel in the VideoSample demo proje

April 14, 2016 - 10:41pm #56

Jove would you help me in that?

i want to play alpha channel video. please

Playing a video with alpha channel in the VideoSample demo proje

April 14, 2016 - 9:13am #55

did you modify the vuforia script?

like this:

 

using UnityEngine;
 
namespace Vuforia
{
    /// <summary>
    /// A custom handler that implements the ITrackableEventHandler interface.
    /// </summary>
/// 
 
    public class DefaultTrackableEventHandler : MonoBehaviour,
                                                ITrackableEventHandler
    {
        #region PRIVATE_MEMBER_VARIABLES
 
        private TrackableBehaviour mTrackableBehaviour;
    
        #endregion // PRIVATE_MEMBER_VARIABLES
 
public static int trackOn=0;
 
 
 
        #region UNTIY_MONOBEHAVIOUR_METHODS
    
        void Start()
        {
            mTrackableBehaviour = GetComponent<TrackableBehaviour>();
            if (mTrackableBehaviour)
            {
                mTrackableBehaviour.RegisterTrackableEventHandler(this);
Debug.Log("Start tracker");
            }
        }
 
        #endregion // UNTIY_MONOBEHAVIOUR_METHODS
 
 
 
        #region PUBLIC_METHODS
 
        /// <summary>
        /// Implementation of the ITrackableEventHandler function called when the
        /// tracking state changes.
        /// </summary>
        public void OnTrackableStateChanged(
                                        TrackableBehaviour.Status previousStatus,
                                        TrackableBehaviour.Status newStatus)
        {
Debug.Log("cambio en estado del tracker");
            if (newStatus == TrackableBehaviour.Status.DETECTED ||
                newStatus == TrackableBehaviour.Status.TRACKED ||
                newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
            {
                OnTrackingFound();
trackOn=1;
Debug.Log("Encontramos algo el tracker, trackOn= 1");
            }
            else
            {
                OnTrackingLost();
trackOn=0;
Debug.Log("Nada el tracker, trackOn= 0");
            }
        }
 
        #endregion // PUBLIC_METHODS
 
 
then you can call the video like this:
 
if ((DefaultTrackableEventHandler.trackOn == 1) &(startTimer==false)) {
 
scrMedia2.Play();
.....
 
 
good luck, cheers!

 

Playing a video with alpha channel in the VideoSample demo proje

April 14, 2016 - 7:53am #54

lucas7cl wrote:

Hi, maybe it´s not as easy as replacing movitexture for easy movie texture.---

First: Use a shader to manage luma key, I already post this:http://answers.unity3d.com/questions/833537/how-to-play-alpha-video-in-unity.html#answer-1094012

Then, you will notice that the video must be set in a "special way" so the shader can do the magic.

If everything is done properly you should see nothing in the development view (PC), but when deployed to mobile should show the alpha video properly.

Two weeks ago a guy from the forum needed help to succed, and we arrange it for some reasonable money.

Cheers!

 

Hello I'm following all the steps as you sugggested, but I have a problem with the video's color:
 
Here a frame of the video I created:

https://dl.dropboxusercontent.com/u/16141944/Frame.png

And this is what I get when I use the Vuforia Video Playback:

https://dl.dropboxusercontent.com/u/16141944/Frame2.png

It loses all the color and looks like a ghost. I would really appreciate any help to get this working.
 
I'm working on windows 8.1, Unity 5.1.2f1 (32 bit) + VideoPlayback-5-5-9, currently testing it on Samsung Galaxy Tab Pro 10.1, I'm wondering if it is going to work on iOS devices too.

Thank you in advance!

Playing a video with alpha channel in the VideoSample demo proje

April 13, 2016 - 9:31am #53

I think this is a init problem, try to load the video some frames before you play it! you can use a timer, half a second is a good point to start testing.

Playing a video with alpha channel in the VideoSample demo proje

April 13, 2016 - 9:14am #52
Thanks lucas7cl:
 
I follow your step and still get a black screen with sound playing.
 
*BUT* I found that, if I press Home button return to the Home screen, and re-enter the app, the video plays perfect!!! no black screen any more. 
 
 
and If I select "auto play" on the MediaPlayerCtrl, set no condition to play, it plays perfect at the begining as well.
 
I'm using iPhone, and no Android to test. is this a iOS bug or Vuforia bug? or something wrong with my code?
 
 
Cheers!
AttachmentSize
Image icon QQ20160414-1.png599.09 KB

Playing a video with alpha channel in the VideoSample demo proje

April 13, 2016 - 7:28am #51

Hi, you must define a public var in the vuforia script: "trackOn". Then in another script attached to videmanager object, the important part is:

if ((DefaultTrackableEventHandler.trackOn == 1) &(startTimer==false)) {

scrMedia2.Play();
Debug.Log ("play video");
if (startTimer==false){
startTimer=true;
}
}
if ((DefaultTrackableEventHandler.trackOn == 0)&(startTimer==true)) {
scrMedia2.Stop();
timeLeft = tiempo;
estado=1;
Debug.Log ("stop video");
startTimer=false;
}
 
don´t forget to define variables like:
 
public MediaPlayerCtrl scrMedia2;  // asign the object Videomanager, take a look at the pic attached
double timeLeft = 0;
bool startTimer = false;

Please take a look at the attached pic, there you can see details.

Cheers!

AttachmentSize
Image icon pic1.png374.29 KB

Playing a video with alpha channel in the VideoSample demo proje

April 13, 2016 - 5:23am #50
using UnityEngine;
using System.Collections;

public class PlayVideo : MonoBehaviour {

	private bool isPlaying = false;
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (!isPlaying) {
			if (GetComponentInParent<DefaultTrackableEventHandler> ().trackOK) {
				GetComponent<MediaPlayerCtrl>().Play();
				isPlaying = true;
			} else {
				GetComponent<MediaPlayerCtrl>().Pause();
				isPlaying = false;
			}
		}

	}
}

 

Like this? but I got a "The type or namespace name `DefaultTrackableEventHandler' could not be found. " error.

Playing a video with alpha channel in the VideoSample demo proje

April 12, 2016 - 9:46am #49

Did you initialize the video before playing?

In your case, I will add a script to the video manager, and add a public variable to the vuforia script, like "TrackOK" when is tracking ok, and ask it value from your script.

 

Playing a video with alpha channel in the VideoSample demo proje

April 12, 2016 - 9:42am #48

Hi 

Yes, I'm using the "VideoManger" prefab, as I said, it run all good if I add nothing in "OnTracking" function,

But if I didn't play video auto, and play it in "OnTrackingFound" function , it will show black screen with sound playing.

I don't know why.

Playing a video with alpha channel in the VideoSample demo proje

April 12, 2016 - 9:01am #47

Are you using the "VideoManager" Prefab?, you must put it like a child of Vuforia Image target.

Be aware of naming of materials, and use of shaders and textures.

 

Playing a video with alpha channel in the VideoSample demo proje

April 12, 2016 - 8:46am #46
Hi,lucas7cl, I haven't try the transparent video yet, just normal video.
 
I found the key point lead to the black screen.
 
If I uncheck the "B Auto Play" in the Media Player Ctrl of Easy Movie Texture,
 
In the DefaultTrackableEventHandler.cs of Vuforia, add 
GetComponentInChildren<MediaPlayerCtrl>().Play();

 

in the OnTrackingFound(), and add
GetComponentInChildren<MediaPlayerCtrl>().Pause();
in the OnTrackingLost(). it will show black sreen with sound playing.
 
If I do nothing with DefaultTrackableEventHandler.cs, it will play all well.
 
Any suggestions?
 
Thanks!

 

AttachmentSize
Image icon QQ20160412-0.png172.71 KB

Playing a video with alpha channel in the VideoSample demo proje

April 12, 2016 - 8:22am #45

Hi, maybe it´s not as easy as replacing movitexture for easy movie texture.---

First: Use a shader to manage luma key, I already post this:http://answers.unity3d.com/questions/833537/how-to-play-alpha-video-in-unity.html#answer-1094012

Then, you will notice that the video must be set in a "special way" so the shader can do the magic.

If everything is done properly you should see nothing in the development view (PC), but when deployed to mobile should show the alpha video properly.

Two weeks ago a guy from the forum needed help to succed, and we arrange it for some reasonable money.

Cheers!

Playing a video with alpha channel in the VideoSample demo proje

April 11, 2016 - 6:14pm #44

Hi lucas7

I bought the Easy Movie Texture, and use it in Vuforia, I replace the Vuforia Video Texture with it, and tested a nomal video (without transparent), the video just show black screen but there was sound playing, what did I do wrong? 

Any suggestions?
 
Thanks!

Playing a video with alpha channel in the VideoSample demo proje

March 29, 2016 - 7:34am #43

Take it easy man, I understand your requirement. I can solve it ASAP, send me a Private Message.

Playing a video with alpha channel in the VideoSample demo proje

March 29, 2016 - 7:29am #42

Hi, 

First you need to purchase easy movie texture plugin. Do you have the video already cutted with alpha channel? 

As I solved the problem you need someone who knows post production software such as After Effects to prepare the video.

Send me a Private Message to talk about money to finish your project ;)

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 11:09pm #41

I want to create a business card(Augmented reality for android app). on that i have my own picture and when i scan it this will play a video on the target image. and video will be alpha channel(or a video only showin me not my surroundings like in image a png format).  this is what i want to do. I am just a bottelnack. please help me.

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 10:53pm #40

I want to learn tell me how much you need?

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 10:52pm #39

@Rockeyman  would you post your step wise procedure to play an alpha channel or a transparent video. thank you.

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 12:57pm #38

Hi, what´s your actual problem? try using the custom shader I have posted down in this thread.

I use the plugin: https://www.assetstore.unity3d.com/en/#!/content/10032

The rest is to have the alpha and matte footage in only one video: 512x1024

If you are "in a hurry" or in "really big trouble with your boss or client" I can make it work for a little amount of cash.

Cheers!

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 12:41pm #37

HI all,

I want to play alpha channel video i have done lots of research on alphac channel video in unity for vuforia application. I have bought plugin which is "U chroma" please helkp me how to implement this plugin to remove the transparency from the video. I found solution regrading remove transparency from the video on the unity answer. I have applied different shaders to got perfect result. I have used unity's inbuilt shaders  fx/flare it remove the transparency from the video but opacity of the video is low. it is looking bright.

so i bought "U chroma Plugin" please help how to integrate this plugin with vuforia. which shader should i apply and what should be value for the shades please help me.

Thanks

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 8:12am #36

yes it works!! 

Just follow my post, or in case you want it asap I can do it for some $$$

cheers

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 5:10am #35

Did you make it worked? actually i want to play an alpha channel video when the target image found for android augmented.

Playing a video with alpha channel in the VideoSample demo proje

March 23, 2016 - 7:55am #34

That asset will help also. Works on mobile
https://www.assetstore.unity3d.com/en/#!/content/22524

Playing a video with alpha channel in the VideoSample demo proje

March 23, 2016 - 7:48am #33

Hi, there are two main things to manage to make it work.

1. Buy a plugin for Mobile Movie Texture: https://www.assetstore.unity3d.com/en/#!/content/10032

2. Use a shader to manage luma key, I already post this: http://answers.unity3d.com/questions/833537/how-to-play-alpha-video-in-unity.html#answer-1094012

I already make it work, for iOS there´s a patch in the plugin folders.

Cheers!

Playing a video with alpha channel in the VideoSample demo proje

March 23, 2016 - 3:07am #32

Please help me out in how to play alpha channel video?

Playing a video with alpha channel in the VideoSample demo proje

March 23, 2016 - 3:02am #31

Did you play the alpha channel video? if yes please help us to achive the same. i wanted to play the alpha channel video.

Playing a video with alpha channel in the VideoSample demo proje

November 12, 2015 - 1:16pm #30

How do you us it without the MovieTexture class in the C# script? 

I already have my video working fine, but can´t deploy to Android due to: "error CS0246: The type or namespace name `MovieTexture' could not be found. Are you missing a using directive or an assembly reference?"

 

Playing a video with alpha channel in the VideoSample demo proje

November 11, 2015 - 12:23pm #29

Playing a video with alpha channel in the VideoSample demo proje

July 21, 2015 - 5:51am #28

Is there any solution for Unity? Can find anything for it

Playing a video with alpha channel in the VideoSample demo proje

June 26, 2015 - 12:44pm #27

We created a plug-in that does this- which we hope to release to the Unity Asset Store soon.  Life-sized people/characters (from chroma keyed video footage) with no pixelation; IOS & Android.  We will keep you updated.

 

Grisly

Playing a video with alpha channel in the VideoSample demo proje

June 8, 2015 - 2:12pm #26

I am trying to do this using the unity sample. I got some tips from here on how to make a custom shader http://answers.unity3d.com/questions/9750/movie-texture-blending.html

So I have used the following shader to be the shader on one of the video layers in the sample project:-

Shader "MovieWithSeperateAlpha" { 
	Properties { 
		_MainTex ("Base (RGB)", 2D) = "white" {} 
		_Mask ("Culling Mask", 2D) = "white" {} 
		_Cutoff ("Cutoff", Range (0,1)) = .5 
	}
	SubShader {
		Tags {"Queue"="Transparent"}
		
		ZWrite Off
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass {    
	         CGPROGRAM 
	         	 #pragma vertex vert
	             #pragma fragment frag 
	             #include "UnityCG.cginc"  
	 
	             sampler2D _MainTex; 
	             sampler2D _Mask; 
	 
	             struct v2f 
	             { 
	                 float4 pos : POSITION; 
	                 float4 uv : TEXCOORD0; 
	             }; 
	             
	             v2f vert (appdata_base v)
	             	{
	             	v2f o;
	             	o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
	             	return o;	             	
	             	}
	 
	             half4 frag (v2f i) : COLOR 
	             { 
	                 half4 color = tex2D(_MainTex, i.uv.xy); 
	                 half4 color2 = tex2D(_Mask, i.uv.xy); 
	 
	                 return half4(color.r, color.g, color.b, color2.r); 
	             } 
	         ENDCG         
	     }    
	 }
	 
	 Fallback "Transparent/Diffuse" 
}

I dont know if the vert part of that is right- unity5 seem to require that the vert bit be there but the code in the linked thread doesn't have it- i think because it was written for unity4

The video that I am using is the same one I used for Metaio and it has the video without alpha on the left and then a black and white mask on the right- the idea is that the shader uses the values from the right half of the video as the alpha channel where black = transparent and white = opaque.

So in the inspector for the video layer in the 'Path' text area I have the video file I am using (and this video plays fine so thats not the issue)

Then I have modified the 'VideoPlaybackBehaviour' script around line 221 so that firstly it makes the video plane half the width of the video (if .alpha is found in the name of the file:-

int videoWidth = mVideoPlayer.GetVideoWidth();
					
					if(m_path.IndexOf(".alpha")> -1)
						{
						videoWidth = videoWidth/2;
						}
                    int videoHeight = mVideoPlayer.GetVideoHeight();

Then in the HandleStateChange function I try to load the mVideoTexture into both the _MainTex and _Mask channels and then scale the _MainTex so that only half of it shows on the plane and do the same with the _Mask channel but offset it so that only the right side shows on that one:-

// Handle video playback state changes
    private void HandleStateChange(VideoPlayerHelper.MediaState newState)
    {
        // If the movie is playing or paused render the video texture
        // Otherwise render the keyframe
        if (newState == VideoPlayerHelper.MediaState.PLAYING ||
            newState == VideoPlayerHelper.MediaState.PAUSED)
        {
			Material mat = GetComponent<Renderer>().material;
			mat.SetTexture("_MainTex",mVideoTexture);
			mat.SetTexture("_Mask",mVideoTexture);
			if(m_path.IndexOf(".alpha")> -1)
				{
				mat.SetTextureScale("_MainTex",new Vector2(0.5f,1));
				mat.SetTextureScale("_Mask",new Vector2(0.5f,1));
				mat.SetTextureOffset("_Mask",new Vector2(0.5f,0));
			}
			else 
				{
				mat.mainTextureScale = new Vector2(1, 1);
				}
        }[etc]

BUT this is not working- I am just getting a blank (transparent) video. This might be because the alpha side does start off all black as the video 'fades in' and maybe the _Mask texture part is not playing perhaps? I can hear that the video is playing because the sound plays... Or maybe its an issue with the vertex bit of the shader (since I just guessed that as I say)

Does anyone have any ideas what I maybe doing wrong?

Playing a video with alpha channel in the VideoSample demo proje

April 13, 2015 - 3:11pm #25

Could you give a way to add shader right? 

I mean tis:

http://pilcrowpipe.blogspot.ru/2013/03/chroma-keying-transparent-background.html

 

Thank you.

Playing a video with alpha channel in the VideoSample demo proje

March 5, 2015 - 3:32pm #24

We have just managed to implement an alpha channel into our video using the shader from this link:

http://jon-martin.com/?p=570#comment-6832

Just needed to lower the smoothness and sensitivity to 0.3 and 0.025 respectivley

Playing a video with alpha channel in the VideoSample demo proje

November 26, 2013 - 11:26pm #23

I do not use Unity, how can I use this shader in native c format? I notice a existing shader in VideoPlayback example, but do not know how to modify it: 

 

static const char videoPlaybackFragmentShader[] =

    "#extension GL_OES_EGL_image_external : require \n"

    "precision mediump float; \n"

    "varying vec2 texCoord; \n"

    "uniform samplerExternalOES texSamplerOES; \n"

    "void main() \n"

    "{ \n"

    "   gl_FragColor = texture2D(texSamplerOES, texCoord); \n"

    "} \n";

 

#endif // _QCAR_VIDEOPLAYBACK_SHADERS_H_

Playing a video with alpha channel in the VideoSample demo proje

September 2, 2013 - 6:24am #22

Sorry, this is something we are not able to help with so you'll have to progress on your own.

 

N

Playing a video with alpha channel in the VideoSample demo proje

September 2, 2013 - 5:55am #21

Playing a video with alpha channel in the VideoSample demo proje

July 23, 2013 - 3:48am #20

 

Although we release a video playback sample, this is not part of the Vuforia SDK.

Instead you are free to extend the sample because all the source code is released for native iOS, and hence there is no "library" as such.

thank you

 

N

Log in or register to post comments