The exported captured movie is played back only in landscape mode and rotated

Before posting a lot of code, here is the script:

  • Using the code based on AVEditDemo from WWDC, I take the movie using the standard control in the portrait.
  • I am posting a video using a code identical to the one in AVEditDemo, which uses Core Animation.

When I play the resulting video using the Camera application, it rotates 90 degrees and is no longer a โ€œportraitโ€ (now itโ€™s in the landscape) and is crushed. (The aspect ratio seems to have been changed, width โ†’ height and height โ†’ width.

Spent many hours on it, and I'm at a loss.

The desired result is a film identical to the recorded original. (With animated overlay in the end).

To see this, just download and run Appleโ€™s AVEditDemo, turn the โ€œONโ€ heading on, and export the movie.

+4
source share
1 answer

I think the short answer is this:

When processing the original video, you want to get "preferredTransform":

AVAssetTrack *sourceVideo = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo]lastObject]; CGAffineTransform *preferredTransform = [sourceVideo preferredTransform]; 

and then when you write the final video, you will do something similar to this:

 AVMutableComposition *composition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionVideoTrack setPreferredTransform:preferredTransform]; 
0
source

Source: https://habr.com/ru/post/1340610/


All Articles