UGCKitMedia.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2019 Tencent. All rights reserved.
  2. #import "UGCKitMedia.h"
  3. #import "SDKHeader.h"
  4. @interface UGCKitMedia ()
  5. {
  6. AVAsset *_videoAsset;
  7. NSArray<UIImage *> *_images;
  8. CGSize _size;
  9. }
  10. @property (nonatomic) CGSize size;
  11. @end
  12. @implementation UGCKitMedia
  13. - (instancetype)initWithAVAsset:(AVAsset *)asset images:(NSArray<UIImage *> *)images {
  14. if (self = [super init]) {
  15. _videoAsset = asset;
  16. _images = images;
  17. if (asset) {
  18. TXVideoInfo *videoInfo = [TXVideoInfoReader getVideoInfoWithAsset:asset];
  19. _size = CGSizeMake(videoInfo.width, videoInfo.height);
  20. }
  21. if (_videoAsset) {
  22. _isVideo = YES;
  23. }
  24. }
  25. return self;
  26. }
  27. - (instancetype)initWithVideoPath:(NSString *)path {
  28. if (self = [self initWithAVAsset:[AVAsset assetWithURL:[NSURL fileURLWithPath:path]] images:nil]) {
  29. _videoPath = path;
  30. }
  31. return self;
  32. }
  33. + (instancetype)mediaWithVideoPath:(NSString *)path
  34. {
  35. return [[UGCKitMedia alloc] initWithVideoPath:path];
  36. }
  37. + (instancetype)mediaWithAVAsset:(AVAsset *)asset {
  38. return [[UGCKitMedia alloc] initWithAVAsset:asset images:nil];
  39. }
  40. + (instancetype)mediaWithImages:(NSArray<UIImage *> *)images canvasSize:(CGSize)canvasSize {
  41. UGCKitMedia *asset = [[UGCKitMedia alloc] initWithAVAsset:nil images:images];
  42. asset.size = canvasSize;
  43. return asset;
  44. }
  45. @end