prepareFrames method

VisionVideoInput prepareFrames(
  1. List<Uint8List> frames, {
  2. required int height,
  3. required int width,
  4. required List<int> frameIndices,
  5. required double sourceFps,
})

Resizes and groups already sampled frames: packed RGB, one size for all, taken at frameIndices of a clip at sourceFps.

Implementation

VisionVideoInput prepareFrames(
  List<Uint8List> frames, {
  required int height,
  required int width,
  required List<int> frameIndices,
  required double sourceFps,
}) {
  if (frames.length < temporalPatchSize ||
      frames.length != frameIndices.length ||
      frames.any((f) => f.length != height * width * 3) ||
      !sourceFps.isFinite ||
      sourceFps <= 0) {
    throw ArgumentError(
      'expected sampled frames of one size and their indices',
    );
  }
  final (outH, outW) = resizedSize(frames.length, height, width);
  final resized = [
    for (final frame in frames) _resizeRgb(frame, height, width, outH, outW),
  ];
  while (resized.length % temporalPatchSize != 0) {
    resized.add(resized.last);
  }
  return VisionVideoInput._(
    List.unmodifiable([
      for (var i = 0; i < resized.length; i += temporalPatchSize)
        _patchify(
          resized.sublist(i, i + temporalPatchSize),
          outH,
          outW,
          patchSize,
          mergeSize,
        ),
    ]),
    List.unmodifiable(frameIndices),
    // Upstream rounds the container's frame rate to six decimals.
    double.parse(sourceFps.toStringAsFixed(6)),
  );
}