Search Unity

Question Video Encoding from Texture2D List

Discussion in 'Scripting' started by TaylorBrownMohxGames, Jun 5, 2023.

  1. TaylorBrownMohxGames

    TaylorBrownMohxGames

    Joined:
    Jun 5, 2023
    Posts:
    2
    Hello Unity Forums,

    I wasn't sure of the correct subforum to post this question, but this felt like the most fitting one.

    We are making a project running on Android using a custom display. This means that we are not using the phone screen to display the application, but an external display connected to the phone through Bluetooth. We want to implement a recording system that will allow users to record the content on the external display and play it back anywhere. Obviously, the screen recorder built into Android will not work since the application is not being displayed on the screen, so we've looked into alternative solutions.

    For a proof of concept, we are storing each frame at 30fps into a Texture2D list and we plan on encoding these frames into a video. We have looked into video encoders and found some leads, but none seem to be a solution for this particular case. For example, Unity has a built-in encoder, but it seems to be for the Editor only. We also found programs like FFMPEG that seem to do the job, but also come with additional features that would just be bloat for our application.

    My questions are as follows:

    -Is anyone aware of an efficient, lightweight software or library that can take individual Texture2D objects and encode them into a video at a set framerate?

    -If one does exist, is there any performance overhead to be aware of when storing large List<Texture2D> objects? This could obviously use a lot of memory if it gets too large, so knowing the best way to go about this would be great. I would assume you can use some sort of call/response system, where the encoder would report to the list which frames are encoded, and can free them from the list once the frame is encoded. Not sure if this is a good solution though.

    Let me know if anyone has any thoughts on the matter, thank you!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Er, that actually is FFMPEG.

    It is incredibly svelte considering all that it does.

    I suppose if you really feel like it you could recompile your own snowflake version of FFMPEG with ONLY the particular codecs you want actually enabled... that's kinda the point of open source!!

    But then you'd have to maintain your snowflake version merging in future FFMPEG changes... just use FFMPEG already.
     
    orionsyndrome likes this.
  3. TaylorBrownMohxGames

    TaylorBrownMohxGames

    Joined:
    Jun 5, 2023
    Posts:
    2
    Will give it a shot then. Thanks for the quick response