rs / SDAVAssetExportSession

AVAssetExportSession drop-in replacement with customizable audio&video settings
MIT License
805 stars 212 forks source link

Videos rotated -90 degrees scaled too much #37

Closed bryanhatwood closed 9 years ago

bryanhatwood commented 9 years ago

I had a video with a rotation of -90 degrees, the preferredTransform is (a = 0, b = -1, c = 1, d = 0, tx = 0, ty = 720). The video was being scaled too much. Looking in to the code, videoAngleInDegree in buildDefaultVideoComposition gets assigned a value between -180 and 180 which becomes -90 for my video. However, the following comparison checks for 90 or 270 and my video doesn't match, resulting in a video that is scaled incorrectly.

    CGAffineTransform transform = videoTrack.preferredTransform;
    CGFloat videoAngleInDegree  = atan2(transform.b, transform.a) * 180 / M_PI;
    if (videoAngleInDegree == 90 || videoAngleInDegree == 270) {
        CGFloat width = naturalSize.width;
        naturalSize.width = naturalSize.height;
        naturalSize.height = width;
    }

Problem in above code seems to be that videoAngleInDegree can be -90 but not 270. Seems odd that this hasn't come up so I am probably missing something!

I've created a fork and will submit a pull request in case. Thanks!

bryanhatwood commented 9 years ago

This is fixed in the commit below. Thank you!

https://github.com/rs/SDAVAssetExportSession/commit/4327f4a5fce5c253bc28b6a093422bd91ace1aae