在iOS中为视频创建缩略图 [英] Creating Thumbnail for Video in iOS

查看:307
本文介绍了在iOS中为视频创建缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在为iPhone开发的应用程序.它的作用是从摄像机捕获视频并将视频文件存储到文件系统中.

I have an application that I am developing for the iPhone. What it does is, it captures the video from the camera and stores the video file onto the File System.

在将图像保存到文件系统之前,我需要创建此视频文件的缩略图图像.我的目的是显示所创建视频的缩略图列表,以便用户可以选择特定的缩略图来播放所需的文件.

I need to create a Thumbnail Image of this video file before I save the Image to the File System. My motive is to show a list of thumbnails of the created video so that the user can select a specific thumbnail to play the desired file.

有人可以建议我如何为相机捕获的视频文件创建缩略图图像.

Could someone please advise on how I can create a Thumbnail image of a video file that has been captured by the Camera.

此外,能否请您告知我是否可以使用iOS SDK创建现有视频文件的缩略图.

Also, can you please advise if I can create a Thumbnail of an existing video file using iOS SDK.

推荐答案

尝试一下(它实际上并不显示电影播放器​​):

Try this (it doesn't actually show the movie player):

+ (UIImage *)imageFromMovie:(NSURL *)movieURL atTime:(NSTimeInterval)time {
  // set up the movie player
  MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] 
    initWithContentURL:movieURL];
  mp.shouldAutoplay = NO;
  mp.initialPlaybackTime = time;
  mp.currentPlaybackTime = time;
  // get the thumbnail
  UIImage *thumbnail = [mp thumbnailImageAtTime:time 
                           timeOption:MPMovieTimeOptionNearestKeyFrame];
  // clean up the movie player
  [mp stop];
  [mp release];
  return(thumbnail);
}

它应该是一个同步调用,因此它可能会阻塞主线程,但是当我在电影开始时使用某个时间时,对我来说似乎正在立即运行.如果您经常这样做,则可以将其添加为UIImage上的类别,这就是我所做的.

It's supposed to be a synchronous call, so it might block the main thread some, but seems to be running pretty instantly for me when I use a time at the beginning of the movie. If you're doing this a lot, you can add it as a category on UIImage, which is what I did.

从您的问题中我看到您想在保存电影之前执行此操作,并且我想如果没有文件URL,它可能无法正常工作.但是,如果您使用UIImagePickerController进行相机捕获,则可以通过键UIImagePickerControllerMediaURL将在imagePickerController:didFinishPickingMediaWithInfo:的信息字典中返回的URL传递给此函数.

I see from your question that you want to do this before the movie is saved, and I guess it might not work without a file url. However, if you're using the UIImagePickerController for camera capture, you can pass this function the URL returned in the info dictionary of imagePickerController:didFinishPickingMediaWithInfo: with the key UIImagePickerControllerMediaURL.

这篇关于在iOS中为视频创建缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