Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[video_player_android] Incorrect orientation when previewing captured videos #154696

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

Open
AlexV525 opened this issue Sep 6, 2024 · 43 comments
Open
Assignees
Labels
found in release: 3.24 Found to occur in 3.24 found in release: 3.25 Found to occur in 3.25 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@AlexV525
Copy link
Member

AlexV525 commented Sep 6, 2024

Workaround

Pin video_player_android to 2.7.1.

Steps to reproduce

With the official example

  1. Run the example of camera
  2. Select a camera and record for a few seconds in portrait up.
  3. See the preview video being orientated incorrectly.

With other Flutter packages

Run the example of package:wechat_camera_picker.

Expected results

The video preview should have a correct rotation.

Actual results

The video preview shows an incorrect rotation. This is likely affected by flutter/packages#6456, and we also have similar problems with camera_android_camerax: #149177, and camera_android: #150549.

Code sample

https://github.com/flutter/packages/tree/main/packages/camera/camera/example

Screenshots or Video

Screenshots / Video demonstration
petal_20240906_092951.mp4

Logs

N/A

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.25.0-1.0.pre.270, on Microsoft Windows [Version 10.0.22631.4037], locale en-US)
    • Flutter version 3.25.0-1.0.pre.270 on channel master at X:\SDK\flutter-master
    • Upstream repository https://github.com/flutter/flutter
    • Framework revision a7cd788d80 (16 hours ago), 2024-09-05 05:57:40 -0400
    • Engine revision 34b61eb53b
    • Dart version 3.6.0 (build 3.6.0-216.0.dev)
    • DevTools version 2.39.0
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at X:\Android\SDK
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = X:\Android\SDK
    • ANDROID_SDK_ROOT = X:\Android\SDK
    • Java binary at: X:\IDEs\AndroidStudio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • All Android licenses accepted.
@huycozy huycozy added the in triage Presently being triaged by the triage team label Sep 6, 2024
@huycozy

This comment was marked as outdated.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 6, 2024
@huycozy
Copy link
Member

huycozy commented Sep 6, 2024

Re-checking this on Flutter stable 3.24.2 and master 3.25.0-1.0.pre.283, I can reproduce the issue using camera_android_camerax example.

The current plugin versions: camera_android_camerax: 0.6.8+3 and video_player_android: ^2.7.3

@huycozy huycozy added platform-android Android applications specifically p: video_player The Video Player plugin package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on team-android Owned by Android platform team fyi-ecosystem For the attention of Ecosystem team found in release: 3.24 Found to occur in 3.24 found in release: 3.25 Found to occur in 3.25 and removed waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds in triage Presently being triaged by the triage team labels Sep 6, 2024
@kwarnkham

This comment has been minimized.

@stuartmorgan-g stuartmorgan-g added the triaged-ecosystem Triaged by Ecosystem team label Sep 10, 2024
@flutter-triage-bot flutter-triage-bot bot removed fyi-ecosystem For the attention of Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Sep 10, 2024
@camsim99 camsim99 self-assigned this Sep 10, 2024
@camsim99
Copy link
Contributor

I was able to reproduce this on a Pixel. I'm confused because the preview and video rotation is correct but not the thumbnail widget that uses a VideoPlayer. I wonder if the the thumbnail widget needs the same fix as the camera preview but I can't reason about why at this moment.

@jellynoone
Copy link
Contributor

The VideoPlayer already does some correction on it's own, maybe the reported value is incorrect?

https://github.com/flutter/packages/blob/bb53e5d536aeba377b5f8877ad735973293ae200/packages/video_player/video_player/lib/video_player.dart#L864-L887

@camsim99
Copy link
Contributor

camsim99 commented Sep 11, 2024

I was able to reproduce this on a Pixel. I'm confused because the preview and video rotation is correct but not the thumbnail widget that uses a VideoPlayer. I wonder if the the thumbnail widget needs the same fix as the camera preview but I can't reason about why at this moment.

I just tried using the rotation correction that we use for the camera preview on the video player and it does not work.

The VideoPlayer already does some correction on it's own, maybe the reported value is incorrect?

https://github.com/flutter/packages/blob/bb53e5d536aeba377b5f8877ad735973293ae200/packages/video_player/video_player/lib/video_player.dart#L864-L887

This could be what's happening. If so, we'll need to ensure that no rotation correction is applied in this case.

@kwarnkham
Copy link

kwarnkham commented Sep 12, 2024

