After exporting VideoAsset:
the issues:
- Video orientation is not original transform
- Exported Video's layer seems to be always landscape.
trying to:
- transform video layer orientation - rotate to original orientation
- video layer size - make it full screen size (by original orientation)
some notes:
- videoAsset's CGRect is opposite from beginning.
after export, video transform is wrong
tried to rotate with no success for full size layer
AVURLAsset*videoAsset = [[AVURLAsset alloc]initWithURL:url options:nil];
AVMutableComposition* mixComposition = [AVMixerBase compositionVideoTrackAssetUrl:videoAsset];
AVMutableVideoComposition *videoComposition=[AVMutableVideoComposition videoComposition];
videoComposition.frameDuration=CMTimeMake(1, 30); //frames per seconds
videoComposition.renderSize = videoAsset.naturalSize;
//videoComposition.renderScale = 1.0;
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
AVMutableCompositionTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; //was AVAssetTrack *videoTrack
AVMutableVideoCompositionLayerInstruction *layerInstruction = [self layerInstructionAfterFixingOrientationForAsset:videoAsset
forTrack:videoTrack atTime:videoAsset.duration];
AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
[layerInstruction setTransform:videoTrack.preferredTransform atTime:kCMTimeZero];
[layerInstruction setOpacity:0.0 atTime:videoAsset.duration];
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [videoAsset duration]);
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
videoComposition.instructions = [NSArray arrayWithObject:instruction];
setting the track
+(AVMutableComposition *)compositionVideoTrackAssetUrl:(AVURLAsset*)assetUrl{
AVMutableComposition* mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *clipVideoTrack = [[assetUrl tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *clipAudioTrack = [[assetUrl tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetUrl.duration) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetUrl.duration) ofTrack:clipAudioTrack atTime:kCMTimeZero error:nil];
[compositionVideoTrack setPreferredTransform:[[[assetUrl tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]];
return mixComposition;
}
so after researching all stack overflow discussions about export rotation,
I'm still having video rotation to size issue...