Skip to content

Future of the Camera Plugin (Refactor/Rework) #31225

Closed
@bparrishMines

Description

@bparrishMines
Contributor

As our team decides on the direction of the camera plugin, I wanted to create this issue to keep the community updated on our decisions and to catalog the highest requested features and issues with the current implementation.

Below are what I found are a combination of the main requested features and issues. Please feel free to let us know if there is anything else we should also consider.

We’ll update this issue when we have come up with a design.

Support Android Camera 16+:

flutter/plugins#1482
#19083

In order to support 16+, we will have to use the Camera API. (As opposed to Camera2). This comes at the expense of features only available on Camera2. The alternative would be to maintain both an api for 16-20 and 21+.

Also note that CameraX will be discussed at I/O and could be used in the Android implementation.

Support iOS Camera 8.0+

flutter/plugins#801
#20708

We currently use AVCapturePhotoOutput to take photos. For 8.0-10.0, we would need to use AVCaptureStillImageOutput.
We also use AVCaptureDeviceDiscoverySession to find available devices. We could use AVCaptureDevice.devicesWithMediaType: for 8.0-10.0.

Camera Orientation Control

flutter/plugins#1452
#27201
#25232

On iOS, this feature is controlled by AVCaptureVideoOrientation. On Android, the Camera API has setDisplayOrientation and there is no equivalent feature on the Camera2 API.

Video/Preview/Picture output sizes

flutter/plugins#1403
flutter/plugins#1186
flutter/plugins#1107
#15953
#20994

Currently we use preview presets. But, it would probably be best to expose all available formats.

Android Pause and Resume video recording (MediaRecorder)

flutter/plugins#1370

Zoom Control

flutter/plugins#1304

We would expose the zoom feature on both platforms. Similar to the above PR.

Flash

flutter/plugins#1047
#19845

We would expose the flash feature on both platforms. Similar to the above PR.

Automatic Exposure

flutter/plugins#1035

We would expose the AE feature on both platforms. Similar to the above PR.

Permission Handling (Camera/Audio)

flutter/plugins#904
flutter/plugins#837
flutter/plugins#823
#19670

The solution to this one is a little bit more complicated. Below are proposed solutions:

  1. Remove permissions from the plugin entirely. This would require users to use a separate plugin to handle permissions. Currently, there isn’t any first party plugin that supports this, but there are a few popular external ones. (e.g. permission_handler, simple_permissions)

  2. Don’t automatically handle permissions when accessing the camera, but expose the api and allow the user to ask for permissions when they want.

Auto Focus

flutter/plugins#709

We would expose the AF feature on both platforms. Similar to the above PR.

Memory Leak

#29586

Currently no solution for this, but could likely be related to not deallocating the FlutterTexture.

Provide Complex Camera Example

#19515
#18989

Expand Controls over video and image formats

flutter/plugins#1525

Direct access to image buffer when taking a photo

Activity

added this to the June 2019 milestone on Apr 17, 2019
jbts6

jbts6 commented on Apr 19, 2019

@jbts6

How about support a USB Camera?

josh-burton

josh-burton commented on Apr 19, 2019

@josh-burton
Contributor

Might be worth mentioning that there is a CameraX library for Android expected to be announced at Google IO. This might simplify implementing the Android side of things quite a bit.

bparrishMines

bparrishMines commented on Apr 23, 2019

@bparrishMines
ContributorAuthor

@fh I believe iOS and Camera2 for Android both support external cameras automatically by referencing their ids. However, I haven't tried using one yet.

https://source.android.com/devices/camera/external-usb-cameras
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture?language=objc

ghost

ghost commented on May 10, 2019

@ghost

CameraX was announced to be min api 21 , so we still need camera instead of camera2 to support 16 -to 21

Goolpe

Goolpe commented on May 17, 2019

@Goolpe

@bparrishMines there is a problem on some devices(Xiaomi, Samsung Tab...) with stopVideoRecording (camera: 0.5.2+1)
#31414
#18138
#23039
googlearchive/android-Camera2Video#46

Solution for me was

try {
  Camera.this.cameraCaptureSession.stopRepeating();
  Camera.this.cameraCaptureSession.abortCaptures();
} catch (CameraAccessException e) {
  result.error("cameraException", e.getMessage(), null);
} 

add to

private void stopVideoRecording(@NonNull final Result result) {
  if (!recordingVideo) {
    result.success(null);
    return;
  }

  try {
    recordingVideo = false;

    try {
      Camera.this.cameraCaptureSession.stopRepeating();
      Camera.this.cameraCaptureSession.abortCaptures();
    } catch (CameraAccessException e) {
      result.error("cameraException", e.getMessage(), null);
    } 
    
    mediaRecorder.stop();
    mediaRecorder.reset();
    startPreview();
    result.success(null);
  } catch (CameraAccessException | IllegalStateException e) {
    result.error("videoRecordingFailed", e.getMessage(), null);
  }
}
PerLycke

PerLycke commented on May 27, 2019

@PerLycke

camerax surely sounds promising. The amount of testing needed on different devices using the current implementation with camera2 is very resource demanding. I guess we need to figure out how to bind the preview in camerax to Flutter's texture

164 remaining items

mvanbeusekom

mvanbeusekom commented on Mar 2, 2021

@mvanbeusekom

@jdeltoft yes please it would be easier to track if we have a separate issue.

At the moment a temp file is generated when you call startVideoRecording and it’s returned as an XFile when calling the stopVideoRecording method.

jdeltoft

jdeltoft commented on Mar 9, 2021

@jdeltoft

Thanks @mvanbeusekom , i was able to get the XFile from stopVideoRecording and use that with video player to preview it. It worked suprisingly well out of the gate, but I had to be careful with my pubspec as I was including vimeo player which has older video player dependencies still. Anyway, for my case I don't really care where this file is temporarily stored, as I just want to email out a clip if the user chooses. Thanks!

amirjalali1

amirjalali1 commented on Mar 20, 2021

@amirjalali1

Is there any way to pass the video path to FFmpeg as input for the RTMP stream while recording? Is there any way to stream camera-input without recording?

wenxiangjiang

wenxiangjiang commented on Mar 27, 2021

@wenxiangjiang

Do you have any updates about usb camera?

jordanhart

jordanhart commented on Mar 28, 2021

@jordanhart

Are there any thoughts or timelines for Web and Desktop support?

bparrishMines

bparrishMines commented on Mar 29, 2021

@bparrishMines
ContributorAuthor

Since most of the issues and PRs have been closed and I want to discourage adding additional work for this issue, I'm going to go ahead and close it. For additional feature requests or bugs, please file new issues or upvote existing ones. The only issues/PRs included in this issue that are not closed or merged are:

#27201
#25232
#15953
#19515

ccadieux

ccadieux commented on Apr 27, 2021

@ccadieux

@bparrishMines The Readme.md links to this issue.

bparrishMines

bparrishMines commented on Jun 1, 2021

@bparrishMines
ContributorAuthor

Thanks, @ccadieux. I created #83722

github-actions

github-actions commented on Jul 30, 2021

@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.

locked as resolved and limited conversation to collaborators on Jul 30, 2021
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

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @stevepsharpe@juanpujol@jamesdixon@Max-Might@pkill37

      Issue actions

        Future of the Camera Plugin (Refactor/Rework) · Issue #31225 · flutter/flutter