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

Video export extremely slow with overlay #333

Open amilham opened 8 years ago

amilham commented 8 years ago

Hi all, I'm exporting a video using a SCAssetExportSession and giving it a view as an overlay (setting the session's videoConfiguration.overlay property). Exports are extremely slow - on the order of ~10 seconds of processing time for every 1 second of video length. I've tried all sorts of different export options (file types, quality settings, etc), and have narrowed it down to simply having that overlay view present. Does anyone have any idea what's going on or how to speed this up? Thanks!

toddoh commented 8 years ago

I experienced this before, however, it seemed like there's no solution out there. Wonder what the original developer is up to lately.

twomedia commented 8 years ago

Not sure if it will be of any help, but I'm using the following chunk of code to export video with an overlay and it only takes 3 seconds max for a 20 second video.

SCAssetExportSession *exportSession = [[SCAssetExportSession alloc] initWithAsset:videoPreviewPlayer.currentItem.asset];
        exportSession.videoConfiguration.filter = filterSwitcherView.selectedFilter;
        exportSession.videoConfiguration.preset = SCPresetHighestQuality;
        exportSession.audioConfiguration.preset = SCPresetHighestQuality;
        exportSession.videoConfiguration.maxFrameRate = 35;
        exportSession.videoConfiguration.sizeAsSquare = YES;
        exportSession.outputUrl = outputUrl;
        exportSession.outputFileType = AVFileTypeMPEG4;
        exportSession.delegate = self;

        // Add Video Overlay
        exportSession.videoConfiguration.overlay = videoOverlay;

        // Size font to export size
        dispatch_async(dispatch_get_main_queue(), ^{
            [exportSession exportAsynchronouslyWithCompletionHandler:^{
                NSData *videoData = [NSData dataWithContentsOfURL:exportSession.outputUrl];
                NSLog(@"File size is : %.2f MB",(float)videoData.length/1024.0f/1024.0f);
                // Save session and create Upload Session
                [[UploadSessionManager shared] saveVideoWithSessionId:sessionId videoData:videoData];
                [[UploadSessionManager shared] createNewUploadSessionWithChannelId:channelId andMediaId:[MediaManager shared].uploadMedia.mediaId andSessionId:sessionId andUploadStatus:UPLOAD_SESSION_STATUS_UPLOADING andUploadType:UPLOAD_SESSION_TYPE_VIDEO];
                // Upload Media
                [[MediaManager shared] uploadVideo:exportSession.outputUrl forMedia:[MediaManager shared].uploadMedia];
            }];

        });
HackShitUp commented 6 years ago

@twomedia your code makes the video export significantly faster, but do you know why? Also, I've been trying to test a video overlay, but I can't figure out how to do it. What is the "videoOverlay" object you set the video configuration's overlay property to?

pixeled commented 6 years ago

it’s defined as UIView\<SCVideoOverlay> - so.. one of those.

MY problem is that i’m getting a bunch of CGContext errors in the console spew, then crash with no stack trace. (boom - kicked out)

can OP post their UIView subclass code?

Please & Thank You