Make a copy of a video file before uploading

This commit is contained in:
Arnfried Griesert
2024-02-06 05:50:11 +01:00
parent d080240b77
commit 3c08657eb2
2 changed files with 112 additions and 75 deletions

View File

@@ -797,46 +797,25 @@ NSString* MXKFileSizes_description(MXKFileSizes sizes)
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:sendVideoAsset:withThumbnail:)])
{
if (![selectedVideo isKindOfClass:[AVURLAsset class]]) {
MXLogDebug(@"sendSelectedVideoAsset failed because asset is not an AVURLAsset");
return;
}
// Retrieve the video frame at 1 sec to define the video thumbnail
AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:selectedVideo];
assetImageGenerator.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMake(1, 1);
// CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil];
if ([selectedVideo isKindOfClass:[AVURLAsset class]]) {
NSLog(@"AVURLAsset");
CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil];
if(imageRef) {
// Finalize video attachment
UIImage* videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef];
CFRelease(imageRef);
[self.delegate roomInputToolbarView:self sendVideoAsset:selectedVideo withThumbnail:videoThumbnail];
} else {
NSLog(@"Kein AVURLAsset");
MXLogDebug(@"sendSelectedVideoAsset failed because imageRef is nil");
}
// dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
[assetImageGenerator generateCGImagesAsynchronouslyForTimes:@[[NSValue valueWithCMTime:time]] completionHandler:^(CMTime requestedTime, CGImageRef cgImage, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {
// dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Error: %@", error);
NSLog(@"Error: %@", error.localizedDescription);
NSError *dummy = error;
if (result == AVAssetImageGeneratorSucceeded) {
UIImage *thumbnailImage = [UIImage imageWithCGImage:cgImage];
NSLog(@"success: %@", thumbnailImage);
dispatch_sync(dispatch_get_main_queue(), ^{
[self.delegate roomInputToolbarView:self sendVideoAsset:selectedVideo withThumbnail:thumbnailImage];
});
} else if (result == AVAssetImageGeneratorFailed) {
NSLog(@"Error: %@", error.localizedDescription);
NSLog(@"Fehler beim Erstellen des Thumbnails: %@", error);
} else if (result == AVAssetImageGeneratorCancelled) {
NSLog(@"Thumbnail-Erstellung abgebrochen");
}
// });
}];
// });
// Finalize video attachment
// UIImage* videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef];
// CFRelease(imageRef);
// [self.delegate roomInputToolbarView:self sendVideoAsset:selectedVideo withThumbnail:videoThumbnail];
}
else
{