在我的項目中,我需要在一個獨特的結果圖像上覆制一個視頻幀的每個幀。iOS - 視頻幀處理優化
捕獲視頻幀並不是什麼大不了的事。它會是這樣的:
// duration is the movie lenght in s.
// frameDuration is 1/fps. (or 24fps, frameDuration = 1/24)
// player is a MPMoviePlayerController
for (NSTimeInterval i=0; i < duration; i += frameDuration) {
UIImage * image = [player thumbnailImageAtTime:i timeOption:MPMovieTimeOptionExact];
CGRect destinationRect = [self getDestinationRect:i];
[self drawImage:image inRect:destinationRect fromRect:originRect];
// UI feedback
[self performSelectorOnMainThread:@selector(setProgressValue:) withObject:[NSNumber numberWithFloat:x/totalFrames] waitUntilDone:NO];
}
問題出現在我嘗試實施drawImage:inRect:fromRect:
方法。
我試圖this code,其中:
- 從視頻幀創建
CGImageCreateWithImageInRect
新CGImage以提取圖像的塊。 - 請在ImageContext一個CGContextDrawImage提請塊
但是當視頻達到12-14s,我的iPhone 4S宣佈他的第三個內存警告和崩潰。我異形與泄漏工具的應用,並沒有發現任何泄漏在所有...
我不是在石英很強。有沒有更好的優化方式來實現這一目標?
馬丁嗨,一路圖像提取物是完美的,但在應用程序,如果視頻時長超過30秒,然後應用內存警告崩潰。你有其他的方式或者有什麼變化嗎?謝謝 – iBhavik 2013-05-14 06:34:15
嗨。它不應該與長視頻崩潰。檢查你的代碼,也許你在處理程序塊中包含泄漏。您無法將所有提取的圖像保留在內存中,因爲設備沒有足夠的內存空間。 – Martin 2013-05-14 08:06:28
@iBhavik你有沒有找到任何解決方案 – Nil 2017-07-06 15:29:22