Search Unity

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:
    114
    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 :)
     
    khanhuitse05 likes this.
  2. NAKAS

    NAKAS

    Joined:
    Jan 16, 2013
    Posts:
    23
    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
  3. NAKAS

    NAKAS

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

    Red_Dragon69

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

    Best regards :)
     
  5. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,023
    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:
    114
    @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. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,023
    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:
    114
    Rotate the camera then ;)
     
  9. gaglabs

    gaglabs

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

    visionnaireMedia

    Joined:
    Jul 25, 2016
    Posts:
    17
    Awesome library, I just downloaded it and solved my issue, BUT it doesn't work in UnityEditor (on MacOSX, haven't tried on Windows)
    Thank you very very much for giving it out!
     
  11. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,023
    Yes, it works only on iOS/Android.
     
    visionnaireMedia likes this.
  12. AlbertBeck

    AlbertBeck

    Joined:
    Sep 19, 2021
    Posts:
    1
    I changed the resolution on my video and that worked from 1920x1080 to 1080x1920. Everything worked perfect after that, in my VideoPlayer component