ios - SCRecorder : How to create SCRecordSession from local video -


i use screcorder customize videos. want import somes local videos make longer video , save camera roll . use screcord lib implement it. first, make each screcordsegment each local video:

filepath = [nsstring stringwithformat:@"%@/%@", documentsdirectory,[nsstring stringwithformat:@"%@.mp4",videotitle]];         // create         screcordsessionsegment *record = [[screcordsessionsegment alloc] initwithurl:[nsurl urlwithstring:filepath] info:nil]; 

then create recordsession :

screcordsession *recordsession = [screcordsession recordsession]; [recordsession addsegment:record]; 

but crashes when save camera roll .

- (void)savetocameraroll : (screcordsession *)recordsession{ self.navigationitem.rightbarbuttonitem.enabled = no;   scassetexportsession *exportsession = [[scassetexportsession alloc] initwithasset:recordsession.assetrepresentingsegments]; exportsession.videoconfiguration.filter = nil; exportsession.videoconfiguration.preset = scpresethighestquality; exportsession.audioconfiguration.preset = scpresethighestquality; exportsession.videoconfiguration.maxframerate = 35; exportsession.outputurl = recordsession.outputurl;  exportsession.outputfiletype = avfiletypempeg4; exportsession.delegate = self; exportsession.contexttype = sccontexttypeauto;    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);     }       nserror *error = exportsession.error;     if (exportsession.cancelled) {         nslog(@"export 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 camera roll" message:@"" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil] show];             } else {                 [[[uialertview alloc] initwithtitle:@"failed save" message:error.localizeddescription delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil] show];             }         }];     } else {         if (!exportsession.cancelled) {             [[[uialertview alloc] initwithtitle:@"failed save" message:error.localizeddescription delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil] show];         }     } }]; 

}

you not merging video clips first. here sample code

- (ibaction)savetocameraroll:(id)sender {     [[self recorder] pause:^{         [[hprecordsessionmanager sharedinstance] saverecordsession:[[self recorder] session]];         [self setrecordsession:[[self recorder] session]];          [[self saveindicator] startanimating];         [[uiapplication sharedapplication] beginignoringinteractionevents];          void(^completionhandler)(nsurl *url, nserror *error) = ^(nsurl *url, nserror *error) {              if (error == nil) {                  uisavevideoatpathtosavedphotosalbum([url path], self, @selector(video:didfinishsavingwitherror:contextinfo:), nil);             } else {                  [[uiapplication sharedapplication] endignoringinteractionevents];                 [uiviewcontroller displayerroralertwithtitle:kclipsavetocamerarallfailedtitle message:[error localizeddescription] cancelbuttontext:kclipsavetocamerarallfaileddissmissbutton];                 [[self saveindicator] stopanimating];             }         };          [[self recordsession] mergesegmentsusingpreset:avassetexportpresethighestquality completionhandler:completionhandler];     }]; }  - (void)video:(nsstring *)videopath didfinishsavingwitherror:(nserror *)error contextinfo: (void *) contextinfo {     [[self saveindicator] stopanimating];     [[uiapplication sharedapplication] endignoringinteractionevents];      if (error == nil) {         [uiviewcontroller displayerroralertwithtitle:kclipsavetocamerarallsuccesstitle message:kclipsavetocamerarallsuccessmessage cancelbuttontext:kclipsavetocamerarallsuccessdissmissbutton];     } else {         [uiviewcontroller displayerroralertwithtitle:kclipsavetocamerarallfailedtitle message:[error localizeddescription] cancelbuttontext:kclipsavetocamerarallfaileddissmissbutton];     }  } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -