Skip to content

Commit

Permalink
Merge pull request #27 from depthlove/master
Browse files Browse the repository at this point in the history
release v1.7.0
  • Loading branch information
lawder authored Nov 28, 2017
2 parents e98ec9a + fdbf1af commit 10fd791
Show file tree
Hide file tree
Showing 95 changed files with 3,457 additions and 191 deletions.
64 changes: 64 additions & 0 deletions APIDiffs/api-diffs-1.7.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# PLShortVideoKit 1.6.0 to 1.7.0 API Differences

## General Headers

- *Added* class `PLSVideoEditingView`

- *Added* class `PLSVideoEdit`

- *Added* class `PLSText`

- *Added* class `PLSImageToMovieComposer`



```
PLShortVideoRecorder.h
```

- *Added* - (void)insertVideo:(NSURL *_Nonnull)videoURL;
- *Added* - (void)mixAudio:(NSURL *_Nullable)audioURL;
- *Added* - (void)mixWithMusicVolume:(float)musicVolume videoVolume:(float)videoVolume completionHandler:(void (^_Nonnull)(AVMutableComposition * _Nullable composition, AVAudioMix * _Nullable audioMix, NSError * _Nullable error))completionHandler;



```
PLShortVideoEditor.h
```

- *Added* - (PLSPreviewOrientation)rotateVideoLayer;
- *Added* - (void)resetVideoLayerOrientation;


```
PLSEditPlayer.h
```

- *Added* - (PLSPreviewOrientation)rotateVideoLayer;
- *Added* - (void)resetVideoLayerOrientation;


```
PLSAVAssetExportSession.h
```

- *Added* @property (assign, nonatomic) PLSPreviewOrientation videoLayerOrientation;



















102 changes: 94 additions & 8 deletions Example/PLShortVideoKitDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

139 changes: 123 additions & 16 deletions Example/PLShortVideoKitDemo/EditViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import "PLShortVideoKit/PLShortVideoKit.h"
#import <AssetsLibrary/AssetsLibrary.h>

#import "PLSVideoEditingController.h"


#define PLS_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define PLS_SCREEN_WIDTH CGRectGetWidth([UIScreen mainScreen].bounds)
Expand All @@ -34,7 +37,8 @@ @interface EditViewController ()
PLSRateButtonViewDelegate,
DubViewControllerDelegate,
PLShortVideoEditorDelegate,
PLSAVAssetExportSessionDelegate
PLSAVAssetExportSessionDelegate,
PLSVideoEditingControllerDelegate
>

// 水印
Expand Down Expand Up @@ -72,7 +76,7 @@ @interface EditViewController ()
@property (strong, nonatomic) NSMutableArray *mvArray;
@property (strong, nonatomic) NSURL *colorURL;
@property (strong, nonatomic) NSURL *alphaURL;
//时光倒流
// 时光倒流
@property (nonatomic, strong) PLSReverserEffect *reverser;
@property (nonatomic, strong) AVAsset *inputAsset;
@property (nonatomic, strong) UIButton *reverserButton;
Expand All @@ -86,6 +90,11 @@ @interface EditViewController ()
@property (strong, nonatomic) NSArray *titleArray;
@property (strong, nonatomic) NSMutableDictionary *originMovieSettings;

// 视频旋转
@property (assign, nonatomic) PLSPreviewOrientation videoLayerOrientation;

// 添加文字、图片、涂鸦, 需要保存到编辑数据
@property (strong, nonatomic) PLSVideoEdit *videoEdit;

@end

Expand All @@ -112,6 +121,20 @@ - (id)checkNSNullType:(id)object {
}
}

// 获取视频第一帧
- (UIImage *) getVideoPreViewImage:(AVAsset *)asset {
AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];

assetGen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
return videoImage;
}

#pragma mark -- viewDidLoad

- (void)viewDidLoad {
Expand All @@ -122,9 +145,6 @@ - (void)viewDidLoad {
[self setupEditToolboxView];
[self setupMergeToolboxView];

// 视频的分辨率,设置之后影响编辑时的预览分辨率、导出的视频的的分辨率
self.videoSize = CGSizeMake(544, 960);

// 编辑
/* outputSettings 中的字典元素为 movieSettings, audioSettings, watermarkSettings */
self.outputSettings = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -172,11 +192,14 @@ - (void)viewDidLoad {
self.shortVideoEditor.timeRange = CMTimeRangeMake(start, duration);
// 视频编辑时,添加水印
[self.shortVideoEditor setWaterMarkWithImage:watermarkImage position:self.watermarkPosition];
// 视频的分辨率,设置之后影响编辑时的预览分辨率、导出的视频的的分辨率
// self.videoSize = CGSizeMake(544, 960);
// 视频编辑时,改变预览分辨率
self.shortVideoEditor.videoSize = self.videoSize;

// 滤镜
self.filterGroup = [[PLSFilterGroup alloc] init];
UIImage *coverImage = [self getVideoPreViewImage:self.movieSettings[PLSAssetKey]];
self.filterGroup = [[PLSFilterGroup alloc] initWithImage:coverImage];
}

- (void)viewWillAppear:(BOOL)animated {
Expand Down Expand Up @@ -247,7 +270,7 @@ - (void)setupEditToolboxView {

UIScrollView *buttonScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, PLS_SCREEN_WIDTH, 35)];
buttonScrollView.backgroundColor = PLS_RGBCOLOR(25, 24, 36);
buttonScrollView.contentSize = CGSizeMake(582, 35);
buttonScrollView.contentSize = CGSizeMake(672, 35);
buttonScrollView.contentOffset = CGPointMake(0, 0);
buttonScrollView.pagingEnabled = YES;
buttonScrollView.bounces = YES;
Expand Down Expand Up @@ -280,7 +303,6 @@ - (void)setupEditToolboxView {
[musicButton addTarget:self action:@selector(musicButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:musicButton];


// MV 特效
UIButton *mvButton = [UIButton buttonWithType:UIButtonTypeCustom];
mvButton.frame = CGRectMake(267, 0, 35, 35);
Expand All @@ -306,7 +328,6 @@ - (void)setupEditToolboxView {
self.reverserButton.selected = NO;
[self.reverserButton addTarget:self action:@selector(reverserButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:_reverserButton];


// 制作Gif图
UIButton *formGifButton = [UIButton buttonWithType:UIButtonTypeCustom];
Expand All @@ -315,7 +336,6 @@ - (void)setupEditToolboxView {
formGifButton.titleLabel.font = [UIFont systemFontOfSize:14];
[formGifButton addTarget:self action:@selector(formatGifButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:formGifButton];


// 裁剪背景音乐
UIButton *clipMusicButton = [UIButton buttonWithType:UIButtonTypeCustom];
Expand All @@ -324,14 +344,12 @@ - (void)setupEditToolboxView {
[clipMusicButton addTarget:self action:@selector(clipMusicButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:clipMusicButton];


// 音量调节
UIButton *volumeButton = [UIButton buttonWithType:UIButtonTypeCustom];
volumeButton.frame = CGRectMake(492, 0, 35, 35);
[volumeButton setImage:[UIImage imageNamed:@"icon_volume"] forState:UIControlStateNormal];
[volumeButton addTarget:self action:@selector(volumeChangeEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:volumeButton];


// 关闭原声
UIButton *closeSoundButton = [UIButton buttonWithType:UIButtonTypeCustom];
Expand All @@ -340,7 +358,20 @@ - (void)setupEditToolboxView {
[closeSoundButton setImage:[UIImage imageNamed:@"btn_close_sound"] forState:UIControlStateSelected];
[closeSoundButton addTarget:self action:@selector(closeSoundButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:closeSoundButton];


// 视频旋转
UIButton *rotateVideoButton = [UIButton buttonWithType:UIButtonTypeCustom];
rotateVideoButton.frame = CGRectMake(582, 0, 35, 35);
[rotateVideoButton setImage:[UIImage imageNamed:@"rotate"] forState:UIControlStateNormal];
[rotateVideoButton addTarget:self action:@selector(rotateVideoButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:rotateVideoButton];

// 添加文字、图片、涂鸦
UIButton *addTextButton = [UIButton buttonWithType:UIButtonTypeCustom];
addTextButton.frame = CGRectMake(627, 0, 35, 35);
[addTextButton setImage:[UIImage imageNamed:@"btn_add_text"] forState:UIControlStateNormal];
[addTextButton addTarget:self action:@selector(addTextButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
[buttonScrollView addSubview:addTextButton];

// 倍数处理
self.titleArray = @[@"极慢", @"", @"正常", @"", @"极快"];
Expand Down Expand Up @@ -401,10 +432,12 @@ - (void)removeActivityIndicatorView {
for (NSDictionary *filterInfoDic in self.filterGroup.filtersInfo) {
NSString *name = [filterInfoDic objectForKey:@"name"];
NSString *coverImagePath = [filterInfoDic objectForKey:@"coverImagePath"];

NSString *coverImage = [filterInfoDic objectForKey:@"coverImage"];

NSDictionary *dic = @{
@"name" : name,
@"coverImagePath" : coverImagePath
@"coverImagePath" : coverImagePath,
@"coverImage" : coverImage
};

[array addObject:dic];
Expand Down Expand Up @@ -565,9 +598,12 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

NSString *name = [filterInfoDic objectForKey:@"name"];
NSString *coverImagePath = [filterInfoDic objectForKey:@"coverImagePath"];

UIImage *coverImage = [filterInfoDic objectForKey:@"coverImage"];
cell.iconPromptLabel.text = name;
cell.iconImageView.image = [UIImage imageWithContentsOfFile:coverImagePath];
if (coverImage) {
cell.iconImageView.image = coverImage;
}

} else if (self.selectionViewIndex == 1) {
// 音乐
Expand Down Expand Up @@ -664,6 +700,21 @@ - (void)addMVLayerWithColor:(NSURL *)colorURL alpha:(NSURL *)alphaURL {
self.colorURL = colorURL;
self.alphaURL = alphaURL;

// 添加了 MV 特效,就需要让原视频和 MV 特效视频的分辨率相同
if (self.colorURL && self.alphaURL) {
AVAsset *asset = [AVAsset assetWithURL:self.colorURL];
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if (videoTracks.count > 0) {
AVAssetTrack *videoTrack = videoTracks[0];
CGSize naturalSize = videoTrack.naturalSize;
self.videoSize = CGSizeMake(naturalSize.width, naturalSize.height);
self.shortVideoEditor.videoSize = self.videoSize;
}
} else {
self.videoSize = CGSizeZero;
self.shortVideoEditor.videoSize = self.videoSize;
}

[self.shortVideoEditor addMVLayerWithColor:self.colorURL alpha:self.alphaURL];
}

Expand Down Expand Up @@ -835,6 +886,51 @@ - (void)closeSoundButtonEvent:(UIButton *)button {
self.movieSettings[PLSVolumeKey] = [NSNumber numberWithFloat:self.shortVideoEditor.volume];
}

#pragma mark -- 旋转视频
- (void)rotateVideoButtonEvent:(UIButton *)button {
self.videoLayerOrientation = [self.shortVideoEditor rotateVideoLayer];
NSLog(@"videoLayerOrientation: %ld", (long)self.videoLayerOrientation);
}

#pragma mark -- 添加文字、图片、涂鸦
- (void)addTextButtonEvent:(UIButton *)button {
PLSVideoEditingController *videoEditingVC = [[PLSVideoEditingController alloc] init];
videoEditingVC.videoLayerOrientation = self.videoLayerOrientation;
videoEditingVC.delegate = self;
if (self.videoEdit) {
videoEditingVC.videoEdit = self.videoEdit;
} else {
AVAsset *asset = self.movieSettings[PLSAssetKey];
CMTime start = CMTimeMake([self.movieSettings[PLSStartTimeKey] floatValue] * 1e9, 1e9);
CMTime duration = CMTimeMake([self.movieSettings[PLSDurationKey] floatValue] * 1e9, 1e9);
CMTimeRange timeRange = CMTimeRangeMake(start, duration);
[videoEditingVC setVideoAsset:asset timeRange:timeRange placeholderImage:nil];
}

[self presentViewController:videoEditingVC animated:YES completion:nil];
}

#pragma mark - PLSVideoEditingControllerDelegate
- (void)VideoEditingController:(PLSVideoEditingController *)videoEditingVC didCancelPhotoEdit:(PLSVideoEdit *)videoEdit {
[videoEditingVC dismissViewControllerAnimated:YES completion:nil];
}

- (void)VideoEditingController:(PLSVideoEditingController *)videoEditingVC didFinishPhotoEdit:(PLSVideoEdit *)videoEdit {
self.videoEdit = videoEdit;

[videoEditingVC dismissViewControllerAnimated:YES completion:nil];

if (self.videoEdit && self.videoEdit.editFinalURL) {
// 重置视频的方向
self.videoLayerOrientation = PLSPreviewOrientationPortrait;
[self.shortVideoEditor resetVideoLayerOrientation];
// 更新视频
NSURL *url = self.videoEdit.editFinalURL;
AVAsset *asset = [AVAsset assetWithURL:url];
[self.shortVideoEditor replaceCurrentAssetWithAsset:asset];
}
}

#pragma mark -- PLSClipAudioViewDelegate 裁剪背景音乐 的 回调
// 裁剪背景音乐
- (void)clipAudioView:(PLSClipAudioView *)clipAudioView musicTimeRangeChangedTo:(CMTimeRange)musicTimeRange {
Expand Down Expand Up @@ -933,6 +1029,15 @@ - (void)nextButtonClick {
[self.shortVideoEditor stopEditing];

[self loadActivityIndicatorView];

// 判断是否加了文字、图片、涂鸦特效
if (self.videoEdit && self.videoEdit.editFinalURL) {
NSURL *url = self.videoEdit.editFinalURL;
AVAsset *asset = [AVAsset assetWithURL:url];
self.movieSettings[PLSAssetKey] = asset;
self.movieSettings[PLSStartTimeKey] = [NSNumber numberWithFloat:0.f];
self.movieSettings[PLSDurationKey] = [NSNumber numberWithFloat:CMTimeGetSeconds(asset.duration)];
}

AVAsset *asset = self.movieSettings[PLSAssetKey];
PLSAVAssetExportSession *exportSession = [[PLSAVAssetExportSession alloc] initWithAsset:asset];
Expand All @@ -943,6 +1048,8 @@ - (void)nextButtonClick {
exportSession.isExportMovieToPhotosAlbum = YES;
// 设置视频的导出分辨率,会将原视频缩放
exportSession.outputVideoSize = self.videoSize;
// 旋转视频
exportSession.videoLayerOrientation = self.videoLayerOrientation;
[exportSession addFilter:self.colorImagePath];
[exportSession addMVLayerWithColor:self.colorURL alpha:self.alphaURL];
[exportSession exportAsynchronously];
Expand Down
Loading

0 comments on commit 10fd791

Please sign in to comment.