# VideoAspectRatio

> Use these methods to fit a video into your target area.

## Definition

* **Type:** Enum
* **Namespace:** [UnityEngine.Video](/engine/6000.6/script-reference/unityengine/video.md)
* **Assembly:** UnityEngine.VideoModule

```csharp
public enum VideoAspectRatio
```

## Remarks

This enum gives you several options to manage how the VideoPlayer renders the video to a target area. To do this, the VideoPlayer adjusts or maintains the video's original aspect ratio. If you render a video into a [RenderTexture](/engine/6000.6/script-reference/unityengine/rendertexture.md), and the aspect ratio of the [RenderTexture](/engine/6000.6/script-reference/unityengine/rendertexture.md) doesn't match that of the video being rendered, the [VideoPlayer](/engine/6000.6/script-reference/unityengine/video/videoplayer.md) automatically adds black bars around the video. If you render a video into a [Camera](/engine/6000.6/script-reference/unityengine/camera.md), any area around the video remains transparent.

## Examples

```csharp
// This script switches between the aspect ratios when you press the Spacebar. 
// To set up your project for this script: 
// 1. Attach this script to a GameObject in your Scene. 
// 2. Add a VideoPlayer component to your GameObject.
// 3. Assign a VideoClip to your VideoPlayer. 

using UnityEngine;
using UnityEngine.Video;

public class VideoRenderModeExample : MonoBehaviour
{
    VideoPlayer videoPlayer;

    void Start()
    {
        videoPlayer = GetComponent<VideoPlayer>();

        // Make video play over the Scene. 
        videoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
        Camera mainCamera = Camera.main; 
        videoPlayer.targetCamera = mainCamera;

        // Loop the video.
        videoPlayer.isLooping = true;

        // Set the default aspect ratio.
        videoPlayer.aspectRatio = VideoAspectRatio.Stretch;

        // Play the video.
        videoPlayer.Play();
    }

    private void Update()
    {
        // If you press the Spacebar, cycle through the aspect ratios.
        if (Input.GetKeyDown(KeyCode.Space))
        {
            VideoAspectRatio currentAspectRatio = videoPlayer.aspectRatio;

            // Cycle through the enum values and loop back around. 
            int nextAspectRatio = ((int)currentAspectRatio + 1) % System.Enum.GetValues(typeof(VideoAspectRatio)).Length;

            // Apply the new aspect ratio.
            videoPlayer.aspectRatio = (VideoAspectRatio)nextAspectRatio;

            Debug.Log($"Switched aspect ratio to: {videoPlayer.aspectRatio}");
        }
    }
}
```

## Fields

| Value                                                                                                    | Description                                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [FitHorizontally](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/fithorizontally.md) | Resize the image proportionally so that the width fits the target area.                                                                                                                                |
| [FitInside](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/fitinside.md)             | Resize the image proportionally so that the content fits the target area.                                                                                                                              |
| [FitOutside](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/fitoutside.md)           | Resize the image proportionally so that the content fits the target area. The [VideoPlayer](/engine/6000.6/script-reference/unityengine/video/videoplayer.md) automatically crops the image if needed. |
| [FitVertically](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/fitvertically.md)     | Resize the image proportionally so that the height fits the target area.                                                                                                                               |
| [NoScaling](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/noscaling.md)             | Preserve the pixel size without adjusting for target area.                                                                                                                                             |
| [Stretch](/engine/6000.6/script-reference/unityengine/video/videoaspectratio/stretch.md)                 | Resize the image non-proportionally to fit the target area.                                                                                                                                            |
