iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📹

Initial black frames when recording video on iOS with Flutter camera plugin

に公開

When recording video on iOS using Flutter's camera 0.10.3, black frames were generated at the very beginning.

I noticed this issue when I wrote a program to save the first frame as an image for a thumbnail after recording a video, and a pitch-black image was saved.

It seems that if the audio buffer arrives first with a timestamp earlier than the first video buffer, a black frame is saved.

Therefore, setting enableAudio: false to disable audio recording resolved the problem.

If you want to record both video and audio, a workaround like the following is introduced in a GitHub issue.

 if (firstTake && Platform.isIOS) {
      // Flag for first take
      firstTake = false;
      try {
        await cameraController.startVideoRecording();
        await Future.delayed(const Duration(milliseconds: 300));
        final file = await cameraController.stopVideoRecording();
        File(file.path).deleteSync();
        await cameraController.startVideoRecording();
      } on CameraException catch (e) {
        log(e.description!);
      }
      return;
    }

https://github.com/flutter/flutter/issues/57831#issuecomment-1113125562

Also, since this is an issue with the Objective-C code of the camera plugin, there was no problem when using another plugin, camerawesome.

https://pub.dev/packages/camerawesome

Discussion