@@ -154,19 +154,28 @@ - (CGAffineTransform)fixTransform:(AVAssetTrack*)videoTrack {
154
154
// At least 2 user videos show a black screen when in portrait mode if we directly use the
155
155
// videoTrack.preferredTransform Setting tx to the height of the video instead of 0, properly
156
156
// displays the video https://github.com/flutter/flutter/issues/17606#issuecomment-413473181
157
- if (transform.tx == 0 && transform.ty == 0 ) {
158
- NSInteger rotationDegrees = (NSInteger )round (radiansToDegrees (atan2 (transform.b , transform.a )));
159
- NSLog (@" TX and TY are 0. Rotation: %ld . Natural width,height: %f , %f " , (long )rotationDegrees,
160
- videoTrack.naturalSize .width , videoTrack.naturalSize .height );
157
+ NSInteger rotationDegrees = (NSInteger )round (radiansToDegrees (atan2 (transform.b , transform.a )));
158
+ // This prevents the video to be rendered out of the screen if the metadata contain a rotation but
159
+ // no translation to compensate the shift induced by the rotation.
160
+ if (rotationDegrees != 0 && transform.tx == 0 && transform.ty == 0 ) {
161
+ NSLog (
162
+ @" Adding translation to compensate rotation. Rotation = %ld . Natural (width, height) = "
163
+ @" (%f , %f )" ,
164
+ (long )rotationDegrees, videoTrack.naturalSize .width , videoTrack.naturalSize .height );
165
+ NSLog (@" Uncompensated transform (a, b, c, d, tx, ty) = (%f , %f , %f , %f , %f , %f )" , transform.a ,
166
+ transform.b , transform.c , transform.d , transform.tx , transform.ty );
161
167
if (rotationDegrees == 90 ) {
162
- NSLog (@" Setting transform tx" );
163
168
transform.tx = videoTrack.naturalSize .height ;
164
169
transform.ty = 0 ;
170
+ } else if (rotationDegrees == 180 ) {
171
+ transform.tx = videoTrack.naturalSize .width ;
172
+ transform.ty = videoTrack.naturalSize .height ;
165
173
} else if (rotationDegrees == 270 ) {
166
- NSLog (@" Setting transform ty" );
167
174
transform.tx = 0 ;
168
175
transform.ty = videoTrack.naturalSize .width ;
169
176
}
177
+ NSLog (@" Compensated transform (a, b, c, d, tx, ty) = (%f , %f , %f , %f , %f , %f )" , transform.a ,
178
+ transform.b , transform.c , transform.d , transform.tx , transform.ty );
170
179
}
171
180
return transform;
172
181
}
0 commit comments