Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Video Change/Detect video orientation

Discussion in 'Audio & Video' started by Red_Dragon69, Aug 22, 2018.

  1. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    65
    Hy, maybe someone experienced this already. I recorded a video with my smartphone in portrait mode. Every video player (e.g. VLC) shows the video in correct orientation. But when playing the video with the VideoPlayer component in Unity it's always rotated 90° (like it was recorded when in landscape mode). Is there a way to fix this or rotate it depending on the video resolution?

    Best regards :)
     
  2. NAKAS

    NAKAS

    Joined:
    Jan 16, 2013
    Posts:
    21
    Yes you can detect video orientation on mobile thanks to Yasirkula's great asset, Unity Native Gallery
    NativeGallery.VideoProperties NativeGallery.GetVideoProperties( string videoPath )
    https://github.com/yasirkula/UnityNativeGallery

    That being said I'm not sure if its a bug or intended but I really wish Unity URL based runtime video player importer on IOS and Android took the video rotation of mobile video into account.

    In my testing say if a portrait video gets imported via UnityNativeGallery at runtime, the NativeGallery.VideoProperties retaliation returns 90 correctly showing portrait and the width and height variables in the portrait video are flipped when queried during prepare completed and the video gets imported as a landscape video flipped 90 incorrectly. This happened on both iOS/android. I'm going to submit a bug report. Edit: Probs not going to submit a bug report as the more I look into it, it very much just feels like a design choice to not take into account video rotation metadata when import. I may do a feature request down the line.
     
    Last edited: Sep 1, 2018
    Red_Dragon69 likes this.
  3. NAKAS

    NAKAS

    Joined:
    Jan 16, 2013
    Posts:
    21
  4. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    65
    @NAKAS Thank you for your answer. This really helps me out :) Already voted for your suggestion, hopefully it will be considered.

    Best regards :)
     
  5. atorisa

    atorisa

    Joined:
    Dec 1, 2013
    Posts:
    158
    Hi, Guys! If we are using NativeGallery to get orientation by URL (file), then how to rotate it with VideoPlayer?
     
  6. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    65
    @atorisa It usually is enough to rotate the object which is rendering the video (e.g. a plane). Just scale it according to its aspect ratio and rotate it either landscape or portrait.
     
  7. atorisa

    atorisa

    Joined:
    Dec 1, 2013
    Posts:
    158
    There are some reasons by which I am not eligible to rotate/scale the object.
     
  8. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    65
    Rotate the camera then ;)
     
  9. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    3
    Anyone figure this out? My video is being rotated on import from photo gallery.