Require Video Recording in Flutter Windows app

98 views Asked by At

I've integrated WebRTC for camera streaming in my Windows app. I've tried integrating the 'record_widget' (https://pub.dev/packages/record_widget) package for video recording. However, the process is slower than expected, recording videos with 'record_widget' is taking too long.

Need a faster solution for Windows app.

_convertImageToBytes() 
// This function takes too much time,

Flutter Code

Future<void> _processFrames({
    required List<Frame> frames,
    required String directoryPath,
    required Function(int) onProgressChanged,
  }) async {
    final directory = Directory(directoryPath);
    if (!await directory.exists()) {
      await directory.create(recursive: true);
    }

    final futures = <Future>[];
    final totalFrames = frames.length;
    for (var i = 0; i < totalFrames; i++) {
      final frameIndex = i + 1;
      final frame = frames[i];
      final bytesImage = await _convertImageToBytes(frame.image);
      if (bytesImage != null) {
        final bytes = bytesImage.buffer.asUint8List();
        futures.add(_writeImageToFile(bytes, frameIndex, directoryPath));
      }
      final progress =
          totalFrames == 0 ? 0 : (frameIndex / totalFrames * 100).toInt();
      onProgressChanged(progress);
    }

    await Future.wait(futures);
  }

  Future<ByteData?> _convertImageToBytes(ui.Image image) async {
    final completer = Completer<ByteData>();
    final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    completer.complete(byteData);
    return completer.future;
  }

  Future<void> _writeImageToFile(
      Uint8List bytes, int frameIndex, String directoryPath) async {
    final filePath = path.join(directoryPath, '$frameIndex.png');
    final file = File(filePath);
    await file.writeAsBytes(bytes);
  }
0

There are 0 answers