Skip to content

Commit

Permalink
issue 3 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
“Henry” committed Apr 4, 2019
1 parent 45b8da2 commit 7c3e5a7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
2 changes: 2 additions & 0 deletions WAVideoBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 55RAX8ZP36;
INFOPLIST_FILE = WAVideoBox/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -583,6 +584,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 55RAX8ZP36;
INFOPLIST_FILE = WAVideoBox/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
4 changes: 2 additions & 2 deletions WAVideoBox/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ - (IBAction)compressVideo:(id)sender {
__weak typeof(self) wself = self;

[_videoBox appendVideoByPath:_videoPath];
_videoBox.ratio = WAVideoExportRatioLowQuality;
// _videoBox.videoQuality = 1; 有两种方法可以压缩
_videoBox.ratio = WAVideoExportRatio960x540;
_videoBox.videoQuality = 1; // 有两种方法可以压缩
[_videoBox asyncFinishEditByFilePath:filePath complete:^(NSError *error) {
if (!error) {
[wself goToPlayVideoByFilePath:filePath];
Expand Down
5 changes: 3 additions & 2 deletions WAVideoBox/WAVideoBox/WAAVSeCommand/WAAVSEExportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

@property (nonatomic , strong)AVAssetExportSession *exportSession;

/**
只有在开启画布的时候并且不是自动分辩率下才有效
*/
@property (nonatomic , assign) NSInteger videoQuality;

- (void)performSaveByPath:(NSString *)path;

- (void)performSaveAsset:(AVAsset *)asset byPath:(NSString *)path;

- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;

@end
22 changes: 13 additions & 9 deletions WAVideoBox/WAVideoBox/WAAVSeCommand/WAAVSEExportCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation WAAVSEExportCommand

- (instancetype)initWithComposition:(WAAVSEComposition *)composition{
if (self = [super initWithComposition:composition]) {
self.videoQuality = 6;
self.videoQuality = 0;
}
return self;
}
Expand Down Expand Up @@ -48,28 +48,32 @@ - (void)performSaveAsset:(AVAsset *)asset byPath:(NSString *)path{
self.exportSession.videoComposition = self.composition.mutableVideoComposition;
self.exportSession.audioMix = self.composition.mutableAudioMix;

self.exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [self.composition duration]);

self.exportSession.outputURL = [NSURL fileURLWithPath:path];
self.exportSession.outputFileType = self.composition.fileType;

if (self.videoQuality) {

if ([self.composition.presetName isEqualToString:AVAssetExportPreset640x480]) {
self.ratioParam = 0.02;
self.ratioParam = 0.02 ;
}

if ([self.composition.presetName isEqualToString:AVAssetExportPreset960x540]) {
self.ratioParam = 0.04;
self.ratioParam = 0.04 ;
}

if ([self.composition.presetName isEqualToString:AVAssetExportPreset1280x720]) {
self.ratioParam = 0.08;
self.ratioParam = 0.08 ;
}

if (self.ratioParam) {
self.exportSession.fileLengthLimit = CMTimeGetSeconds(self.composition.duration) * self.ratioParam * self.composition.videoQuality * 1024 * 1024;
self.exportSession.fileLengthLimit = CMTimeGetSeconds(self.composition.duration) * self.ratioParam * self.composition.videoQuality * 1024 * 1024;
}

}

self.exportSession.outputURL = [NSURL fileURLWithPath:path];
self.exportSession.outputFileType = self.composition.fileType;

[self.exportSession exportAsynchronouslyWithCompletionHandler:^(void){

switch (self.exportSession.status) {
Expand Down
2 changes: 1 addition & 1 deletion WAVideoBox/WAVideoBox/WAVideoBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef NS_ENUM(NSUInteger,WAVideoExportRatio) {
@property (nonatomic , assign) WAVideoExportRatio ratio;

/**
输出的视频质量(0~10),默认为0(自动),6差不多抖音视频质量平级,自动分辩率下无效
输出的视频质量(0~10),默认为0(不开启),6差不多抖音视频质量平级,此参数有可能会加长处理时长。自动分辩率下此参数会自动失效
*/
@property (nonatomic , assign) NSInteger videoQuality;

Expand Down
17 changes: 15 additions & 2 deletions WAVideoBox/WAVideoBox/WAVideoBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ @interface WAVideoBox (){

@property (nonatomic , copy) NSString *filePath;

@property (nonatomic , copy) NSString *tmpPath;
@property (nonatomic , copy) NSString *tmpPath; //当前临时合成的文件位置

@property (nonatomic , copy) void (^editorComplete)(NSError *error);

Expand Down Expand Up @@ -499,7 +499,6 @@ - (void)__internalClean{
}
self.filePath = nil;
self.tmpPath = nil;

self.directCompostionIndex = 0;

}
Expand Down Expand Up @@ -550,7 +549,16 @@ - (void)processVideoByComposition:(WAAVSEComposition *)composition{
self.tmpPath = filePath = [self tmpVideoFilePath];
}


// 这里需要逐帧扫描
if (self.videoQuality && self.composeCount == 1 && self.tmpVideoSpace.count == 0 && !composition.mutableVideoComposition) {
WAAVSECommand *command = [[WAAVSECommand alloc] initWithComposition:composition];
[command performWithAsset:composition.mutableComposition];
[command performVideoCompopsition];
}

WAAVSEExportCommand *exportCommand = [[WAAVSEExportCommand alloc] initWithComposition:composition];
exportCommand.videoQuality = self.videoQuality;
self.exportCommand = exportCommand;
[exportCommand performSaveByPath:filePath];

Expand Down Expand Up @@ -583,10 +591,15 @@ - (void)successToProcessCurrentCompostion{
[assetAry addObject:[AVAsset assetWithURL:[NSURL fileURLWithPath:filePath]]];
}
[mixComand performWithAssets:assetAry];
if (self.videoQuality) { // 需要逐帧对画面处理
[mixComand performVideoCompopsition];
}

mixComand.composition.presetName = self.presetName;
mixComand.composition.videoQuality = self.videoQuality;

WAAVSEExportCommand *exportCommand = [[WAAVSEExportCommand alloc] initWithComposition:mixComand.composition];
exportCommand.videoQuality = self.videoQuality;
self.exportCommand = exportCommand;
[exportCommand performSaveByPath:self.filePath];

Expand Down

0 comments on commit 7c3e5a7

Please sign in to comment.