我使用此代碼從拍攝的視頻製作靜態圖像以顯示在應用程序視圖中。我意識到你可能只會談論它保存在設備的照片庫中,在這種情況下,我不確定這是否適合你,但我希望它有幫助。 AVFoundation框架可能是找到解決方案的最佳選擇。
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:yourVideoURL options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *videoStill = [[UIImage alloc] initWithCGImage:oneRef];
[imageView videoStill];
imageView.contentMode = UIViewContentModeScaleAspectFit;
乾杯,吉姆。
這不是我的問題。我不需要從視頻中提取靜態圖像。我有這個,我需要爲圖庫中的視頻設置一個特定的靜止圖像作爲封面/海報圖像。 – Surjeet