Ios AVMutableComposition未正确定向视频

Ios AVMutableComposition未正确定向视频,ios,swift,video,avmutablecomposition,Ios,Swift,Video,Avmutablecomposition,我已经在StackOverflow上挖掘了一天的大部分时间,虽然有很多关于这个主题的好帖子,但我还没有找到解决我问题的方法 我正在使用AVAssetWriter编写视频文件,没有问题。我的视频文件,如果我保存到我的相机胶卷中,将以预期的方向正确播放。下面是我如何设置的 init(fileUrl:URL!, height:Int, width:Int) { // Setup the filter writer instance fileWriter = try? AVAssetW

我已经在StackOverflow上挖掘了一天的大部分时间,虽然有很多关于这个主题的好帖子,但我还没有找到解决我问题的方法

我正在使用
AVAssetWriter
编写视频文件,没有问题。我的视频文件,如果我保存到我的相机胶卷中,将以预期的方向正确播放。下面是我如何设置的

init(fileUrl:URL!, height:Int, width:Int) {

    // Setup the filter writer instance
    fileWriter = try? AVAssetWriter(outputURL: fileUrl, fileType: AVFileType.mov)

    // Setup the video settings
    let videoOutputSettings: Dictionary<String, AnyObject> = [
        AVVideoCodecKey : AVVideoCodecType.hevc as AnyObject,
        AVVideoWidthKey : width as AnyObject,
        AVVideoHeightKey : height as AnyObject
    ]

    // Setup the attributes dictionary
    let sourcePixelBufferAttributesDictionary = [
        String(kCVPixelBufferPixelFormatTypeKey) : Int(kCVPixelFormatType_32BGRA),
        String(kCVPixelBufferWidthKey) : Int(width),
        String(kCVPixelBufferHeightKey) : Int(height),
        String(kCVPixelFormatOpenGLESCompatibility) : kCFBooleanTrue
        ] as [String : Any]

    // Setup the video input
    videoInput = AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: videoOutputSettings)

    // Data should be expected in real time
    videoInput.expectsMediaDataInRealTime = true

    // Perform transform
    videoInput.transform = CGAffineTransform(rotationAngle: CGFloat(CGFloat.pi / 2.0))

    // Setup pixel buffer intput
    assetWriterPixelBufferInput = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoInput,
                                                                       sourcePixelBufferAttributes: sourcePixelBufferAttributesDictionary)

    // Add the input
    fileWriter.add(videoInput)
}
我很抱歉这么长时间,但是有没有什么突出的因素可以帮助解释出口过程中的方向变化


谢谢

我有一个关于方向的问题,我就是这样解决的:

AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[a_compositionVideoTrack setPreferredTransform:CGAffineTransformRotate(CGAffineTransformMakeScale(-1, 1), M_PI)];
通过旋转和缩放它。它是用objective-C编写的,但是你可以很容易地转换它。您只需更改以下内容:

// Setup the preferred transform
compositionvideoTrack.preferredTransform = videoTrack.preferredTransform

与preferredTransform不同,手动进行转换。

我将此答案标记为正确答案,因为这确实纠正了我作文中的一个问题。我要问一个单独的问题,因为我相信我在拍摄视频时有一个更大的定位问题,但这非常有帮助。
// Setup the preferred transform
compositionvideoTrack.preferredTransform = videoTrack.preferredTransform