rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

How to get data from recorded video? #295

Open jln19 opened 8 years ago

jln19 commented 8 years ago
- (void)recorder:(SCRecorder *__nonnull)recorder didCompleteSegment:(SCRecordSessionSegment *__nullable)segment inSession:(SCRecordSession *__nonnull)session error:(NSError *__nullable)error {

    [session mergeSegmentsUsingPreset:AVAssetExportPresetHighestQuality completionHandler:^(NSURL *url, NSError *error) {
        if (error == nil) {
            //tried both of these:
            NSData *videoData = [NSData dataWithContentsOfURL:url];
            //NSData *videoData = [NSData dataWithContentsOfFile:[url absoluteString]];
            ...

        } else {
            NSLog(@"Bad things happened: %@", error);
        }
    }];

}

videoData is always nil, even though url is valid:

file:///private/var/mobile/Applications/6A92163A-9A8D-4915-B680-F93424F1E9F4/tmp/ytDg2Vt8K0l4-SCVideo-Merged.mov

I need the video data to send to a server. How do you recommend doing this?

MMasterson commented 8 years ago

you want to upload each segment? I think you should be using didCompleteSession..

But either way, here is how I do it (in swift, but same idea)

  func recorder(recorder: SCRecorder, didCompleteSession session: SCRecordSession) {
        if(!isCreatingVideo){
            isCreatingVideo = true
       var exporter = SCAssetExportSession(asset: (self.recorder.session?.assetRepresentingSegments())!)
        exporter.outputFileType = AVFileTypeMPEG4
        exporter.outputUrl = session.outputUrl
        exporter.exportAsynchronouslyWithCompletionHandler {
            if let error = exporter.error {
                //
                print(error.debugDescription)
            } else {
                self.videoURL = exporter.outputUrl
            }
        }
        }
    }