AVFoundation exporting orientation wrong

前端 未结 2 1832
不思量自难忘°
不思量自难忘° 2021-02-03 10:29

I\'m attempting to combine an image and a video. I have them combining and exporting however it\'s rotated side ways.

Sorry for the bulk code paste. I\'ve seen answers

2条回答
  •  無奈伤痛
    2021-02-03 11:02

    here is the document for the orientation at Apple:

    https://developer.apple.com/library/ios/qa/qa1744/_index.html

    if your original video was taken in portrait mode iOS, it's nature size will still be landscape, but it comes with a metadata of rotate in the mov file. In order to rotate your video, you need to make changes to your 1st piece of code with the following:

    videoLayer.frame    = CGRectMake(0, 0, videoSize.height, videoSize.width) //notice the switched width and height
    ...
    videoComp.renderSize = CGSizeMake(videoSize.height,videoSize.width) //this make the final video in portrait
    ...
    layerInstruction.setTransform(videoTrack.preferredTransform, atTime: kCMTimeZero) //important piece of information let composition know you want to rotate the original video in output
    

    Yes, you are really close!

提交回复
热议问题