                     let videoSettings: [String : Any] = [
                         AVVideoCodecKey  : AVVideoCodecH264,
                         AVVideoCompressionPropertiesKey: compressionSettings,
-                        AVVideoWidthKey  : 1080,
-                        AVVideoHeightKey : 1920,
+                        AVVideoWidthKey  : track.naturalSize.width,
+                        AVVideoHeightKey : track.naturalSize.height,
                         AVVideoScalingModeKey:AVVideoScalingModeResizeAspectFill
                     ]
                     let input = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: videoSettings)
-                    input.transform = tracks[0].preferredTransform
+                    input.transform = track.preferredTransform
                     writer.add(input)
                     let attrs : [String: Any] = [
                         String(kCVPixelBufferPixelFormatTypeKey) : kCVPixelFormatType_32BGRA,
-                        String(kCVPixelBufferWidthKey) : 1080,
-                        String(kCVPixelBufferHeightKey) : 1920,
+                        String(kCVPixelBufferWidthKey) : track.naturalSize.width,
+                        String(kCVPixelBufferHeightKey) : track.naturalSize.height,
                         String(kCVPixelFormatOpenGLESCompatibility) : kCFBooleanTrue
                     ]
                     let adaptor = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: input, sourcePixelBufferAttributes: attrs)

    
    func processNext() {
        guard let reader = self.reader,
            let output = self.output else {
                return
        }

                if status == AVKeyValueStatus.loaded,
                   let reader = try? AVAssetReader(asset: asset) {
                    self.reader = reader
                    let track = asset.tracks(withMediaType: AVMediaTypeVideo)[0]
                    let settings:[String:Any] = [kCVPixelBufferPixelFormatTypeKey as String:kCVPixelFormatType_32BGRA]
                    let output = AVAssetReaderTrackOutput(track: track, outputSettings: settings)
                    self.output = output
                    reader.add(output)
                    reader.startReading()
