Search Unity

Question Multiple camera simultaneous recording

Discussion in 'Audio & Video' started by demoam, Jan 16, 2024.

  1. demoam

    demoam

    Joined:
    Mar 12, 2023
    Posts:
    2
    Hello!
    I'm using Unity 2021.3.20f1 as a simulation environment for my university master's thesis.

    I need to record videos from 3 different cameras during the same simulation run (simultaneously). Unfortunately, this isn't possible using Unity's built-in recorder plugin. How can I achieve this? Would it be possible to attach a script to the camera objects to save the video?

    It's crucial that the video recordings happen in parallel. Viewing the camera feed during the run is not important, as my work is focused on the video material.

    Any kind of help or suggestions would be appreciated. Thank you.
     
  2. demoam

    demoam

    Joined:
    Mar 12, 2023
    Posts:
    2
    UPDATE: I've wrote this script which should do what I meant, and although there is a warning that says that multiple video recorders can produce a crash, it's working.
    The only big problem is that the videos saved are all black. Someone knows why?

    Code (CSharp):
    1. public class MultipleCameraRecorder : MonoBehaviour
    2.     {
    3.         RecorderController m_RecorderController;
    4.  
    5.         void OnEnable()
    6.         {
    7.             var mediaOutputFolder = Path.Combine(Application.dataPath, "..", "SampleRecordings");
    8.  
    9.             var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
    10.             m_RecorderController = new RecorderController(controllerSettings);
    11.  
    12.             // Video Recorder 1
    13.             var videoRecorder1 = CreateVideoRecorder("My Video Recorder 1", "video1_v", "Camera1", mediaOutputFolder);
    14.  
    15.             // Video Recorder 2
    16.             var videoRecorder2 = CreateVideoRecorder("My Video Recorder 2", "video2_v", "Camera2", mediaOutputFolder);
    17.  
    18.             // Video Recorder 3
    19.             var videoRecorder3 = CreateVideoRecorder("My Video Recorder 3", "video3_v", "Camera3", mediaOutputFolder);
    20.  
    21.             // Setup Recording
    22.             controllerSettings.AddRecorderSettings(videoRecorder1);
    23.             //controllerSettings.AddRecorderSettings(videoRecorder2);
    24.             //controllerSettings.AddRecorderSettings(videoRecorder3);
    25.  
    26.             controllerSettings.SetRecordModeToManual();
    27.             controllerSettings.FrameRate = 60.0f;
    28.  
    29.             RecorderOptions.VerboseMode = false;
    30.             m_RecorderController.PrepareRecording();
    31.             m_RecorderController.StartRecording();
    32.         }
    33.  
    34.         void OnDisable()
    35.         {
    36.             m_RecorderController.StopRecording();
    37.         }
    38.  
    39.         private MovieRecorderSettings CreateVideoRecorder(string name, string outputFile, string cameraTag, string outputFolder)
    40.         {
    41.             var videoRecorder = ScriptableObject.CreateInstance<MovieRecorderSettings>();
    42.             videoRecorder.name = name;
    43.             videoRecorder.Enabled = true;
    44.  
    45.             videoRecorder.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4;
    46.             videoRecorder.VideoBitRateMode = VideoBitrateMode.Low;
    47.  
    48.             videoRecorder.ImageInputSettings = new CameraInputSettings
    49.             {
    50.                 Source = ImageSource.TaggedCamera,
    51.                 CameraTag = cameraTag,
    52.                 OutputWidth = 1920,
    53.                 OutputHeight = 1080
    54.             };
    55.  
    56.             videoRecorder.AudioInputSettings.PreserveAudio = true;
    57.             videoRecorder.OutputFile = Path.Combine(outputFolder, outputFile) + DefaultWildcard.Take;
    58.  
    59.             return videoRecorder;
    60.         }
    61.     }