In my case, only videos captured by camera has this issue.

Videos from screen recording is ok.

Samsung Galaxy S22 Ultra
One UI 6.1
Android 14

@bishal-rumba007
Copy link

I am having same issue, I looked into my recorded video metadata and the rotation seems to be correct.
Tested on Redmi Note 9 Pro and Samsung A23. I recorded in portrait mode up but the video player orientation is incorrect.
Any updates on this?

@camsim99
Copy link
Contributor

I just tested the camera_android_camerax example app with/without a video_player_android version that supports Impeller (with 2.7.2, without 2.7.1), and I found that this only reproduces with Impeller support on video_player_android. From running the video_player_android example app, I see that the video recording is correct (I didn't test with the same recording from the camera plugin though). Next, I'll check the rotation reported by the video_player_android plugin as @/jellynoone mentioned before.

cc @matanlurey in case you have any thoughts

@kwarnkham
Copy link

I just tested the camera_android_camerax example app with/without a video_player_android version that supports Impeller (with 2.7.2, without 2.7.1), and I found that this only reproduces with Impeller support on video_player_android. From running the video_player_android example app, I see that the video recording is correct (I didn't test with the same recording from the camera plugin though). Next, I'll check the rotation reported by the video_player_android plugin as @/jellynoone mentioned before.

cc @matanlurey in case you have any thoughts

Would downgrading to 2.7.1 fix the bug?

@rogisolorzano
Copy link

Also running into this on Android API 30, flutter version 3.24.3.

Overriding video_player_android to a version that does not support impeller (2.7.1) displays the video correctly.

dependency_overrides:
  video_player_android: 2.7.1

@regis-leantechroad

This comment has been minimized.

@LiamMarega
Copy link

I was able to fix the error by adding this dependency in my pubspec.yaml in dev_dependencies:
video_player_android: 2.7.1

I'm using video_player: ^2.9.2
and by default it uses video_player_android.

If I don't put what version the latest default version is used video_player_android: 2.7.13 and this is causing me error

@camsim99
Copy link
Contributor

Made an attempt at fixing this issue in version 2.7.16. Please let me know if this does not fix your issue and a reproduction if possible! Specify video_player_android: 2.7.16 in your dependencies to try it.

@bishal-rumba007
Copy link

Made an attempt at fixing this issue in version 2.7.16. Please let me know if this does not fix your issue and a reproduction if possible! Specify video_player_android: 2.7.16 in your dependencies to try it.

@camsim99 Thanks to you, It worked!!! when will video_player update the package version? since it is using video_player_android ^2.3.5

@AndreHaueisen
Copy link

AndreHaueisen commented Oct 29, 2024

Over here, v2.7.16 works as expected when recording in landscape (yay!). However, in portrait mode, the preview appears in a ‘shrunken state,’ as if the resolution is incorrect. See the difference here:

Android

screen-20241029-091647.1.mp4

iOS - works as expected

RPReplay_Final1730204678.mov

Can anyone else see what I'm seeing?

@camsim99
Copy link
Contributor

@AndreHaueisen I think this may be an issue with the plugins assuming a recording in portrait up; I'm seeing the same thing in the camera plugin and trying to fix it right now.

Will take a look at this of course, but if anyone else sees this still let me know with any helpful reproduction info!

@akshayOnform
Copy link

akshayOnform commented Nov 6, 2024

Used video_player_android: 2.7.16 in dev_dependencies. The landscape recorded videos are working fine but potrait videos are shrunken and not taking the right resolution. Reproducible on Samsung S23 ultra (Android 14)
Flutter version 3.24

@camsim99
Copy link
Contributor

camsim99 commented Nov 6, 2024

@akshayOnform thanks for letting me know!

I suspect this is an issue with not applying this correction in cases where we need to since it looks stretched. Also because my PR did not modify anything about the ExoPlayer itself. I plan to look into it but open to other folks investigating in the meantime of course :)

@jellynoone
Copy link
Contributor

I'm experience the same issue as reported by @AndreHaueisen on the latest version of the package (on a Pixel 1).
I was trying to perform more tests to see if I can provide any useful insight and hit a blocker.

I upgraded my Android Studio to Ladybug and can no longer downgrade to 2.7.1, the version I know that works. The reason is mentioned in #148478, essentially before 2.7.7, the plugin was passing -Werror to compiler args which now manifests during build. So, someone might be stuck with a broken version if they accidentally upgraded other parts of their toolchain.

@AlexV525
Copy link
Member Author

Is it possible if we can manually release 2.7.1+1?

@AlexV525
Copy link
Member Author

I upgraded my Android Studio to Ladybug and can no longer downgrade to 2.7.1, the version I know that works. The reason is mentioned in #148478, essentially before 2.7.7, the plugin was passing -Werror to compiler args which now manifests during build. So, someone might be stuck with a broken version if they accidentally upgraded other parts of their toolchain.

On the other hand, you can still use dependency_overrides to use your own fork.

@BHznJNs
Copy link

BHznJNs commented Feb 3, 2025

Used video_player_android: 2.7.16 in dev_dependencies. The landscape recorded videos are working fine but potrait videos are shrunken and not taking the right resolution. Reproducible on Samsung S23 ultra (Android 14)

I also met this problem and maybe the reason is below:
The camera will store the recorded video as landscape whatever it is actually landscape or potrait. Meanwhile, it will store the rotation angle (0, 90, 180, 270) in the video metadata (which can be get by MediaMetadataRetriever api for Android). So we can know if a recorded video is landscape or potrait.
The real problem is, the video_player do not provide any option to adjust the width and height for the rendered video.

@alidemircantechtile

This comment has been minimized.

@alidemircantechtile

This comment has been minimized.

@jt274
Copy link

jt274 commented Feb 26, 2025

Hello, ı fixed issue for my app with that

dependency_overrides: video_player_android: 2.4.14

This may not work for many people as that version still uses the deprecated v1 embeddings. I've tested 2.6.0 and can verify the aspect ratio of videos after recording from image_picker are correct. Basically that's the latest version before impeller support was reintroduced (before later being reverted again and re-reintroduced).

Based on the issue I filed here, which I still find to be valid: #156343

Portrait videos are recorded in landscape with a flag set to tell the player to rotate the video, and impeller has seemed to have an issue with this ever since it was introduced. I'm of the opinion that videos should be recorded in the proper orientation to begin with (without a displaymatrix flag), which should fix all player issues since no rotation would be required.

@mtpultz-dunbar
Copy link

mtpultz-dunbar commented Mar 17, 2025

Thanks @jt274 usage of v2.6.0 in dependency_overrides definitely worked for us until there's a proper fix. I do see warnings appear, but for now will assume the next version bump in video_player will likely resolve it.

[IMPORTANT:flutter/shell/platform/android/platform_view_android.cc(308)] Flutter recommends migrating plugins that create and register surface textures to the new surface producer API. See https://docs.flutter.dev/release/breaking-changes/android-surface-plugins

@flutter-triage-bot flutter-triage-bot bot added the Bot is counting down the days until it unassigns the issue label Mar 22, 2025
@flutter-triage-bot
Copy link

This issue is assigned to @camsim99 but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@mtpultz-dunbar
Copy link

Wanted to report that after overriding with v2.6.0 while testing our application we started to experience fatal errors that we were not experiencing before the override related to surface leaks and memory issues. The changelog for video_player_android beyond 2.6.0 has fixes related to codec handling, surface leaks, and memory issues. I suspect based on the logs that it's related, and after removing the override we no longer get these errors, but now we're back to portrait videos being the wrong size and looking like they were zoomed in on.

@LUK3D

This comment has been minimized.

@flutter-triage-bot flutter-triage-bot bot added Bot is counting down the days until it unassigns the issue and removed Bot is counting down the days until it unassigns the issue labels Apr 6, 2025
@flutter-triage-bot
Copy link

This issue is assigned to @camsim99 but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@2tick
Copy link

2tick commented Apr 11, 2025

i am also facing same problem....if you want temporary solution, You can use this easy_video_editor package to get video aspect ratio and use it with Aspect ratio widget

@suesitran
Copy link

Facing the same problem, but it only happens to Pixel Fold.
Tested on Pixel Fold, Sony Xperia and Samsung Galaxy.

I also tried to set video_player_android to 2.6.0 and 2.4.2, none helped.

@camsim99
Copy link
Contributor

camsim99 commented May 7, 2025

Please let us know if you still see this issue in version 2.8.3. I've been wondering if #157198 impacts this issue, which that version fixes.

@flutter-triage-bot flutter-triage-bot bot removed the Bot is counting down the days until it unassigns the issue label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.24 Found to occur in 3.24 found in release: 3.25 Found to occur in 3.25 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests