Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player_avfoundation] Applies the standardized transform for videos with different orientations #5069

Merged
merged 11 commits into from
Apr 19, 2022

Conversation

AlexV525
Copy link
Member

@AlexV525 AlexV525 commented Mar 18, 2022

Fixes flutter/flutter#71299.

Changes:

  • Split a standalone category (AVAssetTrack+Utils).
  • Add the FakeAVAssetTrack in the test.
  • Tested with all values of UIImageOrientation.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@AlexV525 AlexV525 changed the title [video_player] Always apply preferred transform on iOS [video_player] Apply natural size transform with 90/270 degrees orientated videos on iOS Mar 18, 2022
@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch from e8cf3ac to a80dd47 Compare March 18, 2022 05:06
@AlexV525
Copy link
Member Author

AlexV525 commented Mar 18, 2022

/cc @jmagman Would a test like: Test if transform.tx equals to naturalSize.height effective? Also, we might need a vertical taken video for this fix. The current fix only works like magic. 🪄

@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch 2 times, most recently from a80dd47 to 7c1211e Compare March 18, 2022 08:27
@AlexV525 AlexV525 changed the title [video_player] Apply natural size transform with 90/270 degrees orientated videos on iOS [video_player] Apply transform accordingly for videos Mar 18, 2022
@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch 2 times, most recently from 75aa03b to f984752 Compare March 20, 2022 08:38
@AlexV525 AlexV525 marked this pull request as ready for review March 20, 2022 08:38
@AlexV525
Copy link
Member Author

The current test only tests with the existing video's transform in the new case. If we want to cover more cases, we might need another video for this test.

@AlexV525 AlexV525 requested a review from jmagman March 20, 2022 08:40
@jmagman
Copy link
Member

jmagman commented Mar 22, 2022

Can you confirm that the reproduction case in flutter/flutter#17606 is not regressed?

@AlexV525
Copy link
Member Author

Can you confirm that the reproduction case in flutter/flutter#17606 is not regressed?

This fix does not change the orientation of videos, since it does not manipulate with a, b, c, d of the CGAffineTransform. Though I'll post more screenshots with more cases later.

@AlexV525
Copy link
Member Author

I didn't get the time to make screenshots, but based on the comment at fluttercandies/flutter_photo_manager#685 (comment), all cases are well addressed.

@jmagman jmagman requested a review from hellohuanlin March 23, 2022 21:41
@hellohuanlin
Copy link
Contributor

@AlexV525 I checked out your code and replaced the example remote url to https://squiredev.com/golf.mp4, but still got the same issue

Simulator Screen Shot - iPod touch (7th generation) - 2022-03-23 at 17 41 09

@AlexV525
Copy link
Member Author

AlexV525 commented Mar 24, 2022

@AlexV525 I checked out your code and replaced the example remote url to https://squiredev.com/golf.mp4, but still got the same issue

@hellohuanlin Did you override the avfoundation to the local path in the example? With the video you provided, I got the correct display on my device.

D997FCCE6F3C744B4D0C156E09188EFE.mp4

@hellohuanlin
Copy link
Contributor

@AlexV525 I checked out your code and replaced the example remote url to https://squiredev.com/golf.mp4, but still got the same issue

@hellohuanlin Did you override the avfoundation to the local path in the example? With the video you provided, I got the correct display on my device.

D997FCCE6F3C744B4D0C156E09188EFE.mp4

Not sure what you mean by "override the avfoundation to the local path. can you share the code?

@AlexV525
Copy link
Member Author

Not sure what you mean by "override the avfoundation to the local path. can you share the code?

In video_player/example/pubspec.yaml, add the following code and run flutter pub get again:

dependency_overrides:
  video_player_avfoundation:
    path: ../../video_player_avfoundation

@AlexV525

This comment was marked as duplicate.

@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch from 5483df7 to a91fa2c Compare March 25, 2022 13:05
@AlexV525
Copy link
Member Author

I've done a further investigation about what is the preferredTransform represents in a video track. It turns out it's corresponding to UIImage.Orientation, each case mentioned in the answer correspond to an orientation case. So I've made four videos and manipulated them with rotations, splitting all cases out with comments for better understanding.

@AlexV525 AlexV525 requested a review from hellohuanlin March 25, 2022 13:11
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I hit the wrong button with my last comments; they were intended to be "request changes" not "approve", as I don't think this has sufficient test coverage.

@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch from a91fa2c to d45e721 Compare March 26, 2022 13:37
@AlexV525 AlexV525 marked this pull request as draft April 7, 2022 16:26
* on iOS 14 and above. This method provide a standardized transform
* according to the orientation of the track.
*/
static CGAffineTransform FLTGetStandardizedTransformForTrack(AVAssetTrack *track) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static function is internal to the compilation unit (this file), so can't be access from the test. You need a public declaration of this in a header, just as you do for ObjC classes you want to use in other files.

You should have a separate AVAssetTrackUtils.h and AVAssetTrackUtils.m where you declare and implement this, just as you did when you had it as a category, just using a (non-static) function like this instead of a category.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That helps a lot

@AlexV525 AlexV525 marked this pull request as ready for review April 8, 2022 02:48
/**
* Note: https://stackoverflow.com/questions/64161544
* `AVAssetTrack.preferredTransform` can have wrong `tx` and `ty`
* on iOS 14 and above. This function provides a standardized transform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh just double check - have you tested both iOS 14+ and earlier OS version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I can only and have tested this on iOS14+...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try it on earlier OS. could you please hold this PR for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try it on earlier OS. could you please hold this PR for now?

Sure. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on iOS 13.7 and it worked. I am curious where is this "iOS 14 and above" coming from?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one: "used to be broken and now is working"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try iOS 12 too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shows a blank video on iOS 12.4. Same result with or without this fix.

ios 12 with the change

Copy link
Member Author

@AlexV525 AlexV525 Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me update the comment then.

it shows a blank video on iOS 12.4. Same result with or without this fix.

Maybe we can file another issue to track this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good if you think it's unrelated.

@AlexV525 AlexV525 requested a review from stuartmorgan-g April 12, 2022 02:15
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits.

@AlexV525 AlexV525 force-pushed the fix-ios-video-transform branch from eb0fb1d to b801da1 Compare April 19, 2022 03:30
@AlexV525 AlexV525 changed the title [video_player] Apply transform accordingly for videos [video_player_avfoundation] Applies the standardized transform for videos with different orientations Apr 19, 2022
@AlexV525 AlexV525 added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 19, 2022
@fluttergithubbot fluttergithubbot merged commit 06257dd into flutter:main Apr 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2022
LoPat-Airgram pushed a commit to mindcruiser/plugins that referenced this pull request Apr 19, 2022
* master: (153 commits)
  Roll Flutter from fd360c4 to ef5a6da (1 revision) (flutter#5298)
  [video_player_avfoundation] Applies the standardized transform for videos with different orientations (flutter#5069)
  Roll Flutter from 3752fb7 to fd360c4 (2 revisions) (flutter#5295)
  Roll Flutter from 3c4d7a1 to 3752fb7 (11 revisions) (flutter#5294)
  Add owners for Android implementations (flutter#5293)
  Roll Flutter from f4875ae to 3c4d7a1 (2 revisions) (flutter#5292)
  [video_player_web] Stop buffering when browser canPlayThrough. (flutter#5068)
  Roll Flutter from aa5d7b6 to f4875ae (1 revision) (flutter#5289)
  Roll Flutter from 44be0b8 to aa5d7b6 (12 revisions) (flutter#5286)
  Roll Flutter from ec8289c to 44be0b8 (2 revisions) (flutter#5284)
  Roll Flutter from 329ceae to ec8289c (26 revisions) (flutter#5283)
  [flutter_plugin_tools] Preserve Dart SDK version in all-plugins-app (flutter#5281)
  [webview_flutter_wkwebview] Implements the `HostApis` and methods for the `CookieManager`. (flutter#5244)
  [webview_flutter_wkwebview] Implement `WKNavigationDelegate.didFinishNavigation` as a proof of concept for callback methods (flutter#5199)
  Roll Flutter from 08e467d to 2b83332 (5 revisions) (flutter#5270)
  Roll Flutter from e2d1206 to 08e467d (1 revision) (flutter#5268)
  Roll Flutter from ff9d6e5 to e2d1206 (2 revisions) (flutter#5266)
  Roll Flutter from 0575932 to ff9d6e5 (1 revision) (flutter#5265)
  [local_auth] Refactor package to make use of new platform interface and native implementations (flutter#4701)
  Roll Flutter from cb968c5 to 0575932 (1 revision) (flutter#5263)
  ...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2022
@AlexV525 AlexV525 deleted the fix-ios-video-transform branch April 25, 2022 04:55
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: video_player platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[video_player] Edited videos are distorted when played on iOS
5 participants