gpt4 book ai didi

objective-c - 如何使用 AVFoundation 将视频转换为动画 gif?

转载 作者:搜寻专家 更新时间:2023-10-30 20:09:11 25 4
gpt4 key购买 nike

在使用 AVFoundation 和 AVCamRecorder 录制电影后,我正在推送一个新的 UIViewController。

目前我正在从保存电影的 URL 播放电影,并且工作正常。我在理解如何将视频从 URL 转换为动画 gif 时遇到了很大的麻烦。

我是 Objective C 的新手,并且成功地创建了一个漂亮的自定义录像机,但现在我对下一篇文章感到气馁。

我有

SecondViewController.h

@interface SecondViewController : UIViewController
@property NSURL *videoURL;
@end

SecondViewController.m

#import "SecondViewController.h"
#import "FirstViewController.h"
#import "CaptureManager.h"
#import "AVCamRecorder.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface SecondViewController ()

@property (nonatomic, strong) CaptureManager *grabFile;
@property (nonatomic, strong) MPMoviePlayerController *movie;

@end

@implementation SecondViewController

- (void)viewDidLoad
{
self.movie = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
_movie.view.frame = CGRectMake(0.0, 64.0, 320.0, 320.0);
_movie.movieSourceType = MPMovieSourceTypeFile;
_movie.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview:_movie.view];
[_movie play];
}

我尝试过一些

AVURLAsset

AVAssetImageGenerator

但我无法输出任何内容。我想知道这些步骤,如果可能的话,还有一些关于如何将帧提取到动画 gif 中的示例位。感谢您阅读我的问题! :)

最佳答案

答案是在生成的视频上使用 CVPixelBuffer 将图像 Assets 取出并存入内存,然后将图像添加到 NSDictionary 并从存储的图像。

如何使用CVPixelBuffer
How to turn a CVPixelBuffer into a UIImage?

如何从字典中获取存储的图像并创建 gif:
Create and and export an animated gif via iOS?

关于objective-c - 如何使用 AVFoundation 将视频转换为动画 gif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22404179/

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