@@ -154,19 +154,27 @@ - (CGAffineTransform)fixTransform:(AVAssetTrack*)videoTrack {
154154 // At least 2 user videos show a black screen when in portrait mode if we directly use the
155155 // videoTrack.preferredTransform Setting tx to the height of the video instead of 0, properly
156156 // 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 (@" Adding translation to compensate rotation. Rotation = %ld . Natural (width, height) = "
162+ @" (%f , %f )" ,
163+ (long )rotationDegrees, videoTrack.naturalSize .width , videoTrack.naturalSize .height );
164+ NSLog (@" Uncompensated transform (a, b, c, d, tx, ty) = (%f , %f , %f , %f , %f , %f )" , transform.a ,
165+ transform.b , transform.c , transform.d , transform.tx , transform.ty );
161166 if (rotationDegrees == 90 ) {
162- NSLog (@" Setting transform tx" );
163167 transform.tx = videoTrack.naturalSize .height ;
164168 transform.ty = 0 ;
169+ } else if (rotationDegrees == 180 ) {
170+ transform.tx = videoTrack.naturalSize .width ;
171+ transform.ty = videoTrack.naturalSize .height ;
165172 } else if (rotationDegrees == 270 ) {
166- NSLog (@" Setting transform ty" );
167173 transform.tx = 0 ;
168174 transform.ty = videoTrack.naturalSize .width ;
169175 }
176+ NSLog (@" Compensated transform (a, b, c, d, tx, ty) = (%f , %f , %f , %f , %f , %f )" , transform.a ,
177+ transform.b , transform.c , transform.d , transform.tx , transform.ty );
170178 }
171179 return transform;
172180}
0 commit comments