Search Unity

Question Failed to record tagged camera via recorder

Discussion in 'Audio & Video' started by mikoajciszek, Oct 9, 2022.

  1. mikoajciszek

    mikoajciszek

    Joined:
    May 2, 2022
    Posts:
    2
    Hi,

    I am tring to manage the recording from the selected camera.

    The goal: I have a few cameras in the scene and I need to capture video from all of them.

    What I tried: I wrote the script which is rendering mp4 file for all cameras based on their tags but all of them have a black screen after the recording is finished. Then I used a recorder (version: 3.0.3), select TaggedCamera as a source and record the animation (to verify if it works at all for tagged camera)
    upload_2022-10-9_14-25-59.png upload_2022-10-9_14-27-58.png



    The problem: Every time the mp4 has a black screen. Only if I select display, in game mode, which contains the view from this camera, then the mp4 file is correct, so it seems like the recorder always takes the game view. Is it a common bug?
     
  2. mikoajciszek

    mikoajciszek

    Joined:
    May 2, 2022
    Posts:
    2
    And here is my script which suppose to record from all selected cameras.

    Code (CSharp):
    1. public class MovieRecorder : MonoBehaviour
    2. {
    3.     RecorderController m_RecorderController;
    4.     public bool m_RecordAudio = true;
    5.     //internal MovieRecorderSettings m_Settings = null;
    6.     protected List<GameObject> cameras = new List<GameObject>();
    7.  
    8.  
    9.     void OnEnable()
    10.     {
    11.         Initialize();
    12.     }
    13.  
    14.     internal void Initialize()
    15.     {
    16.         var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
    17.         m_RecorderController = new RecorderController(controllerSettings);
    18.  
    19.         var mediaOutputFolder = new DirectoryInfo(Path.Combine(Application.dataPath, "..", "SampleRecordings"));
    20.         foreach (Transform child in transform)
    21.         {
    22.             cameras.Add(child.gameObject);
    23.         }
    24.         foreach (var camera in cameras)
    25.         {
    26.            // Video
    27.             var videoRecorder = ScriptableObject.CreateInstance<MovieRecorderSettings>();
    28.             videoRecorder.name = camera.name;
    29.             videoRecorder.Enabled = true;
    30.  
    31.             videoRecorder.CaptureAlpha = true;
    32.  
    33.             // This example performs an MP4 recording
    34.             videoRecorder.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4;
    35.             videoRecorder.VideoBitRateMode = VideoBitrateMode.High;
    36.  
    37.             print(camera.tag);
    38.             videoRecorder.ImageInputSettings = new CameraInputSettings
    39.             {
    40.                 Source = ImageSource.TaggedCamera,
    41.                 OutputWidth = 1920,
    42.                 OutputHeight = 1080,
    43.                 CameraTag = camera.tag
    44.                 //RecordTransparency = false,
    45.                 //CaptureUI = false,
    46.                 //FlipFinalOutput = false
    47.             };
    48.  
    49.             videoRecorder.AudioInputSettings.PreserveAudio = m_RecordAudio;
    50.  
    51.             // Simple file name (no wildcards) so that FileInfo constructor works in OutputFile getter.
    52.             videoRecorder.OutputFile = mediaOutputFolder.FullName + "/" + "video_" + camera.name;
    53.  
    54.  
    55.             // Setup Recording
    56.             controllerSettings.AddRecorderSettings(videoRecorder);
    57.  
    58.             //Debug.Log($"Started recording for file {OutputFile.FullName}");
    59.         }
    60.  
    61.         controllerSettings.SetRecordModeToManual();
    62.         controllerSettings.FrameRate = 60.0f;
    63.  
    64.         RecorderOptions.VerboseMode = false;
    65.         m_RecorderController.PrepareRecording();
    66.         m_RecorderController.StartRecording();
    67.     }
    68.  
    69.     void OnDisable()
    70.     {
    71.         m_RecorderController.StopRecording();
    72.     }
    73. }
    74.  
     
  3. rooose

    rooose

    Unity Technologies

    Joined:
    Jun 8, 2022
    Posts:
    30
    mikoajciszek likes this.
  4. timvaire

    timvaire

    Joined:
    Jun 5, 2020
    Posts:
    1
    Hey :) I recorded videos with 3-6 cameras, each assigned different tags, and they worked without problems. The main purpose was to set different culling masks for each camera and then create a single video in After Effects from these clips with opacity transitions between them. For example, I had a sad, grey environment and a happy, colorful environment.

    However, when I attempted the same process in Unity version 2021.3.27f1 with URP, I encountered black screens for each video. I tried everything but had no success :( The only workaround was to use only one camera with a game view and change the culling mask every time. However, because the gameplay varied each time, I was forced to create a Timeline with prepared animations.

    What could be the problem in my case?
     
    markom_unity likes this.