使用AVMutableVideoCompositionLayerInstruction进行视频旋转

时间:2013-09-09 17:56:55

标签: iphone ios avfoundation cgaffinetransform avmutablecomposition

我正在合并多个视频,我想要检测哪些是纵向模式并在横向旋转它们以便所有电影都处于横向模式...我已经完成了所有工作并且除了实际旋转之外完美无缺,我猜它是具有旋转中心或旋转中心的东西。

        AVMutableVideoCompositionLayerInstruction *videoTrackLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];

        if([[AppDelegate sharedInstance] orientationForTrack:avAsset] == UIDeviceOrientationPortrait)
        {
            CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI/2);
            //CGAffineTransform translateToCenter = CGAffineTransformMakeTranslation(640, 480);
            //CGAffineTransform mixedTransform = CGAffineTransformConcat(rotation, translateToCenter);
            [videoTrackLayerInstruction setTransform:rotation atTime:nextClipStartTime];
        }
        else if([[AppDelegate sharedInstance] orientationForTrack:avAsset] == UIDeviceOrientationPortraitUpsideDown)
        {
            CGAffineTransform rotation = CGAffineTransformMakeRotation(-M_PI/2);
            [videoTrackLayerInstruction setTransform:rotation atTime:nextClipStartTime];
        }
        else if([[AppDelegate sharedInstance] orientationForTrack:avAsset] == UIDeviceOrientationLandscapeLeft)
        {
            CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI);
            [videoTrackLayerInstruction setTransform:rotation atTime:nextClipStartTime];
        }
        else if([[AppDelegate sharedInstance] orientationForTrack:avAsset] == UIDeviceOrientationLandscapeRight)
        {
            [videoTrackLayerInstruction setTransform:CGAffineTransformIdentity atTime:nextClipStartTime];
        }

如何正确旋转它们?我尝试了多个来源,但没有按照他们应该的方式旋转它们。我对320比例拟合解决方案不感兴趣我希望视频在使用AVAssetExportSession导出之前保持尽可能多的分辨率。

这样的解决方案:

CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(degreesToRadians(90.0));
CGAffineTransform rotateTranslate = CGAffineTransformTranslate(rotateTransform,320,0);

不适合我的需要,因为我已经尝试过了。你有什么想法?一些帮助将非常感激。

0 个答案:

没有答案