Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Save Texture2D to disk

Discussion in 'Scripting' started by Lisi, Mar 7, 2015.

  1. Lisi

    Lisi

    Joined:
    Apr 8, 2014
    Posts:
    22
    Hi!
    I want to save a Texture2D to disk, but the convertToPNG and the convertToJPG functions are too time consuming for my application. I would like to save the Texture2D as a BMP file. How can I convert a Texture2D to a BMP? I found one forum post where someone did it with System.Drawing.BMP but how can I use System.Drawing in Unity. I tried to put the System.Drawing dll into Unity but that throws an error message.

    Further I want to ask if anyone knows a good libary to convert images to a video inside Unity.
    What I would like to do in the longterm is the following:
    - choose a framerate
    - every frame: render the animation frame accordant to the framerate
    - in postrender: savepixels to texture2d
    - in the end: create video from the textures with a choosen sound sample.

    And all of this should be faster than realtime. For example I want to render a video to disk in about 2 seconds if the animation and sound is 1 minute long. That would be the ideal case.

    Best,
    Elisabeth
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,000
  3. Lisi

    Lisi

    Joined:
    Apr 8, 2014
    Posts:
    22
    Hi! Thanks for the answer :) But I would like to write it on my own to also understand it a little bit more. I have already the texture2Ds for each frame and I can also save them as JPG on the disk, but I would like to know first how I can save them as BMP and then I would like to take FFMPEG or another program to make a video out of it. My problem is that I want to render it out more than realtime and the sound is seperate and not running in my editor. Therefore I don't know if these plugins can attach a sound file in the end and if you can tell the program to record just with 25 frames when I want to have a framerate of about 500 whereas one second of animation will be rendered in 25 frames. Do you know what I mean?
    Let's say I have an animation with 4 seconds. Then Unity shows it with the maximal possible framerate in 4 seconds, but I want to render the video out so that I make 4 * 25 = 100 images and render them in less than a second.

    Is there any possiblity to convert a Texture2D to a BMP?
    And second is there any Unity implementation of FFMPEG?
    Or is there a better way to do it?
    Best regards,
    Elisabeth