Sfoglia il codice sorgente

视频编辑 - 删除冗余

Chris 5 anni fa
parent
commit
32f144dd6d

+ 0 - 14
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -584,7 +584,6 @@
 		BD6122D422C364E400D3F513 /* AliyunMusicPickTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122CA22C364E400D3F513 /* AliyunMusicPickTabView.m */; };
 		BD6122D522C364E400D3F513 /* AliyunMusicPickCoverView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122CB22C364E400D3F513 /* AliyunMusicPickCoverView.m */; };
 		BD6122D622C364E400D3F513 /* AliyunMusicPickHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122CC22C364E400D3F513 /* AliyunMusicPickHeaderView.m */; };
-		BD6122ED22C367E900D3F513 /* AliAssetImageGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122EC22C367E900D3F513 /* AliAssetImageGenerator.m */; };
 		BD6122F822C36A8100D3F513 /* AVAsset+VideoInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122F122C36A8100D3F513 /* AVAsset+VideoInfo.m */; };
 		BD6122F922C36A8100D3F513 /* UIView+Progress.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122F422C36A8100D3F513 /* UIView+Progress.m */; };
 		BD6122FA22C36A8100D3F513 /* QUProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD6122F722C36A8100D3F513 /* QUProgressView.m */; };
@@ -1337,8 +1336,6 @@
 		BD6122CC22C364E400D3F513 /* AliyunMusicPickHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AliyunMusicPickHeaderView.m; sourceTree = "<group>"; };
 		BD6122CD22C364E400D3F513 /* AliyunMusicPickTopView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliyunMusicPickTopView.h; sourceTree = "<group>"; };
 		BD6122CE22C364E400D3F513 /* AliyunMusicLineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliyunMusicLineView.h; sourceTree = "<group>"; };
-		BD6122EB22C367E900D3F513 /* AliAssetImageGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliAssetImageGenerator.h; sourceTree = "<group>"; };
-		BD6122EC22C367E900D3F513 /* AliAssetImageGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AliAssetImageGenerator.m; sourceTree = "<group>"; };
 		BD6122F022C36A8100D3F513 /* AVAsset+VideoInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AVAsset+VideoInfo.h"; sourceTree = "<group>"; };
 		BD6122F122C36A8100D3F513 /* AVAsset+VideoInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AVAsset+VideoInfo.m"; sourceTree = "<group>"; };
 		BD6122F322C36A8100D3F513 /* UIView+Progress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Progress.h"; sourceTree = "<group>"; };
@@ -5017,7 +5014,6 @@
 				BD61227722C35C1000D3F513 /* AlivcShortVideoRoute.h */,
 				BD61227622C35C1000D3F513 /* AlivcShortVideoRoute.m */,
 				BD6122B222C3639E00D3F513 /* FilterAbout */,
-				BD6122EA22C367E900D3F513 /* AliAssetImageGenerator */,
 				BD61229F22C3638300D3F513 /* Model */,
 				BD6122BC22C364E400D3F513 /* MusicPick */,
 				BD61226322C3595B00D3F513 /* UIConfig */,
@@ -5199,15 +5195,6 @@
 			path = View;
 			sourceTree = "<group>";
 		};
