VideoPlayback: understand how to scale video to fill target

0 votes
asked Jan 13, 2018 by gleneindr (220 points)

Hello,

Can someone explain me how to correctly scale the video to fit in the detected imagetarget.

My image target and the video have the same ratio.

I have the following code but my video is "cropped". I mean I see only a part of the video (as it was zoomed in).

I don't understand how I can correctly dislpay my video inside the detected image target

Note: 

the image is 640x360

the video is: 640x360

Thanks a lot for your help !!

public class EasyArMagTarget : MonoBehaviour
    {
        void CreateTarget(string targetName, out SampleImageTargetBehaviour targetBehaviour)
        {
            GameObject Target = new GameObject(targetName);
            
            Target.transform.localPosition = Vector3.zero;
            targetBehaviour = Target.AddComponent<SampleImageTargetBehaviour>();
            
        }

        void Start()
        {
            SampleImageTargetBehaviour targetBehaviour;
            ImageTrackerBehaviour tracker = FindObjectOfType<ImageTrackerBehaviour>();
            // dynamically load all targets from json file
            var targetList = ImageTargetBaseBehaviour.LoadListFromJsonFile("images_targets.json", StorageType.Assets);
            foreach (var target in targetList.Where(t => t.IsValid).OfType<ImageTarget>())
            {

                CreateTarget(target.Name, out targetBehaviour);
                targetBehaviour.Bind(tracker);
                targetBehaviour.SetupWithTarget(target);
                targetBehaviour.Size = new Vector2(target.Size.x, target.Size.y);

                float ratio = target.Size.x / target.Size.y;
                
                GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
                plane.transform.localScale = new Vector3(1f, 1f, 1f/ratio);
                plane.transform.parent = targetBehaviour.gameObject.transform;

                VideoPlayerBehaviour playerBehavior = plane.AddComponent<VideoPlayerBehaviour>();
                playerBehavior.transform.localScale = new Vector3(1f, 1f, 1f / ratio);
                playerBehavior.Path = "myvideo.mp4";
                playerBehavior.EnableAutoPlay = true;
                playerBehavior.EnableLoop = true;
                playerBehavior.OpenWhenStart = true;
                playerBehavior.DisplayTextMessage = true;
                playerBehavior.Storage = StorageType.Assets;
                playerBehavior.Type = VideoPlayerBaseBehaviour.VideoType.TransparentSideBySide;
                playerBehavior.VideoScaleMode = VideoPlayerBaseBehaviour.ScaleMode.Fill;
                playerBehavior.VideoScalePlane = VideoPlayerBaseBehaviour.ScalePlane.XZ;
                playerBehavior.VideoScaleFactorBase = 0.02f;

            }

            targetBehaviour = null;
        }
    }

2 Answers

0 votes
answered Jan 16, 2018 by gleneindr (220 points)

Hello,

Thanks a lot for your reply.
I must do something wrong because I Use 

playerBehavior.VideoScaleMode = VideoPlayerBaseBehaviour.ScaleMode.Fill; 

so the video should be scaled to the dimension of the imageTarget. In the code above in my previous post, i write


targetBehaviour.Size = new Vector2(target.Size.x, target.Size.y);


where Size = [8,4.5] respecting the aspect ratio of the video (640x360)

So why my video looks like zoomed in and cropped.

I thing I don't understand the unit to use

If you can give me further help, I would gretly appreciate

Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...