|
@@ -12,10 +12,14 @@
|
|
|
#import <AliyunVideoSDKPro/AliyunCrop.h>
|
|
|
#import <AliyunVideoSDKPro/AliyunImageCrop.h>
|
|
|
#import <AliyunVideoSDKPro/AliyunErrorCode.h>
|
|
|
+#import <AliyunVideoSDKPro/AliyunImporter.h>
|
|
|
#import "AliyunCropThumbnailView.h"
|
|
|
#import "AliyunCycleProgressView.h"
|
|
|
#import "AliyunCropViewBottomView.h"
|
|
|
#import "AliyunPathManager.h"
|
|
|
+#import "AlivcShortVideoRoute.h"
|
|
|
+#import "AliyunCompositionInfo.h"
|
|
|
+#import "AlivcShortVideoPublishManager.h"
|
|
|
#import "AVC_ShortVideo_Config.h"
|
|
|
#import "MBProgressHUD+AlivcHelper.h"
|
|
|
#import "AlivcMacro.h"
|
|
@@ -64,10 +68,17 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
@property (nonatomic, strong) CALayer *stillImageLayer;
|
|
|
@property (nonatomic, strong) UIImage *stillImage;
|
|
|
|
|
|
+/**
|
|
|
+ 裁剪对象参数
|
|
|
+ */
|
|
|
+@property (nonatomic, strong) AliyunCompositionInfo *cropCompositionInfo;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation AliyunCropViewController
|
|
|
+{
|
|
|
+ AliyunImporter *_importor;
|
|
|
+}
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
@@ -77,26 +88,13 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
}
|
|
|
[self setupSubViews];
|
|
|
|
|
|
- if (_cutInfo.phAsset) {//是图片资源
|
|
|
- if (_cutInfo.phImage) {
|
|
|
- _originalMediaSize = CGSizeMake(_cutInfo.phImage.size.width, _cutInfo.phImage.size.height);
|
|
|
- _destRatio = _cutInfo.outputSize.width / _cutInfo.outputSize.height;
|
|
|
- _orgVideoRatio = _originalMediaSize.width / _originalMediaSize.height;
|
|
|
- }else {
|
|
|
- _originalMediaSize = CGSizeMake(_cutInfo.phAsset.pixelWidth, _cutInfo.phAsset.pixelHeight);
|
|
|
- _destRatio = _cutInfo.outputSize.width / _cutInfo.outputSize.height;
|
|
|
- _orgVideoRatio = _originalMediaSize.width / _originalMediaSize.height;
|
|
|
- }
|
|
|
- [self setupStillImageLayer];
|
|
|
- } else {
|
|
|
- NSURL *sourceURL = [NSURL fileURLWithPath:_cutInfo.sourcePath];
|
|
|
- _avAsset = [AVAsset assetWithURL:sourceURL];
|
|
|
- _originalMediaSize = [_avAsset avAssetNaturalSize];
|
|
|
- _destRatio = _cutInfo.outputSize.width / _cutInfo.outputSize.height;
|
|
|
- _orgVideoRatio = _originalMediaSize.width / _originalMediaSize.height;
|
|
|
- [self setAVPlayer];
|
|
|
- _thumbnailView.avAsset = _avAsset;
|
|
|
- }
|
|
|
+ NSURL *sourceURL = [NSURL fileURLWithPath:_cutInfo.sourcePath];
|
|
|
+ _avAsset = [AVAsset assetWithURL:sourceURL];
|
|
|
+ _originalMediaSize = [_avAsset avAssetNaturalSize];
|
|
|
+ _destRatio = _cutInfo.outputSize.width / _cutInfo.outputSize.height;
|
|
|
+ _orgVideoRatio = _originalMediaSize.width / _originalMediaSize.height;
|
|
|
+ [self setAVPlayer];
|
|
|
+ _thumbnailView.avAsset = _avAsset;
|
|
|
}
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
@@ -131,12 +129,12 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
[self.previewScrollView addGestureRecognizer:tapGesture];
|
|
|
|
|
|
if (!_cutInfo.phAsset) {
|
|
|
- self.thumbnailView = [[AliyunCropThumbnailView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 40 - ScreenWidth/8.0 - 12 - SafeBottom, ScreenWidth, ScreenWidth / 8 + 12) withCutInfo:_cutInfo];
|
|
|
+ self.thumbnailView = [[AliyunCropThumbnailView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 20 - 110 - SafeBottom, ScreenWidth, 110) withCutInfo:_cutInfo];
|
|
|
self.thumbnailView.delegate = (id<AliyunCutThumbnailViewDelegate>)self;
|
|
|
[self.view addSubview:self.thumbnailView];
|
|
|
}
|
|
|
|
|
|
- self.bottomView = [[AliyunCropViewBottomView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 40 - SafeBottom, ScreenWidth, 40)];
|
|
|
+ self.bottomView = [[AliyunCropViewBottomView alloc] initWithFrame:CGRectMake(0, SafeTop, ScreenWidth, 44)];
|
|
|
self.bottomView.delegate = (id<AliyunCropViewBottomViewDelegate>)self;
|
|
|
[self.view addSubview:self.bottomView];
|
|
|
|
|
@@ -216,12 +214,8 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
_previewScrollView.frame = frame;
|
|
|
_previewScrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
|
if (_cutInfo.cutMode == AliyunMediaCutModeScaleAspectCut) {
|
|
|
-
|
|
|
- [self.bottomView.ratioButton setImage:[AliyunImage imageNamed:@"cut_ratio"] forState:0];
|
|
|
[self fitModeCut];
|
|
|
} else {
|
|
|
-
|
|
|
- [self.bottomView.ratioButton setImage:[AliyunImage imageNamed:@"normal"] forState:0];
|
|
|
[self fitModeFill];
|
|
|
}
|
|
|
}
|
|
@@ -304,7 +298,6 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
[alert show];
|
|
|
self.thumbnailView.userInteractionEnabled = YES;
|
|
|
self.bottomView.cropButton.userInteractionEnabled = YES;
|
|
|
- self.bottomView.ratioButton.userInteractionEnabled = YES;
|
|
|
[self destoryAVPlayer];
|
|
|
[self setAVPlayer];
|
|
|
|
|
@@ -333,9 +326,13 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
}
|
|
|
_cutInfo.endTime = _cutInfo.endTime - _cutInfo.startTime;
|
|
|
_cutInfo.startTime = 0;
|
|
|
- if (self.delegate) {
|
|
|
- [self.delegate cropViewControllerFinish:self.cutInfo viewController:self];
|
|
|
- }
|
|
|
+
|
|
|
+ // 本页面处理,不做回调
|
|
|
+// if (self.delegate) {
|
|
|
+// [self.delegate cropViewControllerFinish:self.cutInfo viewController:self];
|
|
|
+// }
|
|
|
+
|
|
|
+ [self dealWithCropWith:self.cutInfo];
|
|
|
}
|
|
|
_bottomView.cropButton.enabled =YES;
|
|
|
}
|
|
@@ -343,39 +340,83 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
- (void)cropTaskOnCancel {
|
|
|
self.progressView.progress = 0;
|
|
|
_bottomView.cropButton.enabled =YES;
|
|
|
- _bottomView.ratioButton.enabled = YES;
|
|
|
NSLog(@"cancel");
|
|
|
}
|
|
|
|
|
|
-#pragma mark ---
|
|
|
-- (void)photoCrop {
|
|
|
- AliyunImageCrop *imageCrop = [[AliyunImageCrop alloc] init];
|
|
|
- imageCrop.originImage = _stillImage;
|
|
|
- imageCrop.cropMode = (AliyunImageCropMode)_cutInfo.cutMode;
|
|
|
- imageCrop.outputSize = _cutInfo.outputSize;
|
|
|
- imageCrop.fillBackgroundColor = _cutInfo.backgroundColor;
|
|
|
-
|
|
|
- if (_cutInfo.cutMode == 1) {
|
|
|
- imageCrop.cropRect = [self configureReservationRect];
|
|
|
+// 裁剪后的处理
|
|
|
+- (void)dealWithCropWith:(AliyunMediaConfig *)mediaInfo {
|
|
|
+ _cropCompositionInfo = [[AliyunCompositionInfo alloc] init];
|
|
|
+ _cropCompositionInfo.sourcePath = mediaInfo.outputPath;
|
|
|
+ if (![mediaInfo.outputPath isEqualToString:mediaInfo.sourcePath]) {
|
|
|
+ _cropCompositionInfo.asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:mediaInfo.outputPath]];
|
|
|
}
|
|
|
+ _cropCompositionInfo.duration = [_cropCompositionInfo.asset avAssetVideoTrackDuration];
|
|
|
|
|
|
- UIImage *image = [imageCrop generateImage];
|
|
|
+ _cropCompositionInfo.startTime = mediaInfo.startTime;
|
|
|
+ _cropCompositionInfo.duration = mediaInfo.endTime - mediaInfo.startTime;
|
|
|
|
|
|
- self.cutInfo.phImage = image;
|
|
|
+ [self jumpToEditController];
|
|
|
+}
|
|
|
+
|
|
|
+// 跳转至编辑页面
|
|
|
+- (void)jumpToEditController {
|
|
|
+ NSString *editDir = [AliyunPathManager compositionRootDir];
|
|
|
+ NSString *taskPath = [editDir stringByAppendingPathComponent:[AliyunPathManager randomString]];
|
|
|
+
|
|
|
+ _importor = [[AliyunImporter alloc] initWithPath:taskPath outputSize:_cutInfo.outputSize];
|
|
|
+ NSMutableArray *saveAVURLAssetArray = [[NSMutableArray alloc] init];
|
|
|
+ AliyunCompositionInfo *info = _cropCompositionInfo;
|
|
|
+ AliyunClip *clip = [[AliyunClip alloc] initWithVideoPath:info.sourcePath startTime:info.startTime duration:info.duration animDuration:0];
|
|
|
+ [_importor addMediaClip:clip];
|
|
|
+ if (info.asset) {
|
|
|
+ [saveAVURLAssetArray addObject:info.asset];
|
|
|
+ }
|
|
|
+ if ([_cutInfo mediaRatio] == AliyunMediaRatio9To16) {
|
|
|
+ _cutInfo.cutMode = AliyunMediaCutModeScaleAspectCut;
|
|
|
+ }else {
|
|
|
+ _cutInfo.cutMode = AliyunMediaCutModeScaleAspectFill;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- NSString *tmpPhotoPath = [[[AliyunPathManager compositionRootDir] stringByAppendingPathComponent:[AliyunPathManager randomString] ] stringByAppendingPathExtension:@"jpg"];
|
|
|
- NSData *imageData = UIImageJPEGRepresentation(image, 1);
|
|
|
- [imageData writeToFile:tmpPhotoPath atomically:YES];
|
|
|
- self.cutInfo.sourcePath = tmpPhotoPath;
|
|
|
|
|
|
- if (self.delegate) {
|
|
|
- [self.delegate cropViewControllerFinish:self.cutInfo viewController:self];
|
|
|
+ // set video param
|
|
|
+ AliyunVideoParam *param = [[AliyunVideoParam alloc] init];
|
|
|
+ param.fps = _cutInfo.fps;
|
|
|
+ param.gop = _cutInfo.gop;
|
|
|
+ param.bitrate = _cutInfo.bitrate;
|
|
|
+ param.videoQuality = (AliyunVideoQuality)_cutInfo.videoQuality;
|
|
|
+ if (_cutInfo.cutMode == AliyunMediaCutModeScaleAspectCut) {
|
|
|
+ param.scaleMode = AliyunScaleModeFit;
|
|
|
+ }else{
|
|
|
+ param.scaleMode = AliyunScaleModeFill;
|
|
|
+ }
|
|
|
+ // 编码模式
|
|
|
+ if (_cutInfo.encodeMode == AliyunEncodeModeHardH264) {
|
|
|
+ param.codecType = AliyunVideoCodecHardware;
|
|
|
+ }else if(_cutInfo.encodeMode == AliyunEncodeModeSoftFFmpeg) {
|
|
|
+ param.codecType = AliyunVideoCodecFFmpeg;
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-- (void)didStartClip {
|
|
|
|
|
|
+ [_importor setVideoParam:param];
|
|
|
+ // generate config
|
|
|
+ [_importor generateProjectConfigure];
|
|
|
+ // output path
|
|
|
+ _cutInfo.outputPath = [[taskPath stringByAppendingPathComponent:[AliyunPathManager randomString]]stringByAppendingPathExtension:@"mp4"];
|
|
|
+
|
|
|
+
|
|
|
+ // edit view controller
|
|
|
+ [[AlivcShortVideoRoute shared] registerEditVideoPath:nil];
|
|
|
+ [[AlivcShortVideoRoute shared] registerEditMediasPath:taskPath];
|
|
|
+ [[AlivcShortVideoRoute shared] registerMediaConfig:_cutInfo];
|
|
|
+ UIViewController *editVC = [[AlivcShortVideoRoute shared] alivcViewControllerWithType:AlivcViewControlEdit];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [self.navigationController pushViewController:editVC animated:YES];
|
|
|
+ //存储点击的相册资源,防止之后合成没有相关资源导致失败
|
|
|
+ [[AlivcShortVideoPublishManager shared]saveResources:(NSArray *)saveAVURLAssetArray];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark ------
|
|
|
+- (void)didStartClip {
|
|
|
[self pauseVideo];
|
|
|
self.thumbnailView.userInteractionEnabled = NO;
|
|
|
if (_previewScrollView.isDragging) {
|
|
@@ -388,8 +429,6 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
}
|
|
|
_cutPanel = [[AliyunCrop alloc] init];
|
|
|
_cutPanel.delegate = (id<AliyunCropDelegate>)self;
|
|
|
-// _cutPanel.inputPath = tmp32Path;
|
|
|
-// _cutPanel.outputPath = mp32Path;
|
|
|
_cutPanel.inputPath = _cutInfo.sourcePath;
|
|
|
_cutPanel.outputPath = _cutInfo.outputPath;
|
|
|
|
|
@@ -425,7 +464,7 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
|
|
|
NSLog(@"TestLog, %@:%@", @"log_crop_start_time", @([NSDate date].timeIntervalSince1970));
|
|
|
|
|
|
- int res =[_cutPanel startCrop];
|
|
|
+ int res = [_cutPanel startCrop];
|
|
|
if (res == -100002){
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[MBProgressHUD showWarningMessage:@"当前视频格式不支持" inView:[UIApplication sharedApplication].keyWindow];
|
|
@@ -478,7 +517,6 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
self.progressView.progress = 0;
|
|
|
self.thumbnailView.userInteractionEnabled = YES;
|
|
|
self.bottomView.cropButton.enabled = YES;
|
|
|
- self.bottomView.ratioButton.enabled = YES;
|
|
|
[_cutPanel cancel];
|
|
|
}
|
|
|
|
|
@@ -606,23 +644,10 @@ typedef NS_ENUM(NSInteger, AliyunCropPlayerStatus) {
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-- (void)onClickRatioButton {
|
|
|
- _cutInfo.cutMode = !_cutInfo.cutMode;
|
|
|
- [self cropViewFitRect];
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
- (void)onClickCropButton {
|
|
|
- NSLog(@"点击了裁剪按钮");
|
|
|
- if (_cutInfo.phAsset) {
|
|
|
- [self photoCrop];
|
|
|
- } else {
|
|
|
- [self didStartClip];
|
|
|
- }
|
|
|
+ [self didStartClip];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
[self pauseVideo];
|
|
|
self.cutInfo.cutMode = _cutMode;
|