-		BD6122EA22C367E900D3F513 /* AliAssetImageGenerator */ = {
-			isa = PBXGroup;
-			children = (
-				BD6122EB22C367E900D3F513 /* AliAssetImageGenerator.h */,
-				BD6122EC22C367E900D3F513 /* AliAssetImageGenerator.m */,
-			);
-			path = AliAssetImageGenerator;
-			sourceTree = "<group>";
-		};
 		BD6122EE22C36A8100D3F513 /* Vendor */ = {
 			isa = PBXGroup;
 			children = (
@@ -6107,7 +6094,6 @@
 				A70B2C272286C5D600B2449F /* ProductDetailFSPagerViewCell.swift in Sources */,
 				A7FF1585228C847300A85748 /* OrderDetailContactAddressTableViewCell.swift in Sources */,
 				A72A72AA22321DE000B21995 /* Log.swift in Sources */,
-				BD6122ED22C367E900D3F513 /* AliAssetImageGenerator.m in Sources */,
 				BD61226A22C3595B00D3F513 /* AlivcEditUIConfig.m in Sources */,
 				A7AA9F6522C63DCD0086498B /* CommunityFollowFeedModel.swift in Sources */,
 				A72A72B622321DE000B21995 /* Extension+NSRange.swift in Sources */,

+ 0 - 51
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/Common/AliAssetImageGenerator/AliAssetImageGenerator.h

@@ -1,51 +0,0 @@
-//
-//  AliAssetImageGenerator.h
-//  AlivcSceneDemo
-//
-//  Created by Worthy on 2017/7/25.
-//  Copyright © 2017年 Worthy. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
-#import <AVFoundation/AVFoundation.h>
-
-typedef NS_ENUM(NSUInteger, AliAssetInfoType) {
-    AliAssetInfoTypeVideo,
-    AliAssetInfoTypeImage
-};
-
-@interface AliAssetInfo : NSObject
-@property (nonatomic, copy) NSString *path;
-@property (nonatomic, assign) AliAssetInfoType type;
-@property (nonatomic, assign) CGFloat startTime;
-@property (nonatomic, assign) CGFloat duration;
-@property (nonatomic, assign) CGFloat animDuration;
-
-- (UIImage *)captureImageAtTime:(CGFloat)time outputSize:(CGSize)outputSize;
--(CGFloat)realDuration;
-
-@end
-
-@interface AliAssetImageGenerator : NSObject
-
-@property (nonatomic) CGSize outputSize;
-@property (nonatomic) NSInteger imageCount; //图片数量
-@property (nonatomic, assign) CGFloat timePerImage; //2个图片的间隔时间
-@property (nonatomic, assign) CGFloat duration;
-
-- (void)addVideoWithPath:(NSString *)path startTime:(CGFloat)startTime duration:(CGFloat)duration animDuration:(CGFloat)animDuration;
-- (void)addImageWithPath:(NSString *)path duration:(CGFloat)duration animDuration:(CGFloat)animDuration;
-- (void)generateWithCompleteHandler:(void(^)(UIImage *))handler;
-- (void)cancel;
-/**
- 获取视频缩略图
-
- @param videoURL 视频地址
- @param time 时间
- @return 封面
- */
-+ (UIImage*)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time;
-
-
-@end

+ 0 - 194
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/Common/AliAssetImageGenerator/AliAssetImageGenerator.m

@@ -1,194 +0,0 @@
-//
-//  AliAssetImageGenerator.m
-//  AlivcSceneDemo
-//
-//  Created by Worthy on 2017/7/25.
-//  Copyright © 2017年 Worthy. All rights reserved.
-//
-
-#import "AliAssetImageGenerator.h"
-
-
-@interface AliAssetImageGenerator ()
-@property (nonatomic, strong) NSMutableArray<AliAssetInfo *> *assets;
-
-@property (nonatomic, assign) BOOL shouldCancel;
-@property (nonatomic, strong) dispatch_queue_t queue;
-@end
-
-
-@implementation AliAssetImageGenerator
-
--(instancetype)init {
-    self = [super init];
-    if (self) {
-        _assets = [NSMutableArray array];
-        _imageCount = 8;
-        _outputSize = CGSizeMake(200,200);
-        _duration = 0;
-    }
-    return self;
-}
-
--(void)addImageWithPath:(NSString *)path duration:(CGFloat)duration animDuration:(CGFloat)animDuration {
-    AliAssetInfo *info = [[AliAssetInfo alloc] init];
-    info.path = path;
-    info.duration = duration;
-    info.animDuration = animDuration;
-    info.type = AliAssetInfoTypeImage;
-    [_assets addObject:info];
-    _duration += [info realDuration];
-}
-
--(void)addVideoWithPath:(NSString *)path startTime:(CGFloat)startTime duration:(CGFloat)duration animDuration:(CGFloat)animDuration {
-    AliAssetInfo *info = [[AliAssetInfo alloc] init];
-    info.path = path;
-    info.duration = duration;
-    info.animDuration = animDuration;
-    info.startTime = startTime;
-    info.type = AliAssetInfoTypeVideo;
-    [_assets addObject:info];
-    _duration += [info realDuration];
-}
-
--(void)generateWithCompleteHandler:(void(^)(UIImage *))handler {
-    _shouldCancel = NO;
-    _queue = dispatch_queue_create("com.ali.thumb.generator", NULL);
-    //new
-    dispatch_async(_queue, ^{
-       
-        for (int imageIndex = 0; imageIndex < _imageCount; imageIndex++) {
-            CGFloat currentImageDuration = imageIndex * _timePerImage; //当前图片对应的时间节点
-            
-            CGFloat totalInfoDuration = 0; //资源的在总的里面的时间节点
-            for (int infoIndex = 0; infoIndex < _assets.count; infoIndex ++) {
-                AliAssetInfo *info = _assets[infoIndex];
-                CGFloat currentInfoDuration = [info realDuration]; //当前资源的时间
-                CGFloat preSourceTotalTime = totalInfoDuration;//当前资源之前的资源加起来的总时间
-                totalInfoDuration = totalInfoDuration + currentInfoDuration;
-                if (currentImageDuration < totalInfoDuration) {
-                    CGFloat relaTimeInCurrentInfo = currentImageDuration - preSourceTotalTime; // 图片在当前资源里的实际时间
-                    UIImage *image = [info captureImageAtTime:relaTimeInCurrentInfo outputSize:_outputSize];
-                    handler(image);
-                    break;
-                }
-                if (_shouldCancel) {
-                    break;
-                }
-                
-            }
-        }
-    });
-}
-
--(void)cancel {
-    _shouldCancel = YES;
-}
-
-+ (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {
-    
-    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
-    NSParameterAssert(asset);
-    AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
-    assetImageGenerator.appliesPreferredTrackTransform = YES;
-    assetImageGenerator.maximumSize = CGSizeMake(300, 300);
-    assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
-    
-    
-    CGImageRef thumbnailImageRef = NULL;
-    CFTimeInterval thumbnailImageTime = time;
-    NSError *thumbnailImageGenerationError = nil;
-    thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
-    
-    if(!thumbnailImageRef) {
-        NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
-    }
-    UIImage*thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : nil;
-    
-    return thumbnailImage;
-}
-
-
-@end
-
-#pragma mark - AliAssetInfo Class
-
-@interface AliAssetInfo ()
-@property (nonatomic, strong) AVAssetImageGenerator *generator;
-@end
-
-@implementation AliAssetInfo
-
--(CGFloat)realDuration {
-    return _duration - _animDuration;
-}
-
-- (UIImage *)captureImageAtTime:(CGFloat)time outputSize:(CGSize)outputSize {
-    if (_type == AliAssetInfoTypeImage) {
-        return [self imageFromImageWithOutputSize:outputSize];
-    }else {
-        return [self imageFromVideoWithOutputSize:outputSize atTime:time];
-    }
-
-}
-
-- (UIImage *)imageFromImageWithOutputSize:(CGSize)outputSize {
-    UIImage *image = [UIImage imageWithContentsOfFile:_path];
-    CGFloat imageRatio = image.size.width / image.size.height;
-    if (image.size.width > image.size.height) {
-        outputSize.height = outputSize.width / imageRatio;
-    } else {
-        outputSize.width = outputSize.height * imageRatio;
-    }
-
-    UIGraphicsBeginImageContext(outputSize);
-    [image drawInRect:CGRectMake(0, 0, outputSize.width, outputSize.height)];
-    UIImage *picture = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
-    return picture;
-}
-
-- (UIImage *)imageFromVideoWithOutputSize:(CGSize)outputSize atTime:(CGFloat)atTime {
-    if (!_generator) {
-//        _generator = [[AVAssetImageGenerator alloc] initWithAsset:[self composition]];
-        AVURLAsset *asset = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:_path] options:nil];
-        _generator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
-        _generator.maximumSize = outputSize;
-        _generator.appliesPreferredTrackTransform = YES;
-//        _generator.requestedTimeToleranceAfter = kCMTimeZero;
-//        _generator.requestedTimeToleranceBefore = kCMTimeZero;
-    }
-    if (atTime < 0) {
-        atTime = 0;
-    }
-    CMTime time = CMTimeMake(atTime * 1000, 1000);
-    CGImageRef image = [_generator copyCGImageAtTime:time actualTime:NULL error:nil];
-    UIImage *picture = [UIImage imageWithCGImage:image];
-    CGImageRelease(image);
-    return picture;
-}
-
-
--(AVComposition *)composition {
-    AVMutableComposition *composition = [AVMutableComposition composition];
-    AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
-    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:_path] options:nil];
-    AVAssetTrack *assetTrackVideo = nil;
-    if ([[asset tracksWithMediaType:AVMediaTypeVideo] count] != 0) {
-        assetTrackVideo = [asset tracksWithMediaType:AVMediaTypeVideo][0];
-    }
-    if (assetTrackVideo) {
-        CMTime start = CMTimeMake((_startTime-_animDuration)*1000, 1000);
-        CMTime duration = assetTrackVideo.timeRange.duration;
-        if (_duration) {
-            duration = CMTimeMake(_duration * 1000, 1000);
-        }
-        [compositionVideoTrack insertTimeRange:CMTimeRangeMake(start, duration) ofTrack:assetTrackVideo atTime:kCMTimeZero error:nil];
-        compositionVideoTrack.preferredTransform = assetTrackVideo.preferredTransform;
-        return composition;
-    }
-    return nil;
-}
-
-
-@end

