簡體   English   中英

如何在iOS中提高視頻錄制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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM