Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Load video from memory

Discussion in '5.6 Beta' started by Saticmotion, Mar 27, 2017.

  1. Saticmotion

    Saticmotion

    Joined:
    Aug 27, 2014
    Posts:
    15
    I'm working on a video player in Unity. I intend to package a video with certain metadata and other related files (such as images) into a single file, so users don't have to download a bunch of separate files or unpack an archive file themselves. Problem is, I haven't yet found a way to load a video from memory, file handle, etc. Only via a URI/URL.

    So the only way I see now is to unpack a downloaded archive once into a folder, and then load from there in the future. This is certainly an option. But I'd still prefer if I could load from some kind of archive/pack format.

    What options do I have to load a video from memory/pack file/archive file?
     
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi Saticmotion!

    Have you looked at Unity's asset bundles? The scenario you are describing seems to fit the intended usage model quite well. Can you tell us what platform you are targeting for this?

    BTW, the URL source for the VideoPlayer also works for the file:// URLs so if the platform you target lets you use temporary storage and provides direct access to the filesystem, you can use this.

    Finally: I'm curious to hear why you'd want to load videos from memory: they will typically be large enough that you don't want them to sit completely in memory at a given time.

    Hope this helps and if not, get back to us with more info / questions!

    Dominique
    A/V developer at Unity
     
  3. Saticmotion

    Saticmotion

    Joined:
    Aug 27, 2014
    Posts:
    15
    Hey Dominique, thanks for your suggestions!

    Responses to your questions:

    1) I have looked into asset bundles, but as far as I can tell I can only create them from the editor. My users want to be able to create these videos + metadata themselves in the editor I'm currently programming.
    I am targeting at least Windows and Android. But I suspect OS X and iOS will also be needed in the future.

    2) I was also aware of loading from URI, and am already using this for testing other parts of the system.

    3) I should probably have used a more general term than "memory" :)
    I was looking for a clever way to pack multiple files in one, so that I could -- for example -- load only the video into memory, or provide the engine a file handle with the correct offset to start loading from. In newer versions of .NET I could have also used something like ZipArchiveEntry.Open() to get a stream to just the video.

    But after thinking some more, it seems like I have to set up a download server anyway, so in that case I can just download and store the separate files without inconveniencing my users.
     
  4. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    OK, thanks for the additional information.

    Using file:// URLs seems the best approach, then.

    Please keep in mind that reading videos from asset bundles is not yet possible in 5.6, I'll be adding this functionality in a follow-up release; hopefully 5.6.x. This will be pointed out in the release notes.

    But I will keep your usage scenario in mind: a proper generalization would be for you to pass delegates to open/read/seek/getSize operations and let you implement them as you want to read from an arbitrary source.

    Dominique
     
  5. Saticmotion

    Saticmotion

    Joined:
    Aug 27, 2014
    Posts:
    15
    That sounds like a great idea! Probably useful in a lot of other use cases as well.
     
  6. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Indeed! Just realized that developers may use this to implement their own file-level DRM mechanisms.