Recording script freezes game on startup

I have an old recording script I made a long time ago, and I wanted to try it with the new Unity Timeline and stuff. I tried it, but the Editor freezes when I press Play. Is there anything I’m doing wrong?

using System;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;
public class Recorder : MonoBehaviour
{
private bool _done;
private int _frames = 1;
public int Fps = 24;
public int Frames = 100;
public string Name = “Recording”;
public bool Enabled = false;
// Use this for initialization
public void Start()
{
Time.captureFramerate = Fps;
Directory.CreateDirectory(“Output/” + Name + “/”);
Directory.CreateDirectory(“Output/” + Name + “/Video”);
}
public void Update()
{
if (_done || !Enabled) return;
var output = “Output/” + Name + “/Frame” + _frames + “.png”;
ScreenCapture.CaptureScreenshot(output);
_frames++;
if (_frames <= Frames) return;
Debug.Log(“Done recording.”);
_done = true;
var oldDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(“Output/” + Name);
Debug.Log(system(“ffmpeg -f Image2 -i Frame%d.png -vb 20M -start_number 1 Video/Output.avi”));
Directory.SetCurrentDirectory(oldDirectory);
}
[DllImport(“msvcrt.dll”, CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
private static extern int system(string command);
}

EDIT: Oh and no images actually save

Which line of code causes the problem?

Not entirely sure but removing the ScreenCapture.CaptureScreenshot() line makes it not freeze, although that doesn’t necessarily mean it’s because of that - maybe it’s being used incorrectly/too much? But I guess that’s it.

And what is the value of “output” at that point?

And of course you are trying to write out the file every frame, like 24 times a second. Does it work correctly when it saves a single time, like in a button click on during Start ?

I’ll check the value of output, and see what happens if I only record one frame. I’d also like to point out that this script worked when I last used it, in Unity 5.


Those are the frame names

If I add this before the save screenshot thing:
if (_frames > 2)
then it doesn’t freeze

It works now, but it’s very slow, is there a better way to record it?