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

ImageData.Data Stride Estimation #134

Open
Scubaboy opened this issue Nov 6, 2023 · 0 comments
Open

ImageData.Data Stride Estimation #134

Scubaboy opened this issue Nov 6, 2023 · 0 comments

Comments

@Scubaboy
Copy link

Scubaboy commented Nov 6, 2023

Hi,
I'm using FFMediaToolKit in a Unity 3D project to create videos of Unity's 3D scene. I'm capturing Unity's camera view as follows:

 _screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
 _captureCamera.targetTexture = _renderTexture;
 RenderTexture.active = _renderTexture;
 _screenShot.ReadPixels(new Rect(0,0,Screen.width, Screen.height),0,0);
 _screenShot.Apply();
var pixelData = _screenShot.GetRawTextureData();

The above code provides a byte array of raw pixel data. When I take the byte array and try to construct an 'ImageData' object

ImageData.FromArray(pixelData , ImagePixelFormat.Rgb24, Screen.width, Screen.height);

I get the following exception:

Pixel buffer size doesn't match size required by this image format.

You use the following formula to calculate the expected stride:

4 * (((GetBitsPerPixel(format) * width) + 31) / 32);

However the byte array generated by Unity is

Screen.Width x Screen.height x 3

3 bytes per pixel corresponding to the 'TextureFormat.RGB24'

Is there any course of action I can take to resolve this difference?

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

1 participant