gpt4 book ai didi

ios - 从视频ios创建缩略图?

转载 作者:行者123 更新时间:2023-12-01 18:14:50 24 4
gpt4 key购买 nike

我从照片库中的视频中获得了缩略图,现在我想在缩略图上添加持续时间和相机图标,如​​ image 。有什么建议吗?谢谢。

thumbnailImg

最佳答案

当您从库中选择视频文件时,您可以获得视频的持续时间,如下所示:-

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];

AVPlayerItem *SelectedItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];

CMTime duration = SelectedItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
}

您可以使用以下方式获取视频拇指:-
-(UIImage *)getThumbNail:(NSString*)stringPath
{

//stringPath is a path of stored video file from document directory
NSURL *videoURL = [NSURL fileURLWithPath:stringPath];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

//Player autoplays audio on init
[player stop];

return thumbnail;
}

现在你有你只需要创建你的自定义 View 并做你想做的事。

不要忘记添加
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import <AVFoundation/AVAsset.h>

这里还有一个很好的答案,适合
您的问题请检查以下内容:-

iOS: get video duration and thumbnails without playing video

关于ios - 从视频ios创建缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23105204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com