SCRecorder icon indicating copy to clipboard operation
SCRecorder copied to clipboard

Not able to create an AVAsset from the exportSession.outputUrl.

Open abhipermukha opened this issue 7 years ago • 2 comments

I am trying to export the recorded video and then create an AVAsset from the exportSession.outputUrl so that i can use this asset for mixing other audios to the video as per the requirement of my app. But i am not able to create an AVAsset from the exportSession.outputUrl .

If I save it to camera roll , then i am able to create an AVAsset. But without saving to camera roll, just after the completion of exporting, if i try to create an AVAsset from the exportSession.outputUrl, then it says the duration of the asset is zero seconds(when i print the duration of asset).

Please help me out.

Thanks.

code is as below,

  • (void)saveToCameraRoll { self.navigationItem.rightBarButtonItem.enabled = NO; SCFilter *currentFilter = [self.filterSwitcherView.selectedFilter copy]; [_player pause];

    SCAssetExportSession *exportSession = [[SCAssetExportSession alloc] initWithAsset:self.recordSession.assetRepresentingSegments]; exportSession.videoConfiguration.filter = currentFilter; exportSession.videoConfiguration.preset = SCPresetHighestQuality; exportSession.audioConfiguration.preset = SCPresetHighestQuality; exportSession.videoConfiguration.maxFrameRate = 35;

    exportSession.outputUrl = self.recordSession.outputUrl;

    exportSession.outputFileType = AVFileTypeQuickTimeMovie;//AVFileTypeMPEG4; exportSession.delegate = self; exportSession.contextType = SCContextTypeAuto; self.exportSession = exportSession;

    self.exportView.hidden = NO; self.exportView.alpha = 0; CGRect frame = self.progressView.frame; frame.size.width = 0; self.progressView.frame = frame;

    [UIView animateWithDuration:0.3 animations:^{ self.exportView.alpha = 1; }];

    //SCWatermarkOverlayView *overlay = [SCWatermarkOverlayView new]; //overlay.date = self.recordSession.date; //exportSession.videoConfiguration.overlay = overlay; //exportSession.videoConfiguration.watermarkFrame = CGRectMake([UIScreen mainScreen].bounds.size.width-210, [UIScreen mainScreen].bounds.size.height-210, 200, 200);

    //exportSession.videoConfiguration.watermarkFrame = CGRectMake(0, 0, 200, 200); //exportSession.videoConfiguration.watermarkImage = [UIImage imageNamed:@"watermark"]; NSLog(@"Starting exporting");

    CFTimeInterval time = CACurrentMediaTime(); __weak typeof(self) wSelf = self; [exportSession exportAsynchronouslyWithCompletionHandler:^{ __strong typeof(self) strongSelf = wSelf;

      if (!exportSession.cancelled) {
          NSLog(@"Completed compression in %fs", CACurrentMediaTime() - time);
      }
    
      if (strongSelf != nil) {
          [strongSelf.player play];
          strongSelf.exportSession = nil;
          strongSelf.navigationItem.rightBarButtonItem.enabled = YES;
    
          [UIView animateWithDuration:0.3 animations:^{
              strongSelf.exportView.alpha = 0;
          }];
      }
    
      NSError *error = exportSession.error;
      if (exportSession.cancelled) {
          NSLog(@"Export was cancelled");
      } else if (error == nil) {
          [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
          [exportSession.outputUrl saveToCameraRollWithCompletion:^(NSString * _Nullable path, NSError * _Nullable error) {
              [[UIApplication sharedApplication] endIgnoringInteractionEvents];
    
              if (error == nil) {
                  [[[UIAlertView alloc] initWithTitle:@"Saved to camera roll" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
                  NSLog(@"path = %@",path);
    
                  NSLog(@"exportSession.outputUrl = %@",[exportSession.outputUrl absoluteString]);
                  NSData *videoFile = [NSData dataWithContentsOfURL:exportSession.outputUrl];
                  NSLog(@"videoFile size is : %.2f MB",(float)videoFile.length/1024.0f/1024.0f);
    
                  AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[exportSession.outputUrl absoluteString]]];
                  float duration = asset.duration.value/asset.duration.timescale;
    
                  NSLog(@"duration = %f",duration);  //this gets printed as 0.00 , why????????
    
              } else {
                  [[[UIAlertView alloc] initWithTitle:@"Failed to save" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
              }
          }];
      } else {
          if (!exportSession.cancelled) {
              [[[UIAlertView alloc] initWithTitle:@"Failed to save" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
          }
      }
    

    }]; }

abhipermukha avatar Sep 29 '17 07:09 abhipermukha

Were you able to figure it out?

JayBone16 avatar Jul 10 '18 00:07 JayBone16

It was my own mistake in my code in some other place....SCRecorder works awesome...

Thanks and regards, Abhilash P

On Tue, Jul 10, 2018, 5:42 AM JayBone16 [email protected] wrote:

Were you able to figure it out?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rFlex/SCRecorder/issues/407#issuecomment-403658484, or mute the thread https://github.com/notifications/unsubscribe-auth/AXR6uKpkSk2ykyAnDy-tHXoq7BNwi5Riks5uE_FkgaJpZM4PoSmp .

abhipermukha avatar Jul 11 '18 15:07 abhipermukha