Flutter Camera start record lag

Viewed 523

Perhaps this is due to my own code, I'm fairly new to flutter. I'm using the built in camera library to record video. The problem being that there is a notable lag between hitting record and the video starting to record / updating the live preview.

This lag is probably 1-3 seconds.

Our code is very simple:

void _cameraRecordPress() async {
    if (!controller.value.isInitialized) return;
    if (controller.value.isRecordingVideo) {
      controller.stopVideoRecording();
      setState(() {
        recordState = false;
      });
      String result = await Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => PostRecordPage(
                    recording: recording,
                  )));
      Navigator.pop(context, result);
      return;
    }

    final String currentTime = DateTime.now().millisecondsSinceEpoch.toString();
    final String filePath = '$videoDirectory/$currentTime.mp4';
    controller.startVideoRecording(filePath);
    recording.path = File(filePath);
    setState(() {
      recordState = true;
    });
  }

We call controller.prepareForVideoRecording(); prior to this call. This is all in the async event for the button. Is there some way to improve performance here? I can't really see a way of moving this record to the background or anything. Maybe a more complex flutter trick?

0 Answers
Related