NSGIF2 1.3.1

NSGIF2 1.3.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年4月

Brian Lee维护。




NSGIF2 1.3.1

  • Brian Lee 和 Sebastian Dobrincu(原始仓库)

从提供的视频文件 URL 创建 GIF。

该仓库已与原始仓库分离,并包含一些非平凡的不同功能、设计和改进。如有需要,请相互比较,并访问原始仓库获取更多信息。

安装

您可以通过两种方式将 NSGIF 添加到项目中

手工方式

直接将 'NSGIF' 添加到您的项目中,然后在您想要使用它的类中导入以下内容

#import "NSGIF.h"

使用方法

默认请求自动设置必要选项,例如最佳帧数、延时时间、输出临时文件名或大小。更多选项请参考接口文件。

写一行代码进行导出

[NSGIF create:[NSGIFRequest requestWithSourceVideo:tempVideoFileURL] completion:^(NSURL *GifURL) {
    //GifURL is to nil if it failed or stopped.
}];

如果需要更多。

NSGIFRequest * request = [NSGIFRequest requestWithSourceVideo:tempVideoFileURL destination:gifFileURL];
request.progressHandler = ^(double progress, NSUInteger position, NSUInteger length, CMTime time, BOOL *stop, NSDictionary *frameProperties) {
    NSLog(@"%f - %lu - %lu - %lld - %@", progress, position, length, time.value, frameProperties);
};

[NSGIF create:request completion:^(NSURL *GifURL) {
    //GifURL is to nil if it failed or stopped.
}];

中断特定请求的进程

request.progressHandler = ^(double progress, NSUInteger position, NSUInteger length, CMTime time, BOOL *stop, NSDictionary *frameProperties) {
    BOOL cancelationCondition = YES;
    if(cancelationCondition){
        *stop = YES;
    }
};

选项

@interface NSGIFRequest : NSObject

/* required.
 * a file's url of source video */
@property(nullable, nonatomic) NSURL * sourceVideoFile;

/* optional.
 * defaults to nil.
 * automatically assign the file name of source video (ex: IMG_0000.MOV -> IMG_0000.gif)  */
@property(nullable, nonatomic) NSURL * destinationVideoFile;

/* optional but important.
 * Defaults to NSGIFScaleOptimize (not set).
 * This option will affect gif file size, memory usage and processing speed. */
@property(nonatomic, assign) NSGIFScale scalePreset;

/* optional but important.
 * Defaults to 4.
 * number of frames in seconds.
 * This option will affect gif file size, memory usage and processing speed. */
@property(nonatomic, assign) NSUInteger framesPerSecond;

/* optional but defaults is recommended.
 * Defaults is to not set.
 * How far along the video track we want to move, in seconds. It will automatically assign from duration of video and framesPerSecond. */
@property(nonatomic, assign) NSUInteger frameCount;

/* optional.
 * Defaults to 0,
 * the number of times the GIF will repeat. which means repeat infinitely. */
@property(nonatomic, assign) NSUInteger loopCount;

/* optional.
 * Defaults to 0.13.
 * unit is 10ms, 1/100s, the amount of time for each frame in the GIF.
 * This option will NOT affect gif file size, memory usage and processing speed. It affect only FPS. */
@property(nonatomic, assign) CGFloat delayTime;

/* optional.
 * Defaults is to not set. unit is seconds, which means unlimited */
@property(nonatomic, assign) NSTimeInterval maxDuration;

/* optional.
 * Defaults is nil */
@property (nonatomic, copy, nullable) NSGIFProgressHandler progressHandler;

/* gif creation job is now proceeding */
@property(atomic, readonly) BOOL proceeding;

- (NSGIFRequest * __nonnull)initWithSourceVideo:(NSURL * __nullable)fileURL;
+ (NSGIFRequest * __nonnull)requestWithSourceVideo:(NSURL * __nullable)fileURL;
+ (NSGIFRequest * __nonnull)requestWithSourceVideo:(NSURL * __nullable)fileURL destination:(NSURL * __nullable)videoFileURL;
+ (NSGIFRequest * __nonnull)requestWithSourceVideoForLivePhoto:(NSURL *__nullable)fileURL;
@end

将来,我将添加以下功能:

  • 从提供的照片 URL 创建。
  • 执行与特定块大小提供的并行处理。
  • 查找特定点。
  • 生成无限长度的 GIF(用特定块大小分割 -> 编码 -> 合并每个编码的 GIF 片段)。
  • 使用与 iOS 的 PhotosKit完美相似的 API。

欢迎提交新功能请求!

许可证

MIT 许可证 下提供使用。请参阅 LICENSE 以获取完整详情。