- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AVCaptureMovieFileOutput
录制视频。然而,我只想保留最后 2 分钟的视频,而不是在整个录制时间内保留捕获的视频。本质上,我想创建一个视频的尾随缓冲区。
我尝试通过将 movieFragmentInterval
设置为 15 秒来实现此目的。当缓冲这 15 秒时,将使用以下代码修剪 MOV 文件的前 15 秒:
//This would be called 7 seconds after the video stream started buffering.
-(void)startTrimTimer
{
trimTimer = [NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(trimFlashbackBuffer) userInfo:nil repeats:YES];
}
-(void)trimFlashbackBuffer
{
//make sure that there is enough video before trimming off 15 seconds
if(trimReadyCount<3){
trimReadyCount++;
return;
}
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/flashbackBuffer.MOV",tripDirectory]] options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/flashbackBuffer.MOV",tripDirectory]];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(15000, 1000), CMTimeMake(120000, 1000));
exportSession.timeRange = timeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
// Custom method to import the Exported Video
[self loadAssetFromFile:exportSession.outputURL];
break;
case AVAssetExportSessionStatusFailed:
//
NSLog(@"Failed:%@",exportSession.error);
break;
case AVAssetExportSessionStatusCancelled:
//
NSLog(@"Canceled:%@",exportSession.error);
break;
default:
break;
}
}];
}
但是,每次调用 trimFlashbackBuffer
时我都会收到以下错误:
Failed:Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x12e710 {NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save}
这是因为该文件已被 AVCaptureMovieFileOutput
写入吗?
如果此方法不起作用,如何才能实现无缝尾部视频缓冲区的效果?
谢谢!
最佳答案
不确定您在这里想要实现的目标是否有效,这是因为就像您所说,您在尝试修剪文件的同时编写文件,为什么不能录制视频并稍后修剪它?如果你真的想随时保留两分钟的视频,你可能想尝试使用 AVCaptureVideoDataOutput,使用它你将获得视频帧,你可以使用 AVAssetWriter 将其写入压缩并将帧写入文件,请查看此SO关于如何做到这一点的问题 This code to write video+audio through AVAssetWriter and AVAssetWriterInputs is not working. Why?
关于iphone - AVCaptureMovieFileOutput -- 写入时修剪文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7166164/
我正在使用 AVCaptureMovieFileOutput 录制视频。然而,我只想保留最后 2 分钟的视频,而不是在整个录制时间内保留捕获的视频。本质上,我想创建一个视频的尾随缓冲区。 我尝试通过将
我使用以下代码来捕获视频并将其保存到我的应用程序的文档文件夹中: AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput
我正在尝试在我的应用程序中实现自定义视频录制和图像捕获。我已经设置了 AVCaptureSession 和所有必要的输入/输出来捕获音频、视频和静态图像。但是,我录制完视频后,输出文件不存在。由于输出
我目前能够将视频录制到 AVCaptureMovieFileOutput 实例,但我找不到任何可以学习的资源,这些资源显示了如何像 snapchat/facebook/instagram 那样播放视频
我想在一系列流畅、可变长度的剪辑中录制视频/音频。也就是说,vid1.mp4 后跟 vid2.mp4 应该无缝连接在一起,或者几乎是无缝连接。 我目前的问题是我似乎无法在不出错的情况下立即切换文件。
我正在开发一个 osx 捕获应用程序,我可以使用 AVFoundation 提供的文件格式 UTIs 来分配文件输出格式,如 .mov、.mp4、 .m4v 等 我可以创建自定义文件格式 UTIs 来
正如标题所述,我希望在用户使用 AVFoundation 录制视频时显示当前的录制长度。我对 AVAudioRecorder 做了类似的事情,我创建了一个计时器来设置标签的文本,如下所示: recor
我能够组装一个最小的屏幕录制 Swift 演示,用于调试另一件事,但有些东西告诉我 - AVFoundation 从未调用我的委托(delegate)进行录制。事实上,他们都不是。 代码非常简单: c
当我的应用程序启动时,我试图使用 AVCaptureMovieFileOutput 将设备相机录制到视频文件中。令我非常沮丧的是,我无法让它工作: 我可以使用 AVCaptureVideoPrevie
当应用程序在视频录制和拍照之间切换时,我想防止延迟:通过仅使用 AVCaptureMovieFileOutput 并在捕获图像时从中获取快照。 就像 SnapChat 一样。 这有可能吗?我还没有找到
我试图阻止 AVCaptureSession 在没有足够的磁盘空间时添加 AVCaptureMovieFileOutput。我在 viewDidload 中使用以下代码进行测试: let sessio
我对 captureStillImageAsynchronouslyFromConnection 有一个奇怪的问题。如果我在镜像视频时使用 jpegStillImageNSDataRepresenta
我尝试了几种不同的方法,但它们对我没有帮助。我想更改 AVFoundation 中的视频方向。我怎样才能做到? override func viewDidLoad() { super.
我尝试使用以下代码从 iphone 相机保存视频文件: class Camera { ... private func loadDeviceInput() { let devices = AV
我正在尝试使用 AVFoundation 在我的 iPhone 应用程序中录制视频。但是每当我单击“录制”按钮时,应用程序就会崩溃并显示此消息 -[AVCaptureMovieFileOutput s
我需要将屏幕视频从 Mac 实时发送到多播组,例如“239.1.1.110:46110”。 我知道 AVCaptureMovieFileOutput 有一个方法“startRecordingToOut
我已经创建了一个电影文件,并且能够将其本地保存到设备上。不过,我想利用 icloud 文档并将其保存到 icloud 并公开共享。如何使用 swift 做到这一点? 我找到了这个用于保存一般文件的链接
目前我正在尝试使用 AVCaptureMovieFileOutput 录制视频并将其保存到照片库。然而,一旦照片库的 URL 传递到 startRecording 函数,它就会声称“在此服务器上找不到
我正在创建一个使用 AVFoundation 的相机应用程序。 当我用我的 AVCaptureStillImageOutput 对象拍照时,它会发出与默认相机相同的“快门”噪音,而无需我告诉 AVCa
用例:我想捕捉来自相机的输入,在捕捉的帧(和声音)之上绘制并将结果保存为 .mov 文件。 我看到我可以使用 AVCaptureSession 捕获相机的输入。 我可以使用 AVCaptureMovi
我是一名优秀的程序员,十分优秀!