+ 0 - 109
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoEdit/Controller/AliyunEditViewController.m

@@ -36,7 +36,6 @@
 
 //其它
 #import "AVAsset+VideoInfo.h"
-#import "AliAssetImageGenerator.h"
 #import "AliyunCustomFilter.h"
 #import "AliyunEffectFilterView.h"
 #import "AliyunMusicPickViewController.h"
@@ -53,7 +52,6 @@
 typedef enum : NSUInteger {
     AlivcEditVCStatus_Normal = 0, //播放或者暂停状态 - 非编辑状态
     AlivcEditVCStatus_Edit,       //编辑状态
-    
 } AlivcEditVCStatus;
 
 // TODO:此类需再抽一层,否则会太庞大
@@ -542,28 +540,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     [self playButtonTouchedHandle];
 }
 
-/**
- 取消按钮点击响应
- 1.不应用特效 - 去除预览中的特效
- 2.退出编辑模式
- */
-- (void)cancel {
-    
-    // 2
-    [self quitEditWithActionType:_editSouceClickType CompletionHandle:nil];
-}
-
-/**
- 保存按钮点击响应
- 1.应用特效
- 2.退出编辑模式
- */
-- (void)apply {
-    // 2
-    
-    [self quitEditWithActionType:_editSouceClickType CompletionHandle:nil];
-}
-
 /**
  返回
  */
