Le moyen le plus rapide de compresser la taille de la vidéo à l’aide de Library ou Algo

J’essaie de compresser des vidéos de haute qualité en moins grandes tailles et je suis en mesure de réduire la taille des vidéos que j’ai compressées à l’aide du code objective-c suivant:

- (BOOL)convertMovieToMP4:(NSSsortingng ) originalMovPath andStoragePath:(NSSsortingng ) compMovPath { NSURL *tmpSourceUrl = [NSURL fileURLWithPath:originalMovPath]; compMovPath = [compMovPath ssortingngByReplacingOccurrencesOfSsortingng:[compMovPath pathExtension] withSsortingng:@"mp4"]; NSURL *tmpDestUrl = [NSURL fileURLWithPath:compMovPath]; AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:tmpSourceUrl options:nil]; AVMutableComposition* mixComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil]; [compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; CGSize videoSize = [[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize]; CATextLayer *titleLayer = [CATextLayer layer]; titleLayer.ssortingng = @"Ojatro"; titleLayer.font = (_bridge CFTypeRef Nullable)(@"Helvetica"); titleLayer.fontSize = videoSize.height / 8; titleLayer.shadowOpacity = 0.2; titleLayer.alignmentMode = kCAAlignmentCenter; titleLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height / 6); titleLayer.position=CGPointMake(videoSize.width/2, videoSize.height/2); CALayer *parentLayer = [CALayer layer]; CALayer *videoLayer = [CALayer layer]; parentLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height); videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height); [parentLayer addSublayer:videoLayer]; [parentLayer addSublayer:titleLayer]; AVMutableVideoComposition* videoComp = [AVMutableVideoComposition videoComposition]; videoComp.renderSize = videoSize; videoComp.frameDuration = CMTimeMake(1, 30); videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mixComposition duration]); AVAssetTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack]; instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction]; videoComp.instructions = [NSArray arrayWithObject: instruction]; AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];//AVAssetExportPresetPasst _assetExport.videoComposition = videoComp; //NSSsortingng* videoName = @"mynewwatermarkedvideo.mov"; NSSsortingng *tmpDirPath = [compMovPath ssortingngByReplacingOccurrencesOfSsortingng:[compMovPath lastPathComponent] withSsortingng:@""]; if ([Utility makeDirectoryAtPath:tmpDirPath]) { NSLog(@"Directory Created"); } //exportPath=[exportPath ssortingngByAppendingSsortingng:videoName]; NSURL *exportUrl = tmpDestUrl; if ([[NSFileManager defaultManager] fileExistsAtPath:compMovPath]) { [[NSFileManager defaultManager] removeItemAtPath:compMovPath error:nil]; } _assetExport.outputURL = exportUrl; _assetExport.shouldOptimizeForNetworkUse = YES; _assetExport.outputFileType = AVFileTypeMPEG4; //[strRecordedFilename setSsortingng: exportPath]; [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { switch (_assetExport.status) { case AVAssetExportSessionStatusUnknown: NSLog(@"Export Status Unknown"); break; case AVAssetExportSessionStatusWaiting: NSLog(@"Export Waiting"); break; case AVAssetExportSessionStatusExporting: NSLog(@"Export Status"); break; case AVAssetExportSessionStatusCompleted: NSLog(@"Export Completed"); totalFilesCopied++; [self startProgressBar]; break; case AVAssetExportSessionStatusFailed: NSLog(@"Export failed"); break; case AVAssetExportSessionStatusCancelled: NSLog(@"Export canceled"); break; } } ]; return NO; } 

Mais mon problème principal est que lorsque je compresse un fichier vidéo de 500 Mo (c’est-à-dire une vidéo moyenne), cela prend environ 20 à 30 minutes ou plus. Il réduit la taille de la vidéo à environ 130 Mo. J’utilise la bibliothèque native AVFoundation pour compresser la vidéo afin de réduire sa taille.

J’ai besoin de compresser la taille de la vidéo très rapidement, tout comme l’application Apple Compressor. Elle compresse le fichier de 500 Mo en 30 secondes seulement …

https://itunes.apple.com/fr/app/compressor/id424390742?mt=12

J’ai aussi utilisé la bibliothèque FFMPEG pour cela, mais c’est aussi lent, je n’ai plus trouvé cette bibliothèque utile.

J’ai également essayé de trouver la solution en utilisant d’autres langages tels que java, python. mais n’a pas trouvé aucune solution a été trouvée.

Si quelqu’un a la solution à ce problème particulier, ou a des bibliothèques (par exemple, une bibliothèque payante ou une bibliothèque open source) qui peuvent effectuer la compression en moins de temps, au moins 1 minute … Merci de partager avec moi. Ou un autre élément de code capable de résoudre le problème du temps de compression de 20 à 30 minutes à au moins 1 minute.

Merci…

Voici un document contenant des informations RnD sur la compression vidéo: https://drive.google.com/file/d/0BySTUFVtfzJmM3pYeVRiWmxSLVU/view

Il contient également un exemple de code pour la compression rapide de vidéos dans Objective-C. Il utilise AVAssetExportSession pour la compression de vidéos.