Log in or register to post comments

Playing a video with alpha channel in the VideoSample demo project

July 10, 2012 - 4:03pm #69

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

July 17, 2012 - 2:00pm #68

I'm inquiring on this. Do you know of any examples of video w/ alpha channel transparency that I can test with?

Playing a video with alpha channel

July 19, 2012 - 8:19am #67

I'd also like to use this in a project.  I don't have a sample on hand of an alpha-enabled video file though.  I'd be curious to know if this is possible from the developers' POV.

I've seen posts on the Unity forums suggesting the use of 2 videos, one RGB version and one alpha-enabled version with a "Luminance as Alpha" setting.

Since my project will end up on mobile devices (for this project the iPad3 thankfully), I'd like to know the best practice way of using shaders on video textures.

 

Playing a video with alpha channel

July 19, 2012 - 12:27pm #66

I'm also having trouble encoding and importing my own video.  I'm using Adobe Media Encoder to encode my file using h.264, 640x360 res, in m4v file format with AAC audio.  For some reason it always imports my video as a movie texture (even the icon looks different than the VuforiaSizzle_1 & 2 examples when viewed in the project). I've successfully played videos in AR scenes before, but they were provided to me by our client.  I have not created and encoded my own Unity-compatible video file for playback on a mobile device through an AR-enabled app.

I already know the recommended specs for Android/iOS video playback and encode settings mentioned in the Unity documentation, but for some reason I cannot get my video file into the same .m4v container that was used to encode the VuforiaSizzle sample videos in the demo app.

Am I missing something here?  What software / encoder did you guys @ Qualcomm use to create the 2 videos in the Vuforia Video Playback Sample app?

Thanks!

Ignore my previous post

July 19, 2012 - 2:34pm #65

Apologies - please ignore my post below, I figured out how to get the videos in the correct format using Handbrake (free encoding software).

Choose the ipod/iphone preset to get an MPEG-4 container .M4V file ready for Unity.

Playing a video with alpha channel

July 19, 2012 - 3:08pm #64

If you're interested in seeing official support for Alpha channel video transparency please post a request to the wishlist. Apparently this is something that is likely to be feasible, but hasn't been implemented on the current Video Playback sample.

The basic requirements, as conveyed to me , are to ..

-          Enable blending when rendering
-          Output the alpha values of the movie on the fragment shader.
-          And probably setup an RGBA texture on iOS (Android’s is done automatically).

This could be pretty handy.

July 19, 2012 - 5:50pm #63

This could be pretty handy.  Video wouldn't necessarily have to be squared off anymore, and that opens up a lot of possibilities.

Playing a video with alpha channel in the VideoSampledemoproject

August 23, 2012 - 4:50am #62

Hello,DavidBeard!

It works on android, but i failed to find how to set up an rgba texture on ios.Can you tell me how to do that? I'm trying to use this shader(it works on android 4)