@@ -574,26 +550,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     [self.navigationController popViewControllerAnimated:YES];
 }
 
-- (UIImage *)featchFirstFrame {
-    NSArray *clips = [self.clipConstructor mediaClips];
-    AliyunClip *firstClip = clips.firstObject;
-    if (firstClip) {
-        AliAssetInfo *info = [[AliAssetInfo alloc] init];
-        info.path = firstClip.src;
-        info.duration = firstClip.duration;
-        info.animDuration = 0;
-        info.startTime = firstClip.startTime;
-        if (firstClip.mediaType == AliyunClipVideo) {
-            info.type = AliAssetInfoTypeVideo;
-        } else {
-            info.type = AliAssetInfoTypeImage;
-        }
-        UIImage *image = [info captureImageAtTime:0 outputSize:_outputSize];
-        return image;
-    }
-    return nil;
-}
-
 /**
  发布
  */
@@ -809,7 +765,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     CGFloat animationTime = 0.2f;
     BOOL canEditFrame = [self isEditFrameType:type];
     if (canEditFrame) {
-        [self p_changeUIToEnterEditFrameModeCompletionHandle:completion];
         [self pause];
     } else {
         [self p_presentBackgroundButton];
@@ -839,7 +794,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     
     BOOL canEditFrame = [self isEditFrameType:type];
     if (canEditFrame) {
-        [self p_changeUIToQuitEditFrameMode];
         [self resume];
     } else {
         [self p_dismissBackgroundButton];
@@ -965,55 +919,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
                      }];
 }
 
