缩放后组合视频并旋转目标C.

时间:2017-07-16 19:10:07

标签: ios objective-c video-processing

这是我的问题:我想生成一个包含多个视频中的部分的视频。 对于使用后置摄像头创建的视频,一切正常,但是当我尝试从自拍相机中引入视频时,我有一半的黑屏。 这是我用来旋转,缩放,重新定位视频的代码。我想我也必须应用其他变换,但我无法找到......

            CGAffineTransform orientationTransform = videoAssetTrack.preferredTransform;
            CGSize naturalSize = CGSizeApplyAffineTransform(videoAssetTrack.naturalSize, orientationTransform);
            naturalSize.width = fabs(naturalSize.width);
            naturalSize.height = fabs(naturalSize.height);

            // Make sure the video is transformed properly - Apply Aspect Fill
            float scale = naturalSize.width < naturalSize.height ? _renderSize.width / naturalSize.width : _renderSize.height / naturalSize.height;

            CGPoint recenter;
            recenter.x = (_finalSize.width - naturalSize.width * scale) * 0.5;
            recenter.y = (_finalSize.height - naturalSize.height * scale) * 0.5;

            // If orientationTransform rotated the video in a way that changed the orientation, switch recenter
            if ((videoAssetTrack.naturalSize.width > videoAssetTrack.naturalSize.height) != (naturalSize.width > naturalSize.height)) {
                typeof(recenter.x) temp = recenter.x;
                recenter.x = recenter.y;
                recenter.y = temp;
            }    
            CGAffineTransform transform = CGAffineTransformConcat(CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),  CGAffineTransformMakeTranslation(recenter.x, recenter.y)), orientationTransform);

            [layerInstruction setTransform:transform atTime:timeOffset];

1 个答案:

答案 0 :(得分:0)

您需要分别为纵向变换和横向变换进行变换。