Skip to content

Commit

Permalink
VMVideoNAudioMerger: Add +mergeVideoNAudioFiles:atFolderPath:preferre…
Browse files Browse the repository at this point in the history
…dResultName:completion:
  • Loading branch information
Kjuly committed Jul 18, 2020
1 parent dff02cd commit c58ff73
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
7F52B3FB24C05A440048AE58 /* VMPythonResourceDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F52B3EF24C05A440048AE58 /* VMPythonResourceDownloader.m */; };
7F52B3FC24C05A440048AE58 /* VMDownloadOperationConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F52B3F224C05A440048AE58 /* VMDownloadOperationConstants.m */; };
7F52B3FD24C05A440048AE58 /* VMPythonDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F52B3F324C05A440048AE58 /* VMPythonDownloadOperation.m */; };
7F92A79924C1E13E00D3A15C /* VMVideoNAudioMerger.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F92A79824C1E13E00D3A15C /* VMVideoNAudioMerger.m */; };
7F6D774E24C2F6FA00294B9F /* VMVideoNAudioMerger.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F6D774D24C2F6FA00294B9F /* VMVideoNAudioMerger.m */; };
7F6D775124C2F73F00294B9F /* VMMergingAssetTrackModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F6D775024C2F73F00294B9F /* VMMergingAssetTrackModel.m */; };
7FFEE24624A883DE0071144F /* AFNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FFEE24524A883DE0071144F /* AFNetworking.framework */; };
7FFEE24A24A883E10071144F /* MBProgressHUD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FFEE24924A883E10071144F /* MBProgressHUD.framework */; };
7FFEE25A24AADB9D0071144F /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FFEE25924AADB9C0071144F /* libbz2.tbd */; };
Expand Down Expand Up @@ -105,8 +106,10 @@
7F52B3F424C05A440048AE58 /* VMDownloadOperationConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMDownloadOperationConstants.h; sourceTree = "<group>"; };
7F52B3F524C05A440048AE58 /* VMPythonResourceDownloaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMPythonResourceDownloaderDelegate.h; sourceTree = "<group>"; };
7F52B3F624C05A440048AE58 /* VMPythonResourceDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMPythonResourceDownloader.h; sourceTree = "<group>"; };
7F92A79724C1E13E00D3A15C /* VMVideoNAudioMerger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMVideoNAudioMerger.h; sourceTree = "<group>"; };
7F92A79824C1E13E00D3A15C /* VMVideoNAudioMerger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VMVideoNAudioMerger.m; sourceTree = "<group>"; };
7F6D774C24C2F6FA00294B9F /* VMVideoNAudioMerger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMVideoNAudioMerger.h; sourceTree = "<group>"; };
7F6D774D24C2F6FA00294B9F /* VMVideoNAudioMerger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VMVideoNAudioMerger.m; sourceTree = "<group>"; };
7F6D774F24C2F73F00294B9F /* VMMergingAssetTrackModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMMergingAssetTrackModel.h; sourceTree = "<group>"; };
7F6D775024C2F73F00294B9F /* VMMergingAssetTrackModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VMMergingAssetTrackModel.m; sourceTree = "<group>"; };
7FFEE24524A883DE0071144F /* AFNetworking.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AFNetworking.framework; path = ../Carthage/Build/iOS/AFNetworking.framework; sourceTree = "<group>"; };
7FFEE24924A883E10071144F /* MBProgressHUD.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MBProgressHUD.framework; path = ../Carthage/Build/iOS/MBProgressHUD.framework; sourceTree = "<group>"; };
7FFEE25924AADB9C0071144F /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -284,8 +287,7 @@
children = (
7F52B3E424C05A440048AE58 /* VMFileSizeCalculator.h */,
7F52B3E524C05A440048AE58 /* VMFileSizeCalculator.m */,
7F92A79724C1E13E00D3A15C /* VMVideoNAudioMerger.h */,
7F92A79824C1E13E00D3A15C /* VMVideoNAudioMerger.m */,
7F6D774B24C2F6FA00294B9F /* VMVideoNAudioMerger */,
);
path = Others;
sourceTree = "<group>";
Expand Down Expand Up @@ -332,6 +334,17 @@
path = VMPythonDownloadOperation;
sourceTree = "<group>";
};
7F6D774B24C2F6FA00294B9F /* VMVideoNAudioMerger */ = {
isa = PBXGroup;
children = (
7F6D774C24C2F6FA00294B9F /* VMVideoNAudioMerger.h */,
7F6D774D24C2F6FA00294B9F /* VMVideoNAudioMerger.m */,
7F6D774F24C2F73F00294B9F /* VMMergingAssetTrackModel.h */,
7F6D775024C2F73F00294B9F /* VMMergingAssetTrackModel.m */,
);
path = VMVideoNAudioMerger;
sourceTree = "<group>";
};
7FFEE25824AADB9C0071144F /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -510,9 +523,10 @@
files = (
7F52B3F924C05A440048AE58 /* VMWebResourceOptionModel.m in Sources */,
7F52B3FB24C05A440048AE58 /* VMPythonResourceDownloader.m in Sources */,
7F92A79924C1E13E00D3A15C /* VMVideoNAudioMerger.m in Sources */,
7F6D774E24C2F6FA00294B9F /* VMVideoNAudioMerger.m in Sources */,
7F4CB57F24A42AAB00CC0889 /* ViewController.m in Sources */,
7F4CB57924A42AAB00CC0889 /* AppDelegate.m in Sources */,
7F6D775124C2F73F00294B9F /* VMMergingAssetTrackModel.m in Sources */,
7F52B3FD24C05A440048AE58 /* VMPythonDownloadOperation.m in Sources */,
7F52B3FA24C05A440048AE58 /* VMResourceDownloader.m in Sources */,
7F08BBD924AF1E1700B3F5EB /* Constants.m in Sources */,
Expand Down
27 changes: 27 additions & 0 deletions PythonForVideoMemos-Demo/PythonForVideoMemos-Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#import "VMPythonResourceDownloader.h"
#import "VMWebResourceModel.h"

#define DEBUG_VMVideoNAudioMerger 1
#ifdef DEBUG_VMVideoNAudioMerger
#import "VMVideoNAudioMerger.h"
#endif // END #ifdef DEBUG_VMVideoNAudioMerger


static NSString * const kVideosFolderName_ = @"videos";

Expand Down Expand Up @@ -114,6 +119,27 @@ - (void)viewDidAppear:(BOOL)animated
if (![fileManager fileExistsAtPath:savePath]) {
[fileManager createDirectoryAtPath:savePath withIntermediateDirectories:NO attributes:nil error:NULL];
}

#ifdef DEBUG_VMVideoNAudioMerger
/*
NSString *videoFilePath = [savePath stringByAppendingPathComponent:@"id=2455392162450265036[00].mp4"];
NSString *audioFilePath = [savePath stringByAppendingPathComponent:@"id=2455392162450265036[01].mp4"];
NSString *resultPath = [savePath stringByAppendingPathComponent:@"id=2455392162450265036.mp4"];
[VMVideoNAudioMerger mergeVideoFileAtPath:videoFilePath withAudioFileAtPath:audioFilePath intoResultPath:resultPath];
*/
// [VMVideoNAudioMerger mergeVideoNAudioFilesWithIdentifier:@"id=2455392162450265036"
// atFolderPath:savePath
// completion:^(NSString *mergedFilePath, NSString *mergingErrorMessage) {
// }];
NSArray <NSString *> *filenames = @[@"id=2455392162450265036[00].mp4", @"id=2455392162450265036[01].mp4"];
[VMVideoNAudioMerger mergeVideoNAudioFiles:filenames
atFolderPath:savePath
preferredResultName:@"id=2455392162450265036"
completion:^(NSString *mergedFilePath, NSString *mergingErrorMessage) {

}];

#else
VMPythonResourceDownloader *downloader = [VMPythonResourceDownloader sharedInstance];
downloader.savePath = savePath;
downloader.cacheJSONFile = YES;
Expand Down Expand Up @@ -149,6 +175,7 @@ - (void)viewDidAppear:(BOOL)animated
[weakSelf _presentAlertWithTitle:nil message:errorMessage];
}
}];
#endif // END #ifdef DEBUG_VMVideoNAudioMerger
}

#pragma mark - Private
Expand Down
24 changes: 0 additions & 24 deletions PythonForVideoMemos/VMPython/Others/VMVideoNAudioMerger.h

This file was deleted.

98 changes: 0 additions & 98 deletions PythonForVideoMemos/VMPython/Others/VMVideoNAudioMerger.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// VMMergingAssetTrackModel.h
// PythonForVideoMemos-Demo
//
// Created by Kjuly on 18/7/2020.
// Copyright © 2020 Kjuly. All rights reserved.
//

@import Foundation;
@import AVFoundation;


NS_ASSUME_NONNULL_BEGIN

@interface VMMergingAssetTrackModel : NSObject

@property (nonatomic, strong) AVURLAsset *asset;
@property (nonatomic, assign) AVMediaType mediaType;
@property (nonatomic, strong) AVAssetTrack *track;
@property (nonatomic, assign) CMTime duration;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// VMMergingAssetTrackModel.m
// PythonForVideoMemos-Demo
//
// Created by Kjuly on 18/7/2020.
// Copyright © 2020 Kjuly. All rights reserved.
//

#import "VMMergingAssetTrackModel.h"

@implementation VMMergingAssetTrackModel

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// VMVideoNAudioMerger.h
// PythonForVideoMemos-Demo
//
// Created by Kjuly on 17/7/2020.
// Copyright © 2020 Kjuly. All rights reserved.
//

@import Foundation;

NS_ASSUME_NONNULL_BEGIN

typedef void (^VMVideoNAudioMergerCompletion)(NSString *_Nullable mergedFilePath, NSString *_Nullable mergingErrorMessage);

@interface VMVideoNAudioMerger : NSObject

/**
* Merge video & audio files
*
* @param identifier The unique filename, generally, same to VMPythonResourceDownloader's `preferredName`.
* @param folderPath The path to folder that hosts video & audio files, and also, the merged file will be exporeted there.
* @param completion The bloack to execute when completed.
*/
//+ (void)mergeVideoNAudioFilesWithIdentifier:(NSString *)identifier
// atFolderPath:(NSString *)folderPath
// completion:(VMVideoNAudioMergerCompletion)completion;

/**
* Merge video & audio files
*
* @param filenames The video & audio filenames
* @param folderPath The path to folder that hosts video & audio files, and also, the merged file will be exporeted there.
* @param preferredResultName The preferred merging result filename
* @param completion The bloack to execute when completed.
*/
+ (void)mergeVideoNAudioFiles:(NSArray <NSString *> *)filenames
atFolderPath:(NSString *)folderPath
preferredResultName:(NSString *)preferredResultName
completion:(VMVideoNAudioMergerCompletion)completion;

//+ (void)mergeVideoFileAtPath:(NSString *)videoFilePath
// withAudioFileAtPath:(NSString *)audioFilePath
// intoResultPath:(NSString *)resultPath
// completion:(VMVideoNAudioMergerCompletion)completion;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit c58ff73

Please sign in to comment.