How to get Media Texture or Media Player content resolution in blueprints?

I´m working in a blueprint that changes dynamically the video texture of a Static Mesh. All the videos have different resolutions and I need to rescale the static mesh to conserve the video original aspect ratio.

There is any way to get the original resolution of this videos (from the Media Player or the Media Texture) in blueprints? If you look in the Media Texture you can find these:

But i can´t find a way to get these info from a reference of the player or texture in a blueprint. Any idea?

You’re right, there’s currently no way to get this information in Blueprint, neither via UTexture nor via UMediaTexture.

I’m going to add BP functions like the ones in UTexture2D, and I will also add a delegate that will notify you if the media texture dimensions changed, so you don’t have to poll each tick. This won’t make it into 4.14, however, because we already branched.

1 Like

Added UE-37241 for tracking

I added the following BP functions to UMediaTexture in CL# 3160746:

  • GetWidth
  • GetHeight
  • GetAspectRatio

I decided to not add a script delegate for dimension changes at this time, because it would greatly complicate the current implementation.

1 Like

Here are the changes in case you want to modify your Engine locally:

MediaTexture.h

public:

	/**
	 * Gets the current aspect ratio of the texture.
	 *
	 * @return Texture aspect ratio.
	 * @see GetHeight, GetWidth
	 */
	UFUNCTION(BlueprintCallable, Category="Media|MediaTexture")
	float GetAspectRatio() const;

	/**
	 * Gets the current height of the texture.
	 *
	 * @return Texture height (in pixels).
	 * @see GetAspectRatio, GetWidth
	 */
	UFUNCTION(BlueprintCallable, Category="Media|MediaTexture")
	int32 GetHeight() const;

	/**
	 * Gets the current width of the texture.
	 *
	 * @return Texture width (in pixels).
	 * @see GetAspectRatio, GetHeight
	 */
	UFUNCTION(BlueprintCallable, Category="Media|MediaTexture")
	int32 GetWidth() const;

MediaTexture.cpp

float UMediaTexture::GetAspectRatio() const
{
	if (Resource == nullptr)
	{
		return 0.0f;
	}

	const FIntPoint Dimensions = ((FMediaTextureResource*)Resource)->GetSizeXY();

	if (Dimensions.Y == 0)
	{
		return 0.0f;
	}

	return Dimensions.X / Dimensions.Y;
}


int32 UMediaTexture::GetHeight() const
{
	return (Resource != nullptr) ? (int32)Resource->GetSizeY() : 0;
}


int32 UMediaTexture::GetWidth() const
{
	return (Resource != nullptr) ? (int32)Resource->GetSizeX() : 0;
}
1 Like

Thanks so much for this man. I will try to compile with these changes.