作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 ReplayKit 但我的问题是我需要获取视频(或临时视频),而不必通过 RPPreviewViewController 我正在使用以下内容,但必须使用 RPPreviewViewController,还有其他方法吗?
- (void)stopScreenRecording {
RPScreenRecorder *sharedRecorder = RPScreenRecorder.sharedRecorder;
[sharedRecorder stopRecordingWithHandler:^(RPPreviewViewController *previewViewController, NSError *error) {
if (error) {
NSLog(@"stopScreenRecording: %@", error.localizedDescription);
}
if (previewViewController) {
previewViewController.previewControllerDelegate = self;
self.previewViewController = previewViewController;
// RPPreviewViewController only supports full screen modal presentation.
self.previewViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:previewViewController animated:YES completion:nil];
}
}];
最佳答案
我起诉了以下内容,但我不得不裁剪视频,因为它记录了整个屏幕我希望这对您有所帮助:
- (void)startScreenRecording {
self.screenRecorder = [RPScreenRecorder sharedRecorder];
if (self.screenRecorder.isRecording) {
return;
}
NSError *error = nil;
NSArray *pathDocuments = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *outputURL = pathDocuments[0];
NSString *videoOutPath = [[outputURL stringByAppendingPathComponent:[NSString stringWithFormat:@"%u", arc4random() % 1000]] stringByAppendingPathExtension:@"mp4"];
self.assetWriter = [AVAssetWriter assetWriterWithURL:[NSURL fileURLWithPath:videoOutPath] fileType:AVFileTypeMPEG4 error:&error];
NSDictionary *compressionProperties = @{AVVideoProfileLevelKey : AVVideoProfileLevelH264HighAutoLevel,
AVVideoH264EntropyModeKey : AVVideoH264EntropyModeCABAC,
AVVideoAverageBitRateKey : @(1920 * 1080 * 11.4),
AVVideoMaxKeyFrameIntervalKey : @60,
AVVideoAllowFrameReorderingKey : @NO};
NSNumber* width= [NSNumber numberWithFloat:self.view.frame.size.width];
NSNumber* height = [NSNumber numberWithFloat:self.view.frame.size.height];
if (@available(iOS 11.0, *)) {
NSDictionary *videoSettings = @{AVVideoCompressionPropertiesKey : compressionProperties,
AVVideoCodecKey : AVVideoCodecTypeH264,
AVVideoWidthKey : width,
AVVideoHeightKey : height};
self.assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
} else {
// Fallback on earlier versions
}
[self.assetWriter addInput:self.assetWriterInput];
[self.assetWriterInput setMediaTimeScale:60];
[self.assetWriter setMovieTimeScale:60];
[self.assetWriterInput setExpectsMediaDataInRealTime:YES];
if (@available(iOS 11.0, *)) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
[self.screenRecorder setMicrophoneEnabled:YES];
[self.screenRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
if (CMSampleBufferDataIsReady(sampleBuffer)) {
if (self.assetWriter.status == AVAssetWriterStatusUnknown && bufferType == RPSampleBufferTypeVideo) {
[self.assetWriter startWriting];
[self.assetWriter startSessionAtSourceTime:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
}
if (self.assetWriter.status == AVAssetWriterStatusFailed) {
NSLog(@"An error occured.");
//show alert
[[RPScreenRecorder sharedRecorder] stopCaptureWithHandler:^(NSError * _Nullable error) {}];
return;
}
if (bufferType == RPSampleBufferTypeVideo) {
if (self.assetWriterInput.isReadyForMoreMediaData) {
[self.assetWriterInput appendSampleBuffer:sampleBuffer];
}else{
NSLog(@"Not ready for video");
}
}
}
} completionHandler:^(NSError * _Nullable error) {
if (!error) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
// Start recording
NSLog(@"Recording started successfully.");
}else{
//show alert
}
}];
}
});
}];
} else {
// Fallback on earlier versions
}
}
关于ios - ReplayKit 获取视频而不去 RPPreviewViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47266113/
我在我的应用程序中使用 replaykit,在用户完成录制后,我提供了一个按钮来“分享”视频。我展示了 RPPreviewViewController,如果我点击视频中的播放,当我返回应用程序时,音频
我正在使用 ReplayKit 但我的问题是我需要获取视频(或临时视频),而不必通过 RPPreviewViewController 我正在使用以下内容,但必须使用 RPPreviewViewCont
使用 ReplayKit 录制视频后,将呈现 RPPreviewController。但是当从共享扩展中选择消息时,屏幕变黑了。 此时已注销以下内容: plugin com.apple.ReplayK
我在使用 ObjectiveC 在 ReplayKit 中保留对 RPPreviewViewController 的引用时遇到问题,我想知道我做错了什么。 .h 文件: @interface Repl
我是一名优秀的程序员,十分优秀!