almost 8 years ago
Hello all, Refer the code below to compress the video file and save the compressed file in document directory.
- (void)compressMyVideo:(NSURL *)videoPath completionBlock:(void(^)(id data, BOOL result))block{ NSLog(@"compressing ====%@", videoPath); completionBlock = block; NSURL *videoURL = videoPath;//[NSURL fileURLWithPath:videoPath]; NSLog(@"video url is== %@", videoURL); NSString *outputPath = [self outputFilePath]; NSURL *outputURL = [NSURL fileURLWithPath:outputPath]; [self convertVideoToLowQuailtyWithInputURL:videoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession) { if (exportSession.status == AVAssetExportSessionStatusCompleted) { printf("completed\n"); completionBlock(outputURL, YES); } else { printf("error\n"); completionBlock(nil, NO); } }]; } // Getting the path of outPut file - (NSString *)outputFilePath{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"compressed.MOV"]; NSFileManager *fileManager = [NSFileManager defaultManager]; // return path; if ([fileManager fileExistsAtPath: path]) { [fileManager removeItemAtPath:path error:nil]; } path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"compressed.MOV"] ]; NSLog(@"path is== %@", path); return path; } // Actual compression is here. - (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler { // [self startCompressingTheVideo:outputURL]; // // // return; [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; // AVAssetWriter AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; // exportSession.fileLengthLimit = 30*1024; exportSession.outputURL = outputURL; exportSession.outputFileType = AVFileTypeQuickTimeMovie; [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { handler(exportSession); // [exportSession release]; }]; }
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)