![](/img/trans.png)
[英]How to transcode a video to 16:9 format and vary the bit rate (and perhaps FPS)?
[英]how do i increase video recording fps rate in ios
我在将视频帧(图像)保存到磁盘时遇到问题。 它会向我返回低帧/秒,例如8fps,10fps,12fps,15fps。 如果我播放iPhone相机应用程序并录制视频,那么我将获得29fps,30fps,因此我希望我的应用程序计算与iPhone相机应用程序相同的fps
- (void) blCameraControllerDidCaptureSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
if(shouldSaveVideoToGallery)
{
[analysisQueue addOperationWithBlock:^{
// CMTime t=CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
CMTime t=CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer);
float time=CMTimeGetSeconds(t);//t.value;
if(initialBufferTime==-1)
{
initialBufferTime=time;
}
time=time-initialBufferTime;
UIImage *analysisImage=[self imageFromSampleBuffer:sampleBuffer];
// [analysisImageA addObject:analysisImage];
CMSampleBufferInvalidate(sampleBuffer);
CFRelease(sampleBuffer);
NSString *videoName=[[currentVideoPath lastPathComponent] stringByDeletingPathExtension];
NSString * analysisImagePath=[[[OrbisMediaGallery sharedGallery] getMediaGalleryFolderPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_analysisScreen%d.jpg", videoName, (int)(analysisScreens.count+1)]];
[imagePathA addObject:analysisImagePath];
NSData *imageData=UIImageJPEGRepresentation(analysisImage, 0.5);
[imageData writeToFile:analysisImagePath atomically:NO];
[analysisQueue saveFrameOnDisk:analysisImage andImgPath:analysisImagePath];
NSDictionary *d=@{@"analysisScreenPath": analysisImagePath, @"analysisScreenTime": [NSNumber numberWithFloat:time]};
NSLog(@"_analysisScreen: %@", d);
[analysisScreens addObject:d];
NSLog(@"isRecording:%@, analysisQueue.operationCount:%@", @(isRecording), @(analysisQueue.operationCount));
if(analysisQueue.operationCount<=1)
isDoneGeneratingFrames=YES;
if(!isRecording && analysisQueue.operationCount<=1)
{
// [self saveImageOnDisk];
[self saveFramesOfVideo:currentVideoPath startTime:[d objectForKey:@"analysisScreenTime"]];
// [[OrbisMediaGallery sharedGallery] saveAnalysisImages:analysisScreens forVideoAtPath:currentVideoPath];
}
}];
}
else
{
isDoneGeneratingFrames=YES;
}
}
它是在录制视频时每次调用的委托方法。 其实我在这些线上面临问题
NSData *imageData=UIImageJPEGRepresentation(analysisImage, 0.5);
[imageData writeToFile:analysisImagePath atomically:NO];
当我对这些行发表评论时,它将像iPhone摄像头应用程序一样返回更高的帧速率。 但是在评论这两行时,这里出现的问题是我无法停止视频并在框架上看到它,请不要告诉我将这两行放入后台线程或gcd中。 我曾尝试将其放在后台线程上。 但是fps速率没有改变。
由于篇幅所限,发表评论作为答案。
了解这里发生了什么。 您要获取原始像素数据(每像素4个字节,以rgba为单位)乘以每帧的分辨率(高度x照相机分辨率的宽度),然后将其传递到内存中,然后再尝试将其写入磁盘。 每个帧的大小为几MB,您想每秒执行30次(或更多)操作吗? 无论您很快就会用完空间,这都是不会发生的。
本质上,由于代理无法处理传入的数据包,因此降低了帧速率。 我相信(如果内存能很好地为我服务)文档甚至会警告您将回调中的处理保持在最低水平。
尚不清楚您的目标。 一种提高帧速率的方法是将图像处理移到一个浅队列中,一旦队列达到它的限制(在创建时设置),它将具有丢弃处理块的效果。 明白这只是在移动瓶颈。 另一种方法是将摄像机捕获设置为较低的分辨率。 但是,我怀疑这些都不能满足您的需求。 您需要做的是重新设计整个过程。
同样,在不了解目标的情况下,不可能推荐一个好的解决方案,即您是将这些帧简单地保存为图像,因为这是在用户暂停视频时显示给定帧的最简单方法,还是您确实需要保留所有这些图像? ?
最重要的是,这行不通,如果您详细说明自己的需求,也许可以找到一种满足您要求的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.