Search Unity

Recorder by scripting

Discussion in 'Scripting' started by Novakissime, Aug 29, 2022.

  1. Novakissime

    Novakissime

    Joined:
    Feb 28, 2017
    Posts:
    1
    Hello everyone, I have a problem for which I cannot find a solution.
    I have several cameras on my stage, each camera films a character who makes a single animation.
    I want to record in a .mp4 file, for each camera, the animation of my character and that just with a script that I put in an Empty object.
    Let's imagine, I launch with the player button, for each camera, Unity launches a Recorder of twenty seconds, records in a .mp4 file, then activates another camera, relaunch the scene with a Recorder of 20 secs etc etc.

    How to drive the Unity Recorder by script ?
     
  2. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    Hi Novakissime,

    You can create an empty game object, and associate it a MonoBehavior that sets up
    your recorders and starts recording on play. For example, you can setup a single recorder like so:

    Code (CSharp):
    1. var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
    2. m_RecorderController  = new RecorderController(controllerSettings);
    3.  
    4. var mediaOutputFolder = new DirectoryInfo(Path.Combine(Application.dataPath, "..", "SampleRecordings"));
    5.  
    6. // Video
    7. m_SettingsCamera1 = ScriptableObject.CreateInstance<MovieRecorderSettings>();
    8. m_SettingsCamera1.name = "Camera 1 Recorder";
    9. m_SettingsCamera1.Enabled = true;
    10.  
    11. // This example performs an MP4 recording
    12. m_SettingsCamera1.EncoderSettings = new CoreEncoderSettings
    13. {
    14.    EncodingQuality = CoreEncoderSettings.VideoEncodingQuality.High,
    15.    Codec = CoreEncoderSettings.OutputCodec.MP4
    16. };
    17. m_SettingsCamera1.CaptureAlpha = true;
    18.  
    19. // Record from a specific camera
    20. m_SettingsCamera1.ImageInputSettings = new CameraInputSettings
    21. {
    22.    OutputWidth = 320,
    23.    OutputHeight = 240,
    24.    Source = ImageSource.TaggedCamera,
    25.    CameraTag = "Camera1"
    26. };
    27.  
    28. // Simple file name (no wildcards) so that FileInfo constructor works in OutputFile getter.
    29. m_SettingsCamera1.OutputFile = mediaOutputFolder.FullName + "/" + "video";
    You can setup one setting for each character, and then start the recording like so:
    Code (CSharp):
    1. // Setup Recording
    2. controllerSettings.AddRecorderSettings(m_SettingsCamera1);
    3. controllerSettings.AddRecorderSettings(m_SettingsCamera2);
    4. //...
    5.  
    6. controllerSettings.SetRecordModeToFrameInterval(0, 1119); // 20s @ 60 FPS
    7. controllerSettings.FrameRate = 60.0f;
    8.  
    9. RecorderOptions.VerboseMode = false;
    10. m_RecorderController.PrepareRecording();
    11. m_RecorderController.StartRecording();
    For more information you can also look in the samples provided with the recorder package