-/**
- 让界面进入能编辑视频帧的模式
- */
-- (void)p_changeUIToEnterEditFrameModeCompletionHandle:(void (^__nullable)(BOOL finished))completion {
-    self.backButton.hidden = YES;
-    self.publishButton.hidden = YES;
-    CGRect editFrame = [self editStatusFrameMovieView];
-    
-    [UIView animateWithDuration:0.2
-                     animations:^{
-                         self.movieView.frame = editFrame;
-                     } completion:^(BOOL finished) {
-                         
-                         if (completion) {
-                             completion(finished);
-                         }
-                     }];
-}
-
-/**
- 界面退出编辑模式
- */
-- (void)p_changeUIToQuitEditFrameMode {
-    self.backButton.hidden = NO;
-    self.publishButton.hidden = NO;
-    [self p_setMovieViewFrameToPlayStatusWithAnimation];
-}
-
-/**
- 编辑模式下的frame大小
- 
- @return 编辑模式下的frame大小
- */
-- (CGRect)editStatusFrameMovieView {
-    CGFloat yToTop = SafeTop + 8;
-    
-    UIView *editView = [self editViewWithType:_editSouceClickType];
-    CGFloat mHeight = ScreenHeight - editView.frame.size.height - yToTop - 2;
-    CGFloat factor = _outputSize.width / _outputSize.height;
-    CGFloat mWidth = factor * mHeight;
-    if (mWidth > ScreenWidth) {
-        mWidth = ScreenWidth;
-        mHeight = 1 / factor * mWidth;
-    }
-    CGFloat mx = (ScreenWidth - mWidth) / 2;
-    CGFloat my = yToTop;
-    return CGRectMake(mx, my, ceilf(mWidth), ceilf(mHeight));
-}
-
 - (CGRect)playStatusFrameMovieView {
     CGFloat factor = _outputSize.height / _outputSize.width;
     CGFloat y = ScreenWidth / 8 + SafeTop;
@@ -1039,18 +944,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     self.movieView.frame = [self playStatusFrameMovieView];
    
 }
-/**
- 让播放视图回归正常的大小-以动画的形式
- */
-- (void)p_setMovieViewFrameToPlayStatusWithAnimation {
-    CGRect targetFrame = [self playStatusFrameMovieView];
-    [UIView animateWithDuration:0.2
-                     animations:^{
-                         self.movieView.frame = targetFrame;
-                     } completion:^(BOOL finished) {
-                         
-                     }];
-}
 
 /**
  添加背景按钮
@@ -1084,7 +977,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
 - (void)playerDidEnd {
     
     if (_processAnimationFilter) { //如果当前有正在添加的动效滤镜 则pause
-        //        [self.player replay];
         [self updateUIAndDataWhenPlayStatusChanged];
         _processAnimationFilter.endTime = [self.player getDuration];
         _processAnimationFilter.streamEndTime = [self.player getStreamDuration];
@@ -1093,7 +985,6 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
             [self.player replay];
             [self updateUIAndDataWhenPlayStatusChanged];
             self.isExporting = NO;
-            //            [self forceFinishLastEditPasterView];
         }
     }
 }