保存的视频首选转换显示纵向视频的横向

时间:2014-05-01 08:21:44

标签: ios video gpuimage

我正在使用GPUImage电影框架来保存肖像视频。即使保存在相册中的视频也是纵向模式,分辨率为720 * 1240,但在我检查该视频的首选变换时,代码中显示的是横向。以下是相应的代码

filterView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPresetMedium cameraPosition:AVCaptureDevicePositionBack ];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.shouldSmoothlyScaleOutput=YES;
videoCamera.frameRate = 30.0;
movieURL = [NSURL fileURLWithPath:pathToMovie];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(720, 1280)];
videoCamera.audioEncodingTarget = movieWriter;
[filter removeAllTargets]; 
filter = [[GPUImageRGBFilter alloc] init];
[filter forceProcessingAtSize:CGSizeMake(720, 1280)];
[videoCamera addTarget:filter];


[filter addTarget:filterView];
 [filter addTarget:movieWriter];
videoCamera.audioEncodingTarget = movieWriter;
[movieWriter startRecording];

然后当录制完成后,我停止moviewriter并将其保存在相机胶卷中。之后,当我从相机胶卷拍摄视频进行编辑时,我首先检查它的方向,然后我发现它是在风景中,该部分的代码在下面

AVURLAsset *assetClip = VD.assetForVideoMemory ;
    AVAssetTrack *clipVideoTrack = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGSize size = [clipVideoTrack naturalSize];
    CGAffineTransform rotation;
    CGAffineTransform txf = [clipVideoTrack preferredTransform];
    CGAffineTransform translateToCenter;
    CGAffineTransform mixedTransform;
    float scaleFX = 0, scaleFY =0;
    CGSize naturalSize;
    CGAffineTransform scaleXY;

// changing the height and width of the video
    if (txf.a == 0 && txf.b == 1.0 && txf.c == -1.0 && txf.d == 0)// portrait
    {
        naturalSize = CGSizeMake(clipVideoTrack.naturalSize.height, clipVideoTrack.naturalSize.width);
    }
    if (txf.a == 0 && txf.b == -1.0 && txf.c == 1.0 && txf.d == 0)// portrait upside down
    {
        naturalSize = CGSizeMake(clipVideoTrack.naturalSize.height, clipVideoTrack.naturalSize.width);
    }
    if (txf.a == 1.0 && txf.b == 0 && txf.c == 0 && txf.d == 1.0) // landscape left
    {
        naturalSize = CGSizeMake(clipVideoTrack.naturalSize.width, clipVideoTrack.naturalSize.height);
    }
    if (txf.a == -1.0 && txf.b == 0 && txf.c == 0 && txf.d == -1.0)// landscape right
    {
        naturalSize = CGSizeMake(clipVideoTrack.naturalSize.width, clipVideoTrack.naturalSize.height);
    }

现在在上面的代码中,它始终显示视频处于横向左侧,即使是肖像。问题出在哪儿 ??为什么它没有给出肖像模式

1 个答案:

答案 0 :(得分:0)

我发现如果使用AVFileTypeAppleM4V预设编写视频,则AVAssetTrack随后读取的preferredOrientation不正确。但是,使用AVFileTypeQuickTimeMovie预设进行写入时,AVAssetTrack将获得与写入期间指定的方向相同的方向。此外,Iphone Camera应用程序似乎用后一个预设编写。

我的猜测是你正在使用AVFileTypeAppleM4V写作。