Video Editing

This commit is contained in:
Ilya Laktyushin
2020-05-23 13:26:53 +03:00
parent 29b23c767f
commit 7741978b7e
131 changed files with 3072 additions and 631 deletions

View File

@@ -78,6 +78,7 @@
TGMemoryImageCache *_thumbnailImageCache;
TGMemoryImageCache *_paintingImageCache;
TGMemoryImageCache *_stillPaintingImageCache;
TGMemoryImageCache *_originalImageCache;
TGMemoryImageCache *_originalThumbnailImageCache;
@@ -86,6 +87,7 @@
NSURL *_fullSizeResultsUrl;
NSURL *_paintingDatasUrl;
NSURL *_paintingImagesUrl;
NSURL *_stillPaintingImagesUrl;
NSURL *_videoPaintingImagesUrl;
NSMutableArray *_storeVideoPaintingImages;
@@ -131,6 +133,9 @@
_paintingImageCache = [[TGMemoryImageCache alloc] initWithSoftMemoryLimit:[[self class] imageSoftMemoryLimit]
hardMemoryLimit:[[self class] imageHardMemoryLimit]];
_stillPaintingImageCache = [[TGMemoryImageCache alloc] initWithSoftMemoryLimit:[[self class] imageSoftMemoryLimit]
hardMemoryLimit:[[self class] imageHardMemoryLimit]];
_originalImageCache = [[TGMemoryImageCache alloc] initWithSoftMemoryLimit:[[self class] originalImageSoftMemoryLimit]
hardMemoryLimit:[[self class] originalImageHardMemoryLimit]];
_originalThumbnailImageCache = [[TGMemoryImageCache alloc] initWithSoftMemoryLimit:[[self class] thumbnailImageSoftMemoryLimit]
@@ -145,6 +150,9 @@
_paintingImagesUrl = [NSURL fileURLWithPath:[[[LegacyComponentsGlobals provider] dataStoragePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"paintingimages/%@", _contextId]]];
[[NSFileManager defaultManager] createDirectoryAtPath:_paintingImagesUrl.path withIntermediateDirectories:true attributes:nil error:nil];
_stillPaintingImagesUrl = [NSURL fileURLWithPath:[[[LegacyComponentsGlobals provider] dataStoragePath] stringByAppendingPathComponent:@"stillpaintingimages"]];
[[NSFileManager defaultManager] createDirectoryAtPath:_stillPaintingImagesUrl.path withIntermediateDirectories:true attributes:nil error:nil];
_videoPaintingImagesUrl = [NSURL fileURLWithPath:[[[LegacyComponentsGlobals provider] dataStoragePath] stringByAppendingPathComponent:@"videopaintingimages"]];
[[NSFileManager defaultManager] createDirectoryAtPath:_videoPaintingImagesUrl.path withIntermediateDirectories:true attributes:nil error:nil];
@@ -340,6 +348,27 @@
return result;
}
- (UIImage *)stillPaintingImageForItem:(NSObject<TGMediaEditableItem> *)item
{
NSString *itemId = [self _contextualIdForItemId:item.uniqueIdentifier];
if (itemId == nil)
return nil;
UIImage *result = [_stillPaintingImageCache imageForKey:itemId attributes:NULL];
if (result == nil)
{
NSURL *imageUrl = [_stillPaintingImagesUrl URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", [TGStringUtils md5:itemId]]];
UIImage *diskImage = [UIImage imageWithContentsOfFile:imageUrl.path];
if (diskImage != nil)
{
result = diskImage;
[_stillPaintingImageCache setImage:result forKey:itemId attributes:NULL];
}
}
return result;
}
#pragma mark - Caption
- (NSString *)captionForItem:(id<TGMediaEditableItem>)item
@@ -602,7 +631,7 @@
[_queue dispatch:block];
}
- (bool)setPaintingData:(NSData *)data image:(UIImage *)image forItem:(NSObject<TGMediaEditableItem> *)item dataUrl:(NSURL **)dataOutUrl imageUrl:(NSURL **)imageOutUrl forVideo:(bool)video
- (bool)setPaintingData:(NSData *)data image:(UIImage *)image stillImage:(UIImage *)stillImage forItem:(NSObject<TGMediaEditableItem> *)item dataUrl:(NSURL **)dataOutUrl imageUrl:(NSURL **)imageOutUrl forVideo:(bool)video
{
NSString *itemId = [self _contextualIdForItemId:item.uniqueIdentifier];
@@ -624,10 +653,21 @@
if (dataSuccess && dataOutUrl != NULL)
*dataOutUrl = dataUrl;
if (video)
[_storeVideoPaintingImages addObject:imageUrl];
if (stillImage != nil) {
NSURL *stillImageUrl = [_stillPaintingImagesUrl URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", [TGStringUtils md5:itemId]]];
[_stillPaintingImageCache setImage:stillImage forKey:itemId attributes:NULL];
NSData *stillImageData = UIImagePNGRepresentation(stillImage);
[stillImageData writeToURL:stillImageUrl options:NSDataWritingAtomic error:nil];
if (video)
[_storeVideoPaintingImages addObject:stillImageUrl];
}
return (image == nil || imageSuccess) && (data == nil || dataSuccess);
}