Skip to content

[camera] Add framesPerSecond parameter to CameraImageStreamOptions #176148

Closed
flutter/packages
#10301

Description

@TecHaxter

The CameraImageStreamOptions class in camera_platform_interface currently lacks a mechanism to specify the desired frames per second (FPS) for the camera image stream. This limitation prevents developers from controlling the frame rate of the image data received from the camera, which is crucial for various use cases requiring specific performance or resource management.

Proposed Solution:
Introduce a framesPerSecond parameter (e.g., an int or double) to the CameraImageStreamOptions class. This parameter would allow clients to request a specific frame rate for the image stream.

// ... existing code ...
@immutable
class CameraImageStreamOptions {
  /// Creates a new instance with the given frame rate.
  ///
  /// The [framesPerSecond] parameter specifies the desired frame rate for the
  /// camera image stream. The platform will attempt to achieve this rate,
  /// but it is not guaranteed. A value of null indicates that the platform
  /// should use its default frame rate.
  const CameraImageStreamOptions({this.framesPerSecond});

  /// The desired frames per second for the camera image stream.
  ///
  /// If null, the platform will use its default frame rate.
  final double? framesPerSecond;
}
// ... existing code ...

Use Cases in camera packages:

  • @camera/camera_web:

    • Browser API Integration: This parameter would allow camera_web to pass the desired FPS, providing more control over the streaming of image frames.
    • Video Conferencing: For web-based video conferencing applications, controlling the frame rate can optimize bandwidth usage and improve performance in varying network conditions.
  • @camera/camera_avfoundation (iOS/macOS):

    • AVFoundation Control: AVCaptureDevice on iOS/macOS allows setting activeVideoMinFrameDuration and activeVideoMaxFrameDuration to control the capture frame rate. Implementing framesPerSecond would enable camera_avfoundation to configure these properties, providing fine-grained control over camera input.
    • High-Speed Video: Applications requiring high-speed video capture or specific cinematic effects could leverage precise FPS control.
  • @camera/camera_android_camerax (Android CameraX):

    • CameraX Use Cases: CameraX's Preview, ImageCapture, and ImageAnalysis use cases can be configured with target frame rates. This parameter would allow camera_android_camerax to set appropriate frame rate hints for CameraX, leading to optimized camera performance and power consumption.
    • Computer Vision: For AI/ML applications performing real-time image analysis, a consistent and controlled frame rate is essential for predictable model inference.
  • @camera/camera_windows (Windows):

    • Windows Media Foundation: The Windows camera APIs (e.g., via Windows Media Foundation) allow configuring frame rates for video streams. camera_windows could map framesPerSecond to the appropriate Windows API calls, ensuring proper frame rate negotiation with the camera hardware.
    • Custom Applications: Windows applications requiring specific frame rates for recording or streaming could benefit from this control.
  • @camera/camera_android (Android Camera1/2):

    • Legacy API Support: Even older Android Camera1 and Camera2 APIs offer ways to set preview or capture frame rates (e.g., setPreviewFpsRange in Camera1, CONTROL_AE_TARGET_FPS_RANGE in Camera2). The framesPerSecond parameter would enable camera_android to configure these settings, supporting a wider range of Android devices and API levels.
    • Resource Management: On resource-constrained Android devices, lowering the frame rate can reduce CPU and power consumption.

Considerations:

  • Platform Support: Not all platforms or camera devices may support arbitrary frame rates. The implementation should gracefully handle unsupported requests, potentially by clamping the requested FPS to an available range or falling back to a default.
  • Negotiation: The actual frame rate achieved might differ from the requested one due to hardware limitations or other active camera streams. The platform implementation should aim for the closest possible match.
  • Default Behavior: If framesPerSecond is not provided, the platform should use its default or preferred frame rate.

Activity

  1. changed the title [-][camera_platform_interface]: Add framesPerSecond parameter to CameraImageStreamOptions[/-] [+][camera_platform_interface] Add framesPerSecond parameter to CameraImageStreamOptions[/+] on Sep 27, 2025
  2. added
    in triagePresently being triaged by the triage team
    packageflutter/packages repository. See also p: labels.
    c: new featureNothing broken; request for a new capability
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Sep 29, 2025
  3. tirth-patel-nc commented on Sep 29, 2025

    @tirth-patel-nc
    Member

    @TecHaxter thanks for the report. labelling it as a new proposal.

  4. changed the title [-][camera_platform_interface] Add framesPerSecond parameter to CameraImageStreamOptions[/-] [+][camera] Add framesPerSecond parameter to CameraImageStreamOptions[/+] on Sep 30, 2025
  5. added
    P2Important issues not at the top of the work list
    on Sep 30, 2025
  6. Remi-Coulom commented on Oct 2, 2025

    @Remi-Coulom

    I can give some data in support for this proposal. We are developing an image-recognition system using machine learning, and after developing a native Android prototype, we are now working on a Flutter version. But we are having very significant performance problems with the Flutter version. Here is CPU usage measured with adb shell top (Pixel 5):

    Our native app, capturing at 10 fps, can actually process 8-9 frames per second, CPU usage:
    57% [email protected]
    110% our native Android app

    (Image recognition is one single CPU thread, the additional 10% is probably Android display + bitmap conversion to ARGB)

    Flutter app, capturing at 30 fps, can actually process 5.5 frames per second:
    129% [email protected]
    249% our Flutter app.

    So the Flutter app is much slower, while consuming twice more CPU power. It is likely that not all the performance loss is coming from the high fps of Flutter, but being able to reduce it would certainly help a lot. It is not clear what is the source of the 149% CPU overhead in the Flutter app, but if this could also be divided by 3 by reducing the frame rate, then that would make Flutter usable for our purpose.

  7. github-actions commented on Dec 10, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions