Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspect ratio #11

Open
SupranJowti opened this issue Jun 27, 2019 · 19 comments
Open

Aspect ratio #11

SupranJowti opened this issue Jun 27, 2019 · 19 comments
Assignees

Comments

@SupranJowti
Copy link

my texture size is 640 by 320

but the video stretch, because it does not render on the device screen size,

how can i render camera into fixed size

@zhangtao1104
Copy link
Collaborator

First, you can control the video size by api named setVideoProfile().

Second, you can get the real size of video width and video height by (engine.UpdateTexture (texId, uid, ref texWidth, ref texHeight)

At last, you can new Texture2D According to the second step.

@SupranJowti
Copy link
Author

Thank you for the reply

Now while scaling the cube in (engine.UpdateTexture (texId, uid, ref texWidth, ref texHeight) it is looking fine

but this is not the desire frame size I want to set

@zhangtao1104
Copy link
Collaborator

You can control the video frame size by api named setVideoProfile.
This is the api document:
https://docs.agora.io/en/Interactive%20Gaming/game_unity?platform=Unity

@SupranJowti
Copy link
Author

SupranJowti commented Jul 5, 2019

Thank you again

I am sorry for my previous comment. It should be well informed.

i was trying with setVideoProfile.

the problem is that my requirement is to scale the cube width should be similar to the device screen width
and the cube height is a variable depends on the screen ratio means 1/3 of the screen height

now when i use setVideoProfile(30, false) means 640 x 360
the cube resize as the size

how can i scale fit on my relative size?

frame size is not fixed here.

@plutoless
Copy link
Contributor

agora supports to set your video into fit mode or fill mode. According to your previous msg it seems you are using fill mode that's why it's stretched. If you don't want that, you can choose to set the video display mode to fit, so that is scales to fit your video container while leaving the rest area black.
Usually you should not set videoprofile according to your device screen size, all you need to do is to provide a full screen canvas and let captured video stream to fill up your container using either fill/fit render mode.

@ARUtility
Copy link

ARUtility commented Aug 22, 2019

@plutoless I'm having a somewhat related issue. In the videoSurface.cs file that comes with the Unity SDK there is this code:

if (rend.material.mainTexture == null) {
                System.IntPtr texPtr = (IntPtr)engine.GenerateNativeTexture();
                Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change
                rend.material.mainTexture = nativeTexture;
            }

The problem I'm having is that no matter what I change the width and height to in the CreateExternalTexture method, the texture is getting cropped. I don't know what's going on behind the scenes of the GenerateNativeTexture method but I'm assuming something is going on there that is causing this. I've been trying to figure this out for days and no matter what I do the texture always gets cropped on the receiving end.

Do you know what might be causing this? Whenever I debug to look at the dimensions of the texture I always get 640x360. Setting the videoProfile does not affect it either.

I made some changes to the code to handle the "FIXME! texture size is subject to change" note on the second line. My code is below. I'm applying the texture to a RawImage, hence the change to rend.texture:

if (rend.texture == null) {
            System.IntPtr texPtr = (IntPtr)engine.GenerateNativeTexture();
            if(engine.UpdateTexture((int)texPtr, uid, data, ref texWidth, ref texHeight) == 0) {
                nativeTexture = Texture2D.CreateExternalTexture(texWidth, texHeight, TextureFormat.BGRA32, false, false, texPtr); // FIXME! texture size is subject to change
                rend.texture = nativeTexture;
            }
}

@zhangtao1104
Copy link
Collaborator

The dimensions who capture the video frame can not be control randomly, because it depends on the camera. But the video frame who receive the video is controled by the api named setVideoProfile().

@zhangtao1104
Copy link
Collaborator

So the video frame could be cropped in the receiving side if the ratio of capture different from the videoprofile.

@ARUtility
Copy link

@zhangtao1104 so we would need to modify the video profile using the setVideoProfile on the receiving end? I did try that one time and got the same results unfortunately. I made sure the ratio matched the sending device when I did try it as well.

@ARUtility
Copy link

@zhangtao1104 I just tried this again and still no luck. I tried setting the video profile on the receiving end to a bunch of different settings and it had no effect on the generated texture at all.

@zhangtao1104
Copy link
Collaborator

You need to use the setVideoProfile on the send end. The setVideoProfile control the encode video frame.

If you ensure you had use the setVideoProfile on the send end. Then you can use the callback named OnFirstRemoteVideoDecoded , it contains the width and the height of the videoframe . You can confirm if it the same as the setVideoFrofile which set by send end.

@biemann
Copy link

biemann commented Nov 7, 2019

@zhangtao1104

Hi, I have the same problem, the screen that I send from my Unity app appears cropped on the remote end. Using SetVideoProfile, I can change the aspect ratio to 16:9, so that a smaller part of the image got cropped, but it still does not correspond to the whole image I see on my phone screen.

I suppose what I need is a function like SetRemoteRenderMode(). However, this function only seems to exist in the Android or C++ SDK, but not in the Unity SDK. The stream on the remote end appears at the same aspect ratio than the one I defined via SetVideoProfile.

@raphaelnew
Copy link

same issue here😭

@ARUtility
Copy link

I'm working with the Agora team on this issue now. I have confirmed that the video profile is the issue. Some new phones have an aspect of 19:9 (my galaxy s10 for example) and there is no corresponding video profile for these screen sizes which causes clipping of the image on the receiving end.

@raphaelnew
Copy link

raphaelnew commented Dec 18, 2019

We use
_rtcEngine.SetExternalVideoSource(true, false);
so I push frames with custom resolution only part of the screen in unity, using
_rtcEngine.PushExternVideoFrame(externalVideoFrame);
but the problem is that receiver always gets frames in resolution set from
_rtcEngine.SetVideoProfile(45, false);
so the problem is that SetVideoProfile should have option for custom video resolution, that is not in the list provided on Documentation website😭

This is very breaking issue for us, so use the closest aspect ratio to the one that we need for SetVideoProfile

@ARUtility
Copy link

We use
_rtcEngine.SetExternalVideoSource(true, false);
so I push frames with custom resolution only part of the screen in unity, using
_rtcEngine.PushExternVideoFrame(externalVideoFrame);
but the problem is that receiver always gets frames in resolution set from
_rtcEngine.SetVideoProfile(45, false);
so the problem is that SetVideoProfile should have option for custom video resolution, that is not in the list provided on Documentation website

This is very breaking issue for us, so use the closest aspect ratio to the one that we need for SetVideoProfile

I agree, custom resolution is definitely needed here

@LuizPelegrini
Copy link

LuizPelegrini commented Sep 22, 2020

Hi, I am having issues with this too, using Agora Unity v3.0.1. I am pushing my frames to web, in the Editor it works fine, but when I build and run the app in the iPad Pro (2732x2048, is it too much?), the image is "cropped" in my webpage.

I am using

_rtcEngine.SetVideoEncoderConfiguration(new VideoEncoderConfiguration()
 {
     bitrate = 1130,
     frameRate = FRAME_RATE.FRAME_RATE_FPS_30,
     dimensions = new VideoDimensions() { width = Screen.width, height = Screen.height },

     // Note if your remote user video surface to set to flip Horizontal, then we should flip it before sending
    mirrorMode = VIDEO_MIRROR_MODE_TYPE.VIDEO_MIRROR_MODE_ENABLED,
    orientationMode = ORIENTATION_MODE.ORIENTATION_MODE_FIXED_LANDSCAPE
});

No luck so far, can someone help me, please?

@ROBYER1
Copy link

ROBYER1 commented Feb 16, 2021

Can this be fixed in the advanced demos repo too? Was stuck on this for a while and it is still not clear how to fix this?

@ROBYER1
Copy link

ROBYER1 commented Jul 5, 2021

This was apparently the fix but it didn't really fix it - AgoraIO-Extensions/Agora-Unity-Quickstart@666e1cb#diff-84cdda896658855ce7c5ff608c59e77ee409ef990f689aae04c5530132d2e7d8

Does anyone have a fix or update on this? It seems only 16:9 aspect ratios are supported which is not suitable for most mobile phone screen aspect ratios unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants