Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

To play video from memory

Discussion in 'General Discussion' started by inno_games, Feb 4, 2020.

  1. inno_games

    inno_games

    Joined:
    Jan 18, 2018
    Posts:
    3
    Hi, I am working on a video player in Unity. I intend to package a video with certain metadata and other related files, so users don't have to download a bunch of separate files or unpack an archive file themselves.
    I have been able to play video from url and some file.
    Problem is, I haven't yet found a way to load a video from memory. This is required for some security reasons.
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    The most likely scenario is that you'll need to implement entirety of video player from scratch (or using 3rd party decoders) if you want to do that, and you'll need to do that for every platform you want to support. That's because video player provides a high level abstraction, and you want a low level one, where you feed data into decoder in chunks.

    Given the size of videos, loading from memory is not recommended. Instead use resources or streaming assets folder.
     
    Ryiah likes this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,945
    This, and by taking this approach you'll likely introduce more security holes than if you had just used Unity's VideoPlayer with an asset bundle stored in a secure location.
     
    Deleted User likes this.
  4. inno_games

    inno_games

    Joined:
    Jan 18, 2018
    Posts:
    3
    Thanks for your responses.
    But, I want to know that there isn't any way to load video from memory and play it in unity.
    Other then using any other plug-in.
     
    Last edited: Feb 6, 2020
  5. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    As they said if you want to do that you'll have to build it yourself
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    Nope. There isn't one. I checked video player api, there's nothing. Like I said, high level abstraction. It is either URL or VideoClip, and you can't create VideoClips at runtime.

    The only way you could possibly do that is .... embedding a http server into your application, serving the in-memory file over http and then passing the address to the video player.

    And as you can imagine this is quite ugly. And not exactly secure.
     
    Ryiah likes this.
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,945
    No. If there were we would have pointed you towards it. Like @neginfinity I looked through the existing system to see if it could accept a stream of data from a location in memory (eg a byte array) but the way everything is designed it expects a VideoClip, and you cannot serialize a VideoClip.

    Checking the Unity C# source code reference shows that everything exposed concerning VideoClips is a direct reference to an internal component. Sometimes you get lucky and there is a private function you can use reflection to access that does what you want but this isn't the case here.

    https://github.com/Unity-Technologi...6a3ce5439/Modules/Video/Public/ScriptBindings
     
  8. inno_games

    inno_games

    Joined:
    Jan 18, 2018
    Posts:
    3
    Hi.. Thanks for your responses.
    Actually, the requirement is that I need to secure video and cannot put it in the apk.
    I have to put it somewhere outside from the apk in encrypted form and load the video from there, without keeping actual file somewhere. Videos file size ranges from 20 to 40 MB.
    If any plugin, link or library is available, please share.
    Any help will be greatly appreciated.
     
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    The first thing that comes to mind is put it onto external web server.