         
         // 3.2 - Create an AVMutableVideoCompositionLayerInstruction for the video track and fix the orientation.
         let videolayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack)
-
+        
         videolayerInstruction.setTransform(videoAssetTrack.preferredTransform, atTime: kCMTimeZero)
         videolayerInstruction.setOpacity(0.0, atTime: videoAsset.duration)
         


public class VideoManipulateUtil {
    
    
    public class var sharedInstance: VideoManipulateUtil {
        struct Static {
            static let instance: VideoManipulateUtil = VideoManipulateUtil()

    
    
    public func createDynamicAlbum (#videoURL: NSURL, renderLayer:CALayer, duration: Float, completionBlock: VideoManipulateUtilExportCompletionBlock!) {
        self.goCreateDynamicAlbum(videoURL: videoURL, audioURL: nil, renderLayer: renderLayer, duration: duration, completionBlock: completionBlock, isSaveToPhotosAlbum: false)
    }
    
    
    public func createDynamicAlbum (#videoURL: NSURL, audioURL: NSURL!, renderLayer:CALayer, duration: Float, completionBlock: VideoManipulateUtilExportCompletionBlock!) {
        self.goCreateDynamicAlbum(videoURL: videoURL, audioURL: audioURL, renderLayer: renderLayer, duration: duration, completionBlock: completionBlock, isSaveToPhotosAlbum: false)
    }
    
    
    public func createDynamicAlbum (#videoURL: NSURL, audioURL: NSURL!, renderLayer:CALayer, duration: Float, completionBlock: VideoManipulateUtilExportCompletionBlock!, isSaveToPhotosAlbum: Bool) {
        
        self.goCreateDynamicAlbum(videoURL: videoURL, audioURL: audioURL, renderLayer: renderLayer, duration: duration, completionBlock: completionBlock, isSaveToPhotosAlbum: isSaveToPhotosAlbum)
    }
    
}



//MARK: Utility functions
extension VideoManipulateUtil {
    
    
    public func getCoreAnimationBeginTimeAtZero() -> CFTimeInterval {
        return AVCoreAnimationBeginTimeAtZero
    }
    
    public func querySizeWithAssetURL(#videoURL: NSURL) -> CGSize {
        let videoAsset = AVURLAsset(URL: videoURL, options: nil)
        return self.querySize(video: videoAsset)
    }
    
    
    private func querySize(#video: AVAsset) -> CGSize {
        
        let videoAssetTrack = video.tracksWithMediaType(AVMediaTypeVideo).first as! AVAssetTrack
        let videoTransform = videoAssetTrack.preferredTransform
        
        var isVideoAssetPortrait = false
        
        if (videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0) {
            isVideoAssetPortrait = true
        }
        if (videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0) {
            isVideoAssetPortrait = true
        }
        
        var natureSize = CGSizeZero
        if isVideoAssetPortrait {
            natureSize = CGSizeMake(videoAssetTrack.naturalSize.height, videoAssetTrack.naturalSize.width)
        } else {
            natureSize = videoAssetTrack.naturalSize
        }
        
        return natureSize
    }
}


//MARK: Main process functions
extension VideoManipulateUtil {
    
    
    private func goCreateDynamicAlbum (#videoURL: NSURL, audioURL: NSURL!, renderLayer:CALayer, duration: Float, completionBlock: VideoManipulateUtilExportCompletionBlock!, isSaveToPhotosAlbum: Bool) {
        
        
        // 0 - Get AVAsset from NSURL
        let videoAsset = AVURLAsset(URL: videoURL, options: nil)
