Video tool manager
- Trim video or audio.
- Convert audio to video.
- Convert video to audio.
- Merge video with audio.
- Export video with different quality.
- for example i have mp4 file(old.mp4 (720p)) i want to convert video quality to 480p:
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *filePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"old.mp4"];
// you can select another quality by typing AVAssetExportPreset and xcode will show you :)
[BHVideoManager ExportVideo:filePath WithQuality:AVAssetExportPreset640x480 SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"videoExported" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
- for example i have m4a file(CleanBandit-Rockabye.m4a) i want trim half of time:
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *filePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"CleanBandit-Rockabye.m4a"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:filePath options:nil];
[BHVideoManager TrimAudioWithPath:filePath StartTime:kCMTimeZero EndTime:CMTimeMake(asset.duration.value /2, asset.duration.timescale) SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"test" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
- for example i have mp4 file(old.mp4) i want trim half of time:
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *filePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"old.mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:filePath options:nil];
[BHVideoManager TrimVideoWithPath:filePath StartTime:kCMTimeZero EndTime:CMTimeMake(asset.duration.value/2, asset.duration.timescale) SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"test2" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *VideofilePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"test2.mp4"];
NSURL *audioFilePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"test.m4a"];
[BHVideoManager MergeVideo:VideofilePath WithAudio:audioFilePath SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"VideoMerged" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
- for example i have mp4 file(test2.mp4):
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *filePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"test2.mp4"];
[BHVideoManager ConvertVideoToAudioWithPath:filePath SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"VideoConverted" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
- for example i have m4a file(VideoConverted.m4a):
NSString *documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
NSURL *filePath = [[NSURL fileURLWithPath:documentsDirectoryPath] URLByAppendingPathComponent:@"VideoConverted.m4a"];
[BHVideoManager ConvertAudioToVideoWithPath:filePath SaveFileToPath:[NSURL fileURLWithPath:documentsDirectoryPath] TitleFile:@"AudioConverted" CompletionHandler:^(AVAssetExportSession *exportsession) {
if (AVAssetExportSessionStatusFailed == exportsession.status) {
NSLog(@"faild:%@", exportsession.error);
} else if (AVAssetExportSessionStatusCompleted == exportsession.status) {
NSLog(@"Done");
}
}];
To run the example project, clone the repo, and run pod install
from the Example directory first.
BHVideoManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BHVideoManager'
BandarHL, bandarhl
BHVideoManager is available under the MIT license. See the LICENSE file for more info.