從我已閱讀的蘋果不公開api允許開發人員使用當前sdk獲取電影的縮略圖。iphone sdk> 3.0。視頻縮略圖?
任何人都可以共享一些代碼,以瞭解他們如何去做這件事嗎? 我聽說您可以訪問相機選取器視圖,並在ui圖像選取器關閉之前找到圖像視圖。這看起來有點醜陋。
此外,我認爲使用ffmpeg抓取一個框架的電影,但不知道如何編譯它作爲一個庫的iphone線索。任何指針將不勝感激
從我已閱讀的蘋果不公開api允許開發人員使用當前sdk獲取電影的縮略圖。iphone sdk> 3.0。視頻縮略圖?
任何人都可以共享一些代碼,以瞭解他們如何去做這件事嗎? 我聽說您可以訪問相機選取器視圖,並在ui圖像選取器關閉之前找到圖像視圖。這看起來有點醜陋。
此外,我認爲使用ffmpeg抓取一個框架的電影,但不知道如何編譯它作爲一個庫的iphone線索。任何指針將不勝感激
在與縮略圖的電影相同的文件夾中有一個jpg。我只用手機錄製的視頻進行了測試,但效果很好。它的名稱與電影名稱不同,因此請獲取電影所在的目錄路徑並迭代爲.jpg,然後離開。
如果您使用UIImagePickerController獲取圖像,那麼JPG將不會存儲在tmp目錄中。我不確定這個問題的答案,但ffmpeg,更具體地說是它背後的庫,可能是您的選擇。
希望我的代碼可以幫助你們。它很醜。我認爲蘋果應該開放這種API。 當然,應該刪除所有NSLog()。這只是爲了演示。
阿爾文
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// e.g.
NSString *tempFilePath = [(NSURL *)[info valueForKey:UIImagePickerControllerMediaURL] absoluteString];
NSLog(@"didFinishPickingMediaWithInfo: %@",tempFilePath);
// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp/capture/capturedvideo.MOV
tempFilePath = [[tempFilePath substringFromIndex:16] retain];
NSLog(@"didFinishPickingMediaWithInfo: %@",tempFilePath);
NSLog(@"===Try to save video to camera roll.===");
NSLog(@"UIVideoAtPathIsCompatibleWithSavedPhotosAlbum: %@",UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)? @"YES":@"NO");
// Check if the video file can be saved to camera roll.
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)){
// YES. Copy it to the camera roll.
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(NSString *)contextInfo{
NSLog(@"didFinishSavingWithError--videoPath in camera roll:%@",videoPath);
NSLog(@"didFinishSavingWithError--videoPath in temp directory:%@",contextInfo);
// The thumbnail jpg should located in this directory.
NSString *thumbnailDirectory = [[contextInfo stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
// Debug info. list all files in the directory of the video file.
// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp/capture
NSLog([contextInfo stringByDeletingLastPathComponent]);
NSLog([[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[contextInfo stringByDeletingLastPathComponent] error:nil] description]);
// Debug info. list all files in the parent directory of the video file, i.e. the "~/tmp" directory.
// e.g. /private/var/mobile/Applications/D1E784A4-EC1A-402B-81BF-F36D3A08A332/tmp
NSLog(thumbnailDirectory);
NSLog([[[NSFileManager defaultManager] contentsOfDirectoryAtPath:thumbnailDirectory error:nil] description]);
///////////////////
// Find the thumbnail for the video just recorded.
NSString *file,*latestFile;
NSDate *latestDate = [NSDate distantPast];
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:[[contextInfo stringByDeletingLastPathComponent]stringByDeletingLastPathComponent]];
// Enumerate all files in the ~/tmp directory
while (file = [dirEnum nextObject]) {
// Only check files with jpg extension.
if ([[file pathExtension] isEqualToString: @"jpg"]) {
NSLog(@"***latestDate:%@",latestDate);
NSLog(@"***file name:%@",file);
NSLog(@"***NSFileSize:%@", [[dirEnum fileAttributes] valueForKey:@"NSFileSize"]);
NSLog(@"***NSFileModificationDate:%@", [[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"]);
// Check if current jpg file is the latest one.
if ([(NSDate *)[[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"] compare:latestDate] == NSOrderedDescending){
latestDate = [[dirEnum fileAttributes] valueForKey:@"NSFileModificationDate"];
latestFile = file;
NSLog(@"***latestFile changed:%@",latestFile);
}
}
}
// The thumbnail path.
latestFile = [NSTemporaryDirectory() stringByAppendingPathComponent:latestFile];
NSLog(@"****** The thumbnail file should be this one:%@",latestFile);
// Your code ...
// Your code ...
// Your code ...
}
只是想提供有關此更新。當你將你的選擇器設置爲UIImagePickerControllerSourceTypeCamera時,事情似乎在獲取縮略圖方面起作用。但是,當您嘗試從現有庫(即UIImagePickerControllerSourceTypePhotoLibrary) 中選擇縮略圖的.jpg時,將永遠不會創建。我甚至嘗試用UISaveVideoAtPathToSavedPhotosAlbum(...)重新保存,但仍然沒有骰子。看起來,縮略圖是在捕捉視頻時首先創建的。這是你「搶」它的唯一機會。之後它會移動到/ var/mobile/Media/DCIM /的子目錄中。雖然您可以真正列出縮略圖圖片並查看該圖片,但該文件不可讀且不可複製,因爲我相信該目錄受到保護。
如果任何人有解決這個問題,我將不勝感激,因爲在我的情況下,我需要從庫中選擇它後抓住現有視頻的縮略圖。
這裏有一個博客帖子有關使用ffmpeg的提取電影幀:
http://www.codza.com/extracting-frames-from-movies-on-iphone
在GitHub上相應的項目:iFrameExtractor
最好的方法,我發現...的MPMoviePlayerController thumbnailImageAtTime:timeOption
This。只需創建一個MPMoviePlayerController實例並使用它從回調路徑中獲取縮略圖,無論是從庫中還是從剛錄製的視頻中獲取。工作正常。 – Sam 2010-09-15 14:46:36
毫無疑問,這種方法是最好的。但是可以從iOS 3.2及更高版本中獲得。所以,如果你想在你的應用程序上支持較老的iOS。您將需要使用其他方法。 – 2010-09-16 22:45:55
重要說明... MPMoviePlayerController似乎在初始化後自動播放**。確保在創建後明確停止它,否則,如果用戶沒有靜音,用戶會聽到揚聲器發出的聲音。 – jocull 2010-12-13 15:32:34
NSString *videoLink=[info objectForKey:@"UIImagePickerControllerMediaURL"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:(NSURL*)videoLink];
UIImage *imageSel = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
[player release];
即時將給這個爆炸,並會讓你知道謝謝 – ADAM 2009-08-20 09:49:10
讓我知道它是如何解決的。如果您有任何問題,我可以發佈一些代碼來幫助您。剛剛在我們的應用程序中實現了這一點,所以我知道它的作品 – 2009-08-21 21:22:27
好的,那些修補與這個的另一個細節。在我們的表格中,用戶有能力取消並選擇另一張照片。它實際上將.MOV和.jpg添加到同一個tmp目錄,這會破壞我的以上建議,因爲它不會將正確的jpg與正確的.MOV映射。可能有一個更清晰的方式,但我通過查看文件夾中所有jpgs的NSFileModificationDate並使用最新的一個來修復它。 – 2009-09-04 03:56:58