Screen Recording
- If you attach a render texture to the camera, everything the camera sees gets output to that texture. Then you can take a texture from the rendertexture, and change that to a on or jpeg.
- How to save a picture (take screenshot) from a camera in game? - Unity Answers (From answers.unity3d.com)
- There's a script for taking screenshots on the Unifycommunity Wiki: TakeScreenshot . The method used to do this is: Application.CaptureScreenshot, [EDIT: Which also has a parameter superSize for high resolution screenshots using an integer multiple of the current screen resolution].
- It also shouldn't be too hard to post those screenshots to combine this with the example code in the WWWForm-documentation to post those screenshots to a server.
- There's also an approach to do [-high resolution-] screenshots [EDIT: with any arbitrary resolution]. I have a script which is based on the script posted in Submitting featured content. This will take a screenshot and store it to disk when you press the key "k" (you could change the key by changing the code). You have to attach the script to a camera for it to work:
using UnityEngine; using System.Collections; public class HiResScreenShots : MonoBehaviour { public int resWidth = 2550; public int resHeight = 3300; private bool takeHiResShot = false; public static string ScreenShotName(int width, int height) { return string.Format("{0}/screenshots/screen_{1}x{2}_{3}.png", Application.dataPath, width, height, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); } public void TakeHiResShot() { takeHiResShot = true; } void LateUpdate() { takeHiResShot |= Input.GetKeyDown("k"); if (takeHiResShot) { RenderTexture rt = new RenderTexture(resWidth, resHeight, 24); camera.targetTexture = rt; Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); camera.Render(); RenderTexture.active = rt; screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); camera.targetTexture = null; RenderTexture.active = null; // JC: added to avoid errors Destroy(rt); byte[] bytes = screenShot.EncodeToPNG(); string filename = ScreenShotName(resWidth, resHeight); System.IO.File.WriteAllBytes(filename, bytes); Debug.Log(string.Format("Took screenshot to: {0}", filename)); takeHiResShot = false; } } }
- If you need to record video AZScreenrecorder is free and pretty good. You can also do screen recording through ADB, but that requires you to be connected to a computer
- adb shell screencap /sdcard/screen.png
- adb shell screenrecord /sdcard/demo.mp4
- screenrecord has options
- If you need to add video recording to a Unity App “Images2Video” has a rendertexture recording script.
- If you’re using C or Java you look into the media codec documentation for really low level stuff, if you’re feeling adventurous.
page revision: 2, last edited: 11 Aug 2017 04:00