Skip to main content

What Problem Does This Solve?

Mobile users hold their devices in portrait (vertical) or landscape (horizontal) orientation. Social media platforms like Instagram Stories, TikTok, and YouTube Shorts expect vertical video (9:16), while traditional YouTube prefers horizontal (16:9). LckCameraOrientation lets you set the output orientation to match how users hold their device or the platform they’re targeting.

When to Use This

Use LckCameraOrientation when:
  • Building a mobile app with recording/streaming
  • Supporting social media uploads (TikTok, Instagram, Snapchat)
  • Users can rotate their device during gameplay
  • Creating platform-specific content (vertical for Stories, horizontal for YouTube)
Skip this if you’re desktop-only or always output the same orientation.

Quick Example

// Switch to portrait for TikTok/Instagram Stories
var result = lckService.SetCameraOrientation(LckCameraOrientation.Portrait);
if (!result.IsOk)
{
    Debug.LogError($"Failed to set orientation: {result.Message}");
}

// Switch to landscape for YouTube
lckService.SetCameraOrientation(LckCameraOrientation.Landscape);

How It Works

Camera orientation determines the aspect ratio of the output video: Portrait (Vertical)
  • Aspect ratio: 9:16 (e.g., 1080×1920)
  • Matches vertical phone orientation
  • Best for: TikTok, Instagram Stories, Snapchat, Reels
Landscape (Horizontal)
  • Aspect ratio: 16:9 (e.g., 1920×1080)
  • Matches horizontal phone orientation
  • Best for: YouTube, traditional video platforms
The orientation affects how the resolution is interpreted. A CameraResolutionDescriptor(1080, 1920) in portrait mode outputs vertical video, while landscape swaps it to 1920×1080.

Common Patterns

Auto-detect device orientation

void Update()
{
    var currentOrientation = Input.deviceOrientation;
    
    if (currentOrientation == DeviceOrientation.Portrait || 
        currentOrientation == DeviceOrientation.PortraitUpsideDown)
    {
        lckService.SetCameraOrientation(LckCameraOrientation.Portrait);
    }
    else if (currentOrientation == DeviceOrientation.LandscapeLeft || 
             currentOrientation == DeviceOrientation.LandscapeRight)
    {
        lckService.SetCameraOrientation(LckCameraOrientation.Landscape);
    }
}

Platform-specific orientation

public enum SharePlatform
{
    TikTok,
    Instagram,
    YouTube,
    Twitter
}

void SetOrientationForPlatform(SharePlatform platform)
{
    var orientation = platform switch
    {
        SharePlatform.TikTok => LckCameraOrientation.Portrait,
        SharePlatform.Instagram => LckCameraOrientation.Portrait,
        SharePlatform.YouTube => LckCameraOrientation.Landscape,
        SharePlatform.Twitter => LckCameraOrientation.Landscape,
        _ => LckCameraOrientation.Landscape
    };
    
    lckService.SetCameraOrientation(orientation);
    Debug.Log($"Set {orientation} orientation for {platform}");
}

UI toggle

public class OrientationToggle : MonoBehaviour
{
    public Toggle portraitToggle;
    
    void Start()
    {
        portraitToggle.onValueChanged.AddListener(OnOrientationChanged);
    }
    
    void OnOrientationChanged(bool isPortrait)
    {
        var orientation = isPortrait 
            ? LckCameraOrientation.Portrait 
            : LckCameraOrientation.Landscape;
        
        var result = lckService.SetCameraOrientation(orientation);
        
        if (!result.IsOk)
        {
            Debug.LogError($"Failed to change orientation: {result.Message}");
            portraitToggle.isOn = !isPortrait; // Revert toggle
        }
    }
}

Resolution by Orientation

Portrait (9:16)
// Common portrait resolutions
new CameraResolutionDescriptor(720, 1280)   // HD vertical
new CameraResolutionDescriptor(1080, 1920)  // Full HD vertical
Landscape (16:9)
// Common landscape resolutions
new CameraResolutionDescriptor(1280, 720)   // HD horizontal
new CameraResolutionDescriptor(1920, 1080)  // Full HD horizontal
Make sure your resolution descriptor matches your intended orientation. A 1920×1080 resolution in portrait mode will output vertical video at 1080×1920.

Platform Orientation Guidelines

PlatformPreferred OrientationAspect RatioResolution
TikTokPortrait9:161080×1920
Instagram StoriesPortrait9:161080×1920
Instagram ReelsPortrait9:161080×1920
YouTube ShortsPortrait9:161080×1920
SnapchatPortrait9:161080×1920
YouTubeLandscape16:91920×1080
Twitter/XLandscape16:91280×720
TwitchLandscape16:91920×1080

Enum Values

ValueDescriptionAspect RatioUse Case
PortraitVertical orientation (tall)9:16Mobile-first, social media stories
LandscapeHorizontal orientation (wide)16:9Traditional video, YouTube, desktop

API Reference

Set Orientation

LckResult SetCameraOrientation(LckCameraOrientation orientation)
Parameters:
  • orientationPortrait or Landscape
Returns: LckResult indicating success/failure

Best Practices

Match target platform — Use portrait for TikTok, landscape for YouTube
Set before recording — Orientation should be configured before starting capture
Test both modes — Ensure your UI works in both orientations
Don’t change during recording — Stop recording before switching orientation

Good Pattern

// Check if recording before changing
bool isRecording = lckService.IsRecording();
if (isRecording)
{
    Debug.LogWarning("Cannot change orientation during recording");
    return;
}

var result = lckService.SetCameraOrientation(newOrientation);
if (result.IsOk)
{
    Debug.Log($"Orientation set to {newOrientation}");
}

Mobile Development Tips

Lock orientation in Unity

// Lock to portrait
Screen.orientation = ScreenOrientation.Portrait;
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = false;
Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;

// Lock to landscape
Screen.orientation = ScreenOrientation.LandscapeLeft;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;

Handle safe areas

// Adjust UI for notches and rounded corners
var safeArea = Screen.safeArea;
rectTransform.anchoredPosition = new Vector2(
    safeArea.x, 
    safeArea.y
);