Shader "Custom/Alpha"{

Properties {  

_MainTex ("Base (RGB)", 2D) = "black" {}

_Color ("AlphaColor", Color) = (0,0,0,255) }

SubShader { Tags { "RenderType"="transparent" }

LOD 200 CGPROGRAM

#pragma surface surf Lambert alpha sampler2D _MainTex;

struct Input { float2 uv_MainTex; };

float4 _Color;

void surf (Input IN, inout SurfaceOutput o)

{

half4 c = tex2D (_MainTex, IN.uv_MainTex);

o.Albedo = c.rgb;

if(c.r == _Color.r && c.g == _Color.g && c.b == _Color.b)

o.Alpha = 0;

else

o.Alpha = 1;

// o.Albedo = 1; }

ENDCG

}

FallBack "Diffuse"

Playing a video with alpha channel in the VideoSample demo proje

November 19, 2012 - 6:08am #61

Hey guys,

Any luck trying to make this work?

Cheers,

N

Playing a video with alpha channel in the VideoSample demo proje

November 21, 2012 - 8:54am #60

First of all, @virt, thank you very much for your shader.

It works like a charm in Android ICS. Anyway, I had to modify it, because while using it with compressed video, the Alpha threshold can't be exact due to the pixel values being modified by the compression algorithm. I used a range of +/- 5% instead and everything is ok now.

The next step is to get the same effect in IOS (it is not working as you already stated), and I was wondering if you got any achievement in this sense, since you were already working on it several months ago.

Any help would be appreciated.

Thank you very much in advance.

 

Playing a video with alpha channel in the VideoSample demo proje

November 21, 2012 - 11:13am #59

Hello,alvaroem.Not at all for the shader,it's a pleasure if it can help someone.Well, i was forced to abandon to find how to do it because of some other job.But I succed to play a simple movie with alpha channel with Scaleform, but u'll need to correctly setup the sound as it's not imported with the movie. I'didn't really go on with the subject,but possibly in future with a client contract. Can you contact me if you'll find a good solution for ios?

@vincekilian I'm facing the

December 20, 2012 - 6:32am #58

@vincekilian

I'm facing the same probelm you had in the last comment

But I can't solve it yet .. I tried to use HandBrake with the settings you said, but no success

Can you explain more.

Thanks in advance

Using Handbrake

December 20, 2012 - 6:42am #57

I used the Handbrake software and chose my source video file.  Then I changed the output preset to the "iPhone/iPad/iPod" Preset in the right hand column of the Handbrake interface.  Then I named my output file and chose the destination to output it to (I usually just push it to the desktop and make sure it encoded properly before I copy it into my project.

You need to pass in a video file that will play natively on the target device.  To test this, try taking your encoded video from Handbrake and copying to your target device.  Then, try to play the video directly on the device (not through Unity but through the native video player on the device.)  If it works, it will work when Unity converts it.  If it doesn't work natively, your encode or compression settings are outside of the supported presets that your target device will support.  Therefore, when Unity takes that file and tries to process it, it will always result in an unusable/unplayable file that imports as a movie texture (which is not supported by Unity's mobile solution).

Hope this helps.

Cheers,

Vince

Playing a video with alpha channel in the VideoSample demo proje

March 21, 2013 - 9:34am #56

Hi, may i know is it possible to display this kind of video on galaxy ace 2 with android 2.3.3?

Playing a video with alpha channel in the VideoSample demo proje

March 21, 2013 - 11:45am #55

Hi, on Android devices, you need at least Android 4.0 (ICS) to show video on texture (with or without alpha)

 

Playing a video with alpha channel in the VideoSample demo proje

July 22, 2013 - 11:15am #54

Any update about this?

Playing a video with alpha channel in the VideoSample demo proje

July 22, 2013 - 11:16am #53

Any update about this?

Playing a video with alpha channel in the VideoSample demo proje

July 22, 2013 - 11:26am #52

What is it that you want to know? --  several devs have implemented this capability on their own, it's not part of the SDK.

Playing a video with alpha channel in the VideoSample demo proje

July 22, 2013 - 11:31am #51

I've understood that many devs archived to make it work on android but what about iOs?

 

Ps. It's possible that was my problem about understand the replies (not very good in english)

 

Thanks!

Playing a video with alpha channel in the VideoSample demo proje

July 23, 2013 - 3:48am #50

 

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

Playing a video with alpha channel in the VideoSample demo proje

September 2, 2013 - 5:55am #49

Playing a video with alpha channel in the VideoSample demo proje

September 2, 2013 - 6:24am #48

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

November 26, 2013 - 11:26pm #47

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

March 5, 2015 - 3:32pm #46

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

April 13, 2015 - 3:11pm #45

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

June 8, 2015 - 2:12pm #44

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

June 26, 2015 - 12:44pm #43

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

July 21, 2015 - 5:51am #42

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

Playing a video with alpha channel in the VideoSample demo proje

November 11, 2015 - 12:23pm #41

Playing a video with alpha channel in the VideoSample demo proje

November 12, 2015 - 1:16pm #40

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

March 23, 2016 - 3:02am #39

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

March 23, 2016 - 3:07am #38

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 - 7:48am #37

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 - 7:55am #36

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 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 28, 2016 - 8:12am #34

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 - 12:41pm #33

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 - 12:57pm #32

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 - 10:52pm #31

@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 - 10:53pm #30

I want to learn tell me how much you need?

Playing a video with alpha channel in the VideoSample demo proje

March 28, 2016 - 11:09pm #29

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 29, 2016 - 7:29am #28

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 29, 2016 - 7:34am #27

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

April 11, 2016 - 6:14pm #26

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

April 12, 2016 - 8:22am #25

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 12, 2016 - 8:46am #24
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 - 9:01am #23

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 - 9:42am #22

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:46am #21

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 13, 2016 - 5:23am #20
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 13, 2016 - 7:28am #19

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
Log in or register to post comments