先获得原视频的方向,url为视频路径
-(NSUInteger)degressFromVideoFileWithURL:(NSURL *)url
{
NSUInteger degress = 0;
AVAsset *asset = [AVAsset assetWithURL:url];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([tracks count] > 0) {
AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
CGAffineTransform t = videoTrack.preferredTransform;
if(t.a == 0 && t.b == 1.0 && t.c == -1.0 && t.d == 0){
// Portrait
degress = 90;
}else if(t.a == 0 && t.b == -1.0 && t.c == 1.0 && t.d == 0){
// PortraitUpsideDown
degress = 270;
}else if(t.a == 1.0 && t.b == 0 && t.c == 0 && t.d == 1.0){
// LandscapeRight
degress = 0;
}else if(t.a == -1.0 && t.b == 0 && t.c == 0 && t.d == -1.0){
// LandscapeLeft
degress = 180;
}
}
return degress;
}
然后修改movieWriter的transform属性
NSInteger a= [self degressFromVideoFileWithURL:self.pathURL];
CGAffineTransform rotate = CGAffineTransformMakeRotation(a / 180.0 * M_PI );
movieWriter.transform=rotate;
这样就可以保证美颜之后的视频方向与原视频方向相同。