Failed to record tagged camera via recorder

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)

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?

And here is my script which suppose to record from all selected cameras.

public class MovieRecorder : MonoBehaviour
{
    RecorderController m_RecorderController;
    public bool m_RecordAudio = true;
    //internal MovieRecorderSettings m_Settings = null;
    protected List<GameObject> cameras = new List<GameObject>();


    void OnEnable()
    {
        Initialize();
    }

    internal void Initialize()
    {
        var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
        m_RecorderController = new RecorderController(controllerSettings);

        var mediaOutputFolder = new DirectoryInfo(Path.Combine(Application.dataPath, "..", "SampleRecordings"));
        foreach (Transform child in transform)
        {
            cameras.Add(child.gameObject);
        }
        foreach (var camera in cameras)
        {
           // Video
            var videoRecorder = ScriptableObject.CreateInstance<MovieRecorderSettings>();
            videoRecorder.name = camera.name;
            videoRecorder.Enabled = true;

            videoRecorder.CaptureAlpha = true;

            // This example performs an MP4 recording
            videoRecorder.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4;
            videoRecorder.VideoBitRateMode = VideoBitrateMode.High;

            print(camera.tag);
            videoRecorder.ImageInputSettings = new CameraInputSettings
            {
                Source = ImageSource.TaggedCamera,
                OutputWidth = 1920,
                OutputHeight = 1080,
                CameraTag = camera.tag
                //RecordTransparency = false,
                //CaptureUI = false,
                //FlipFinalOutput = false
            };

            videoRecorder.AudioInputSettings.PreserveAudio = m_RecordAudio;

            // Simple file name (no wildcards) so that FileInfo constructor works in OutputFile getter.
            videoRecorder.OutputFile = mediaOutputFolder.FullName + "/" + "video_" + camera.name;


            // Setup Recording
            controllerSettings.AddRecorderSettings(videoRecorder);

            //Debug.Log($"Started recording for file {OutputFile.FullName}");
        }

        controllerSettings.SetRecordModeToManual();
        controllerSettings.FrameRate = 60.0f;

        RecorderOptions.VerboseMode = false;
        m_RecorderController.PrepareRecording();
        m_RecorderController.StartRecording();
    }

    void OnDisable()
    {
        m_RecorderController.StopRecording();
    }
}

Hi,

It is a known limitation of the recorder, since it captures what is currently displayed in the game view. If it helps, you can change the target display of a camera (Unity - Scripting API: Camera.targetDisplay) and set the main display (Unity - Scripting API: Display.Activate) from your script before recording

1 Like

Hey :slight_smile: 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 :frowning: 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?

1 Like