从视频创建缩略图 - 选择预览期间要使用的图像
使用选择器从视频制作缩略图非常简单。但是,当我在选择器中按“播放”然后选择视频时,我的缩略图始终是黑色的。我希望它能截取屏幕截图 - 然而这种方法只获取视频的第一张图像 - 并且只有在它还没有被播放的情况下!
如何在视频的任意位置制作缩略图?
这里是我用于缩略图的“正常”代码,其中视频尚未播放:
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
CGSize size = viewImage.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 80.0 / size.width;
} else {
ratio = 80.0 / size.height;
}
CGRect rectForthumbnail = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rectForthumbnail.size);
CGRect clipRect = CGRectMake(0.0, 0.0,74,74);
[viewImage drawInRect:clipRect];
dance.thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
不幸的是,按下“播放”后,创建的缩略图是黑色的(仅显示视频滚动和当前视频的 iPhone 屏幕顶部)显示播放位置),缩略图的其余部分始终为黑色。如前所述,在其他情况下它效果很好。
非常感谢!
making a thumbnail from video using the picker is straight forward. However, when I press PLAY in the picker and then chose the video, my thumbnail is alway black. I was hoping it makes a screenshot - however this method only takes the first image of the video - and ONLY IF IT HASN'T BEEN PLAYED!
How can I make a thumbnail at any position of the video?
Here the "normal" code I use for thumbnails, where the video hasn't been played:
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
CGSize size = viewImage.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 80.0 / size.width;
} else {
ratio = 80.0 / size.height;
}
CGRect rectForthumbnail = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rectForthumbnail.size);
CGRect clipRect = CGRectMake(0.0, 0.0,74,74);
[viewImage drawInRect:clipRect];
dance.thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
After having pressed "PLAY", unfortunately, the created thumbnail is black (only shows the top of the iphone screen where the video roll and the current play position is displayed), the remaining of the thumbnail is always black. As said, in other cases it works well.
Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 MPMoviePlayerController doku:链接 。有一个“thumbnailImageAtTime:timeOption:”函数返回 UIImage..希望有帮助
Check the MPMoviePlayerController doku: link. There´s a "thumbnailImageAtTime:timeOption:" function which returns a UIImage.. Hope that helps
如果你使用 MPMoviePlayerController 你可以尝试这个
If you are using MPMoviePlayerController you could try this
如果您使用 MPMoviePlayer,则可以使用
MPMoviePlayerControllerthumbnailImageAtTime:timeOption
方法。或者您可以使用以下方法手动从视频中获取缩略图 -
You can use
MPMoviePlayerController thumbnailImageAtTime:timeOption
method if you are using MPMoviePlayer.or you can manually get thumbnail image from video using following method -