Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Android preview aspect ratio #2964

Merged
merged 3 commits into from
Jun 12, 2024

Conversation

j-jonathan
Copy link
Contributor

What

Currently on iOS, the previewer ratio matches the video capture ratio (or the photo ratio if video mode is disabled).
This ensures that the preview corresponds to the captured result.

The idea of this pull request is to have the same behavior on Android.

Changes

The previewer uses the resolution with the aspect ratio closest to the video capture resolution (or photo resolution if video mode is disabled).

Maybe someone has a better idea, such as adding the preview resolution to the format (but this would significantly increase the number of formats) or adding a new prop to define the previewer resolution.

Tested on

  • iPhone 12, iOS 17.4.1
  • Huawei ELE-L29, Android 12

Copy link

vercel bot commented Jun 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 3:21pm

@mrousavy
Copy link
Owner

mrousavy commented Jun 11, 2024

Hi - thanks for your PR, maybe I am missing something but doesn't the PreviewView automatically match the aspect ratio of other outputs?

@j-jonathan
Copy link
Contributor Author

No, unfortunately the preview does not match the aspect ratio of the other outputs, which means that depending on the device, there can be a significant difference between the photo/video captured and what is seen in the preview at the moment of capture/recording.

@mrousavy
Copy link
Owner

I pushed a commit that cleans up the code a bit, CameraSession+Configuration is already way too big 😅

Otherwise that's cool - I am a bit hesitant about merging this because it differs from how iOS works (and how the formats documentation works).

On iOS, the Preview View size (and aspect ratio) is always bound to the format's videoWidth / videoHeight.
On Android, this is now different; it only uses the format's video size if video is enabled, otherwise it uses the format's photo size.

I think in practise it should be fine, but it is different behaviour now between iOS and Android.

I have code in ShadowLens that finds a format with a video size where the aspect ratio matches the screen aspect ratio, and this also has the assumption that the preview view uses that aspect ratio. I have video enabled so it's fine, but for people who don't have video enabled it's gonna be a different case..

Maybe I will change this in the future to always use the format's video aspect ratio so it stays consistent.

@mrousavy
Copy link
Owner

Anyways - thank you for your contribution, LGTM!!! :)

@mrousavy mrousavy merged commit 555474d into mrousavy:main Jun 12, 2024
5 checks passed
@j-jonathan
Copy link
Contributor Author

Thanks for the review and the modifications!

It's true that I adapted the code to my test case by taking the photo format when video mode is deactivated.
I will check tomorrow if all the ratios are available in video on the various Android devices I have. If so, we could have the same behavior as on iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants