     }
     
     var lastime:CMTime = kCMTimeZero
-    
-    private let queueAudio = DispatchQueue(label: "audio_encode_queue", qos: .background, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
-    private let queueVideo = DispatchQueue(label: "video_encode_queue", qos: .background, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
+    private let background = DispatchQueue(label: "video_encode_queue")
     func append(sample:CMSampleBuffer, type:RPSampleBufferType)
     {
-        if !initialized
-        {
-            setup(sample: sample)
-        }
-        
-        guard CMSampleBufferIsValid(sample) else
-        {
-            print(sample)
-            return
-        }
-        
-        if let track = movieTracks[type], track.isReadyForMoreMediaData
-        {
-            if type == .video
-            {
-                let position = CMSampleBufferGetPresentationTimeStamp(sample)
-                print(position.seconds, (position - lastime).seconds)
-                lastime = position
-                queueVideo.async
+        guard CMSampleBufferIsValid(sample) else {return}
+        
+        background.sync
+        {
+            if !initialized
+            {
+                setup(sample: sample)
+            }
+            
+            if let track = movieTracks[type], track.isReadyForMoreMediaData
+            {
+                if type == .video
                 {
                     track.append(sample)
-                    if self.writer.status == .failed
+                    if writer.status == .failed
                     {
-                        print(self.writer.error!)
+                        print(type, writer.error!)
                     }
                 }
-            }
-            else
-            {
-                queueAudio.async
+                else
                 {
                     track.append(sample)
-                    if self.writer.status == .failed
+                    if writer.status == .failed
                     {
-                        print(self.writer.error!)
+                        print(type, writer.error!)
                     }
                 }
             }

    var fetchUnityTime:(()->Double)? // get game timestamp for timesync
    private func synchronize(timestamp value:Double)
    {
        print("sychronize")
        if let time = fetchUnityTime?()
        {
            syncdata.append([value, time])

    
    func save(completion:(()->Void)? = nil)
    {
        self.writer.finishWriting
        {
            print("finish", self.writer.status, self.writer.error ?? "success")
