ViewController.m 53.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
//
//  ViewController.m
//  CNLiveRDVESDKDemo
//
//  Created by iOS on 2017/11/24.
//  Copyright © 2017年 zhulin. All rights reserved.
//

#import "ViewController.h"
#import "CNLiveRDVESDK/CNLiveRDVESDK.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/PHPhotoLibrary.h>
#import <Photos/Photos.h>
#import "faceAuthpack.h"
#import "UIButton+Block.h"
#import "PlayVideoController.h"

//设备屏幕宽高
#define kWIDTH [UIScreen mainScreen].bounds.size.width
#define kHEIGHT [UIScreen mainScreen].bounds.size.height

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define FaceUURL  @"http://dianbook.17rd.com/api/shortvideo/getfaceprop"
#define MVResourceURL @"http://dianbook.17rd.com/api/shortvideo/getmvprop2"
#define MusicResourceURL  @"http://dianbook.17rd.com/api/shortvideo/getbgmusic"
#define CloudMusicResourceURL @"http://dianbook.17rd.com/api/shortvideo/getcloudmusic"


#define VideoAverageBitRate 1.0
#define CUTVIDEOTYPALERTTAG 200

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource,UITextFieldDelegate>
{
    NSMutableArray *_functionList;
    //压缩设置
    UIView          *_compressSettingView;
    AVURLAsset      *_compressAsset;
    NSString        *_compressOutputPath;   //压缩文件的保存路径
    UIView          *_tsavitoMp4View;

}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) CNLiveCameraConfiguration     *cameraCfg;
@property (nonatomic, strong) CNLiveEditConfiguration       *editCfg;
@property (nonatomic, strong) CNLiveExportConfiguration     *exportCfg;
@property (nonatomic, strong) CNLiveRDVEUIKit *edittingSdk;

@end

@implementation ViewController

NSString *const APPKEY =  @"6ecb39f1c12f1a35";
NSString *const APPSECRET = @"22a44768806a23466dd52ecf954ed6b26sICMKN8iw707KYMWLkJoNaMxb5Xal+afScFJ8/exLzxx1bY5Te7WqZzRD6k4EcUwwJ8a8+AeCO/WSG2qUzso/7u0l758MUsfPzjz7Ih2BY=";

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationItem setHidesBackButton:YES];
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    attributes[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
    attributes[NSForegroundColorAttributeName] = UIColorFromRGB(0xffffff);
    self.navigationController.navigationBar.titleTextAttributes = attributes;
    self.navigationController.navigationBar.barTintColor=UIColorFromRGB(0x0e0e10);
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    self.view.backgroundColor = UIColorFromRGB(0x33333b);
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = UIColorFromRGB(0x33333b);

    self.navigationController.navigationBar.translucent = NO;
    self.title = @"iOS视频编辑SDK-Demo";
    
    //加载数据
    [self loadListData];
    [self.view addSubview:self.tableView];

}

#pragma mark -
#pragma mark - initSDK
- (CNLiveRDVEUIKit *)createSdk {
    CNLiveRDVEUIKit *kit = [[CNLiveRDVEUIKit alloc] initWithAPPKey:APPKEY APPSecret:APPSECRET resultFail:^(NSError * _Nonnull error) {
        NSLog(@"初始化error:%@", error.localizedDescription);
    }];
    
    _cameraCfg = [[CNLiveCameraConfiguration alloc] init];
    _cameraCfg.cameraSquare_MaxVideoDuration = 0;
    _cameraCfg.cameraNotSquare_MaxVideoDuration = 0;
    _cameraCfg.cameraRecordSizeType = CNLiveRecordVideoTypeMixed;
    _cameraCfg.cameraRecordOrientation = CNLiveRecordVideoOrientationAuto;
    _cameraCfg.cameraCollocationPosition = CNLiveCameraCollocationPositionBottom;
    _cameraCfg.cameraModelType = CNLiveCameraModel_Onlyone;

    _cameraCfg.enableFaceU = true;
    _cameraCfg.faceUAuth           = &g_faceuAuth_package;
    _cameraCfg.lenFaceUAuth        = sizeof(g_faceuAuth_package);
    _cameraCfg.enableNetFaceUnity  = true;
    _cameraCfg.enableFilter        = true;
    _cameraCfg.cheekThinning = 0.2;
    _cameraCfg.eyeEnlarging = 0.2;
    _cameraCfg.colorLevel = 0.2;
    _cameraCfg.blurLevel = 2.0;
    _cameraCfg.faceUURL            = FaceUURL;
    
    _cameraCfg.hiddenPhotoLib      = false;     //是否隐藏相机进入相册按钮
    NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
    _cameraCfg.cameraOutputPath = outputPath;

    _cameraCfg.enableUseMusic = true;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"huiyi" ofType:@"mp3"];
    CNLiveMusicInfo *musicInfo = [[CNLiveMusicInfo alloc] init];
    musicInfo.url = [NSURL fileURLWithPath:path];
    musicInfo.name = @"回忆";
    musicInfo.clipTimeRange = kCMTimeRangeZero;
    _cameraCfg.musicInfo = musicInfo;
    
    //编辑
    _editCfg = [[CNLiveEditConfiguration alloc] init];
    //是否需要定制功能
    _editCfg.enableWizard                = false;
    _editCfg.enableMV = false;
    
    //设置相册最大选择张数
    _editCfg.mediaCountLimit              = 0;
    _editCfg.proportionType                = CNLivePROPORTIONTYPE_AUTO;
    
    //定长截取设置
    _editCfg.trimMinDuration_TwoSpecifyTime    = 12.0;
    _editCfg.trimMaxDuration_TwoSpecifyTime    = 30.0;
    _editCfg.defaultSelectMinOrMax             = kCNLiveDefaultSelectCutMax;
    
    //进入/退出动画
    _editCfg.presentAnimated                 = true;
    _editCfg.dissmissAnimated                = true;
    
    _editCfg.enableMusic = true;
    _editCfg.musicResourceURL = MusicResourceURL;
    _editCfg.cloudMusicResourceURL = CloudMusicResourceURL;
    
    //编辑导出设置
    _exportCfg = [[CNLiveExportConfiguration alloc] init];
    _exportCfg.videoBitRate    = VideoAverageBitRate;
    _exportCfg.endPicDisabled  = true;
    _exportCfg.waterDisabled = false;
 
    [kit setEditConfiguration:_editCfg];
    [kit setCameraConfiguration:_cameraCfg];
    [kit setExportConfiguration:_exportCfg];
    
    return kit;
    
}

- (CNLiveRDVEUIKit *)createShortSdk {
    CNLiveRDVEUIKit *kit = [[CNLiveRDVEUIKit alloc] initWithAPPKey:APPKEY APPSecret:APPSECRET resultFail:^(NSError * _Nonnull error) {
        NSLog(@"初始化error:%@", error.localizedDescription);
    }];
    
    _editCfg = [[CNLiveEditConfiguration alloc] init];
    _editCfg.enableMV = true;
    _editCfg.enableFragmentedit = false;
    _editCfg.enableSubtitle = false;
    _editCfg.enableEffect = false;
    _editCfg.dubbingType = CNLiveDUBBINGTYPE_SECOND;
    _editCfg.mediaCountLimit = 1;
    _editCfg.supportFileType = CNLiveONLYSUPPORT_VIDEO;
    _editCfg.trimMode = CNLiveTRIMMODESPECIFYTIME_ONE;
    _editCfg.trimDuration_OneSpecifyTime = 15.0;
    _editCfg.musicResourceURL = MusicResourceURL;
    _editCfg.mvResourceURL = MVResourceURL;
    _editCfg.cloudMusicResourceURL = CloudMusicResourceURL;
    
    NSString * exportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/recordVideoFile.mp4"];
    _cameraCfg = [[CNLiveCameraConfiguration alloc] init];
    _cameraCfg.cameraOutputPath = exportPath;
    _cameraCfg.cameraOutputSize = CGSizeZero;
    _cameraCfg.cameraRecordSizeType = CNLiveRecordVideoTypeSquare;
    _cameraCfg.cameraRecordOrientation = CNLiveRecordVideoOrientationAuto;
    _cameraCfg.cameraRecord_Type = CNLiveRecordType_MVVideo;
    _cameraCfg.cameraMV_MaxVideoDuration = 15.0;
    _cameraCfg.cameraMV_MinVideoDuration = 3.0;
    _cameraCfg.cameraMV = true;
    _cameraCfg.cameraVideo = false;
    _cameraCfg.cameraPhoto = false;
    _cameraCfg.cameraModelType = CNLiveCameraModel_Onlyone;
    
    _exportCfg = [[CNLiveExportConfiguration alloc] init];
    _exportCfg.endPicDisabled = true;
    _exportCfg.waterDisabled = true;

    [kit setEditConfiguration:_editCfg];
    [kit setCameraConfiguration:_cameraCfg];
    [kit setExportConfiguration:_exportCfg];
    
    return kit;
    
}

#pragma mark -
#pragma mark - 录制
- (void)recordVideoWithType:(NSInteger)index {
    
    _edittingSdk = [self createSdk];
    __weak ViewController *weakSelf = self;

    self.editCfg.trimMode = CNLiveTRIMMODEAUTOTIME;
    self.editCfg.enableAlbumCamera = true;
    
    if (index == 0) {
        //方式一(只录制等宽高的视频,这里设置界面方向不会生效)
        self.cameraCfg.cameraRecordSizeType = CNLiveRecordVideoTypeSquare;//设置输出视频是正方形还是长方形
        self.cameraCfg.cameraRecordOrientation = CNLiveRecordVideoOrientationAuto;//设置界面方向(竖屏还是横屏)
    }
    
    if (index == 1) {
        //方式二
       self.cameraCfg.cameraOutputSize = CGSizeMake(1080, 1920);//设置输出视频大小
        self.cameraCfg.cameraRecordSizeType        = CNLiveRecordVideoTypeNotSquare;
        self.cameraCfg.cameraRecordOrientation     = CNLiveRecordVideoOrientationAuto;
    }
    
    if (index == 2) {
        //方式三(自适应尺寸)
        self.cameraCfg.cameraOutputSize = CGSizeZero;//自动根据设备设置大小传入CGSizeZero
        self.cameraCfg.cameraRecordSizeType = CNLiveRecordVideoTypeMixed;//设置输出视频是正方形还是长方形
        self.cameraCfg.cameraRecordOrientation = CNLiveRecordVideoOrientationAuto;//设置界面方向(竖屏还是横屏)
    }
    
    __weak typeof(self) myself = self;

    //从相机进入相册
    [_edittingSdk setCameraConfiguration:self.cameraCfg];
    [_edittingSdk setEditConfiguration:self.editCfg];
    
    //从相机进入相册
    _edittingSdk.cameraEnterPhotoAlbumCallblackBlock = ^(){
        dispatch_async(dispatch_get_main_queue(), ^{
            [myself cameraEnterPhotoAlbum];
        });
    };
    
    //录制视频
    [_edittingSdk videoRecordAutoSizeWithSourceController:self callbackBlock:^(int result, NSString * _Nonnull path) {
        
        if (result == 1) {  //视频
            if (path.length > 0) {
                [weakSelf editVideoWithPath:path type:1];
            }
        } else {            //MV
            _edittingSdk = nil;
            _edittingSdk = [self createShortSdk];
            
            AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:path] options:nil];
            NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
            
            [_edittingSdk editVideoWithSuperController:weakSelf urlAsset:asset clipTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) crop:CGRectMake(0, 0, 1, 1) outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"编辑完成");
                    _edittingSdk = nil;
                    [weakSelf enterPlayView:videoPath];
                });
            } cancel:^{
                _edittingSdk = nil;
            }];
        }
        
    } imagebackBlock:^(NSString * _Nonnull videoPath) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (videoPath.length > 0) {
                [weakSelf editVideoWithPath:videoPath type:2];
            }
        });
        
    } faileBlock:^(NSError * _Nonnull error) {
        NSLog(@"record error:%@",error);
        _edittingSdk = nil;
    } cancel:^{
        _edittingSdk = nil;
    }];
}

- (void)editVideoWithPath:(NSString *)path type:(int)type {
    if(!(path.length>0)){
        return;
    }
    
    NSMutableArray *lists = [[NSMutableArray alloc] init];
    [lists addObject:[NSURL fileURLWithPath:path]];
    
    __weak ViewController *weakSelf = self;
    //实例化RDVEUISDK对象
    NSString * exportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
    
    [_edittingSdk editVideoWithSuperController:self foldertype:kCNLiveFolderDocuments appAlbumCacheName:@"MyVideo" urlsArray:lists outputPath:exportPath callback:^(NSString * _Nonnull videoPath) {
        dispatch_async(dispatch_get_main_queue(), ^{
            _edittingSdk = nil;
            UIInterfaceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;
            if(deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight){
                if(self.navigationController.visibleViewController == self){
                    NSLog(@"横向");
                    self.navigationController.navigationBarHidden = YES;
                    self.navigationController.navigationBar.translucent = YES;
                    [self.navigationController setNavigationBarHidden:YES];
                    [[UIApplication sharedApplication] setStatusBarHidden:YES];
                }
                _tableView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
                
            }
            else if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
                if(self.navigationController.visibleViewController == self){
                    NSLog(@"纵向");
                    self.navigationController.navigationBarHidden=NO;
                    self.navigationController.navigationBar.translucent=NO;
                    [self.navigationController setNavigationBarHidden: NO];
                    [[UIApplication sharedApplication] setStatusBarHidden:NO];
                }
                _tableView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 64);
            }
            
            [weakSelf enterPlayView:videoPath];
        });
    } cancel:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            _edittingSdk = nil;
        });
    }];
}

#pragma mark -
#pragma mark - 进入相册
- (void)cameraEnterPhotoAlbum {
    
    __weak ViewController *weakSelf = self;

    [_edittingSdk onCnVEAlbumWithSuperController:self albumType:kCNLiveALBUMALL callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
            
            [_edittingSdk editVideoWithSuperController:weakSelf foldertype:kCNLiveFolderDocuments appAlbumCacheName:@"MyVideo" urlsArray:[urls mutableCopy] outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    _edittingSdk = nil;
                    [weakSelf enterPlayView:videoPath];
                });
                NSLog(@"edit completed");
                
            } cancel:^{
                _edittingSdk = nil;
                NSLog(@"取消编辑");
            }];
            
        });
        
        
    } cancelBlock:^{
        _edittingSdk = nil;
        NSLog(@"用户取消相册页面");
    }];
}

- (void)onCnVEAlbumWithType:(NSInteger)index {
    
    _edittingSdk = [self createSdk];
    __weak ViewController *weakSelf = self;

    switch (index) {
        case 0: {
            [_edittingSdk onCnVEAlbumWithSuperController:self albumType:kCNLiveALBUMALL callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
                    
                    [_edittingSdk editVideoWithSuperController:weakSelf foldertype:kCNLiveFolderDocuments appAlbumCacheName:@"MyVideo" urlsArray:[urls mutableCopy] outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            _edittingSdk = nil;
                            [weakSelf enterPlayView:videoPath];
                        });
                        NSLog(@"edit completed");
                        
                    } cancel:^{
                        _edittingSdk = nil;
                        NSLog(@"取消编辑");
                    }];
                    
                });
                
            } cancelBlock:^{
                _edittingSdk = nil;
                NSLog(@"取消");
            }];
        }
            break;
            
        case 1: {
            [_edittingSdk onCnVEAlbumWithSuperController:self albumType:kCNLiveONLYALBUMVIDEO callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
                    
                    [_edittingSdk editVideoWithSuperController:weakSelf foldertype:kCNLiveFolderDocuments appAlbumCacheName:@"MyVideo" urlsArray:[urls mutableCopy] outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            _edittingSdk = nil;
                            [weakSelf enterPlayView:videoPath];
                        });
                        
                        NSLog(@"edit completed");
                        
                    } cancel:^{
                        _edittingSdk = nil;
                        NSLog(@"取消编辑");
                        
                    }];
                    
                });
                
            } cancelBlock:^{
                _edittingSdk = nil;
                NSLog(@"取消");
            }];
        }
            break;
        
        case 2: {
            [_edittingSdk onCnVEAlbumWithSuperController:self albumType:kCNLiveONLYALBUMIMAGE callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
                
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil
                                                                   message:[NSString stringWithFormat:@"images:%@",urls]
                                                                  delegate:self
                                                         cancelButtonTitle:@"确定"
                                                         otherButtonTitles:nil, nil];
                [alertView show];
                
                _edittingSdk = nil;
                
            } cancelBlock:^{
                NSLog(@"取消");
                _edittingSdk = nil;
            }];
            
        }
            break;
            
        default:
            break;
    }
    
}

- (void)enterPlayView:(NSString *)path{
    if(_tsavitoMp4View){
        [_tsavitoMp4View.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [_tsavitoMp4View removeFromSuperview];
        _tsavitoMp4View = nil;
    }
    PlayVideoController *playVC = [[PlayVideoController alloc] init];
    if(!(path.length>0)){
        path = [[NSBundle mainBundle] pathForResource:@"testFile1" ofType:@"mov"];
    }
    playVC.videoPath = path;
    [self.navigationController pushViewController:playVC animated:NO];
}
#pragma mark -
#pragma mark - 编辑
- (void)editVideoWithType:(NSInteger)index{

    _edittingSdk = [self createSdk];

    NSString * exportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];

    NSMutableArray *lists = [[NSMutableArray alloc] init];
    if (index ==0){
        NSString *imagepath = [[NSBundle mainBundle] pathForResource:@"test0" ofType:@"JPG"];
        [lists addObject:[NSURL fileURLWithPath:imagepath]];
        
        NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"testFile1" ofType:@"mov"];
        [lists addObject:[NSURL fileURLWithPath:videoPath]];
        
        __weak ViewController *weakSelf = self;
        [_edittingSdk editVideoWithSuperController:self
                                        foldertype:kCNLiveFolderNone
                                 appAlbumCacheName:@""
                                         urlsArray:lists
                                        outputPath:exportPath
                                          callback:^(NSString * _Nonnull videoPath) {
            
                                              dispatch_async(dispatch_get_main_queue(), ^{
                                                  _edittingSdk = nil;
                                                  [weakSelf enterPlayView:videoPath];
                                              });
                                              
                                          } cancel:^{
                                              _edittingSdk = nil;
                                              NSLog(@"取消编辑");
                                          }];
        
       
    } else if(index ==1){
        
        __weak ViewController *weakSelf = self;
        
        [_edittingSdk editVideoWithSuperController:self
                                        foldertype:kCNLiveFolderNone
                                 appAlbumCacheName:@"MyVideo"
                                         urlsArray:lists
                                        outputPath:exportPath
                                          callback:^(NSString * _Nonnull videoPath) {
                                              dispatch_async(dispatch_get_main_queue(), ^{
                                                  _edittingSdk = nil;
                                                  [weakSelf enterPlayView:videoPath];
                                              });
                                          } cancel:^{
                                              _edittingSdk = nil;
                                              NSLog(@"取消编辑");
                                          }];
        
    }
    
}

#pragma mark -
#pragma mark - 短视频编辑
- (void)shortVideoEdit{
    
    _edittingSdk = [self createShortSdk];

    __weak ViewController *weakSelf = self;
    NSString * exportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/recordVideoFile.mp4"];
    
    [_edittingSdk setEditConfiguration:_editCfg];
    [_edittingSdk setCameraConfiguration:_cameraCfg];
    [_edittingSdk setExportConfiguration:_exportCfg];
    
    //从相机进入相册
    _edittingSdk.cameraEnterPhotoAlbumCallblackBlock = ^{
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.edittingSdk onCnVEAlbumWithSuperController:weakSelf albumType:kCNLiveONLYALBUMVIDEO callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
                
                AVURLAsset *asset = [AVURLAsset assetWithURL:[urls firstObject]];
                NSDictionary *dic = [weakSelf.edittingSdk getVideoInformation:asset];
                float width = [[dic objectForKey:@"width"] floatValue];
                float height = [[dic objectForKey:@"height"] floatValue];
                
                 if(width == height && CMTimeGetSeconds(asset.duration) <= weakSelf.cameraCfg.cameraMV_MaxVideoDuration){
                     
                     dispatch_async(dispatch_get_main_queue(), ^{
                        
                         NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];

                         [weakSelf.edittingSdk editVideoWithSuperController:weakSelf urlAsset:asset clipTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) crop:CGRectZero outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                             
                             dispatch_async(dispatch_get_main_queue(), ^{
                                _edittingSdk = nil;
                                 [weakSelf enterPlayView:videoPath];
                                 
                             });
                             
                         } cancel:^{
                             _edittingSdk = nil;
                             NSLog(@"取消短视频编辑");
                             
                         }];
                         
                     });
                     return ;
                 }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                   
                    [weakSelf.edittingSdk trimVideoWithSuperController:weakSelf controllerTitle:@"修剪片段" backgroundColor:weakSelf.view.backgroundColor cancelButtonTitle:@"取消" cancelButtonTitleColor:UIColorFromRGB(0xffffff) cancelButtonBackgroundColor:UIColorFromRGB(0x000000) otherButtonTitle:@"确定" otherButtonTitleColor:UIColorFromRGB(0xffffff) otherButtonBackgroundColor:UIColorFromRGB(0x000000) urlAsset:asset outputPath:exportPath callbackBlock:^(CNLiveCutVideoReturnType cutType, AVURLAsset * _Nonnull asset, CMTime startTime, CMTime endTime, CGRect cropRect) {
                        
                        if (cutType == CNLiveCutVideoReturnTypeTime) {
                            
                            
                            dispatch_async(dispatch_get_main_queue(), ^{
                                
                                NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
                                
                                [weakSelf.edittingSdk editVideoWithSuperController:weakSelf urlAsset:asset clipTimeRange:CMTimeRangeMake(startTime, CMTimeSubtract(endTime, startTime)) crop:cropRect outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                                    
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        _edittingSdk = nil;
                                        [weakSelf enterPlayView:videoPath];
                                    });
                                    
                                } cancel:^{
                                    _edittingSdk = nil;
                                    NSLog(@"取消编辑");
                                }];
                                
                            });
                            
                        } else {
                            
                            NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];

                            dispatch_async(dispatch_get_main_queue(), ^{
                                [weakSelf.edittingSdk editVideoWithSuperController:weakSelf urlAsset:asset clipTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeSubtract(endTime, startTime)) crop:CGRectZero outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                                    
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        _edittingSdk = nil;
                                        [weakSelf enterPlayView:videoPath];
                                    });
                                    
                                } cancel:^{
                                    _edittingSdk = nil;
                                    NSLog(@"取消编辑");
                                }];
                            });
                            
                        }
                        
                        
                    } failback:^(NSError * _Nonnull error) {
                        _edittingSdk = nil;
                        NSLog(@"截取MV error----%@",error);
                    } cancel:^{
                        _edittingSdk = nil;
                        NSLog(@"取消截取");
                    }];
                    
                });
                
            } cancelBlock:^{
                _edittingSdk = nil;
                NSLog(@"取消MV");
            }];
        });
        
    };
    
    [_edittingSdk videoRecordAutoSizeWithSourceController:self callbackBlock:^(int result, NSString * _Nonnull path) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
           
            AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:path] options:nil];
            
            NSString * outputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
            
            [weakSelf.edittingSdk editVideoWithSuperController:weakSelf urlAsset:asset clipTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) crop:CGRectMake(0, 0, 1, 1) outputPath:outputPath callback:^(NSString * _Nonnull videoPath) {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                   _edittingSdk = nil;
                    [weakSelf enterPlayView:videoPath];
                });
                
            } cancel:^{
                _edittingSdk = nil;
                NSLog(@"取消编辑MV");
            }];
            
        });
        
    } imagebackBlock:^(NSString * _Nonnull videoPath) {
        dispatch_async(dispatch_get_main_queue(), ^{

        });
    } faileBlock:^(NSError * _Nonnull error) {
        _edittingSdk = nil;
        NSLog(@"error:%@",error);
    } cancel:^{
        _edittingSdk = nil;
        NSLog(@"取消编辑MV");
    }];
    
}

#pragma mark -
#pragma mark - 截取
- (void)trimVideoWithType:(NSInteger)index {

    NSString *path;
    switch (index) {
        case 0:
            path = [[NSBundle mainBundle] pathForResource:@"testFile1" ofType:@"mov"];
            break;
            
        case 1:
            path = [[NSBundle mainBundle] pathForResource:@"testFile_trimPortrait" ofType:@"mp4"];
            break;
            
        case 2:
            path = [[NSBundle mainBundle] pathForResource:@"testFile_trimSquare" ofType:@"mp4"];
            break;
            
        default:
            path = [[NSBundle mainBundle] pathForResource:@"testFile1" ofType:@"mov"];
            break;
    }
    
    NSString * exportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];
    
    _edittingSdk = [self createSdk];
    _editCfg.trimMode = CNLiveTRIMMODEAUTOTIME;
    _editCfg.trimExportVideoType = CNLiveTRIMEXPORTVIDEOTYPE_ORIGINAL;
    _editCfg.trimDuration_OneSpecifyTime = 15.0;
    _editCfg.trimMaxDuration_TwoSpecifyTime = 30.0;
    _editCfg.trimMinDuration_TwoSpecifyTime = 3.0;
    _editCfg.defaultSelectMinOrMax = kCNLiveDefaultSelectCutMax;
    
    __weak ViewController *weakSelf = self;

    [_edittingSdk setEditConfiguration:_editCfg];
    [_edittingSdk trimVideoWithSuperController:self
                               controllerTitle:@"修剪片段"
                               backgroundColor:self.view.backgroundColor
                             cancelButtonTitle:@"取消"
                        cancelButtonTitleColor:UIColorFromRGB(0xffffff)
                   cancelButtonBackgroundColor:UIColorFromRGB(0x000000)
                              otherButtonTitle:@"下载片段"
                         otherButtonTitleColor:UIColorFromRGB(0xffffff)
                    otherButtonBackgroundColor:UIColorFromRGB(0x00000)
                                     assetPath:path
                                    outputPath:exportPath
                                 callbackBlock:^(CNLiveCutVideoReturnType cutType, NSString * _Nonnull videoPath, CMTime startTime, CMTime endTime, CGRect cropRect) {
                                     
                                     if(cutType == CNLiveCutVideoReturnTypePath){
                                         NSLog(@"path:%@",videoPath);
                                         dispatch_async(dispatch_get_main_queue(), ^{
                                             _edittingSdk = nil;
                                             [weakSelf enterPlayView:videoPath];
                                         });
                                         
                                     }
                                     
                                     if(cutType == CNLiveCutVideoReturnTypeTime){
                                         NSLog(@"time:%lf,%lf",CMTimeGetSeconds(startTime),CMTimeGetSeconds(endTime));
                                         dispatch_async(dispatch_get_main_queue(), ^{
                                             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"截取时间范围" message:[NSString stringWithFormat:@"开始时间:%@\n结束时间:%@",[weakSelf timeFormat:CMTimeGetSeconds(startTime)],[weakSelf timeFormat:CMTimeGetSeconds(endTime)]] delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                                             [alertView show];
                                             _edittingSdk = nil;
                                         });
                                     }
                                     
                                 } failback:^(NSError * _Nonnull error) {
                                     NSLog(@"%@",error);
                                     _edittingSdk = nil;
                                 } cancel:^{
                                     NSLog(@"取消截取");
                                     _edittingSdk = nil;
                                 }];
}

#pragma mark -
#pragma mark - 压缩
- (void)compressVideo {
    
    _edittingSdk = [self createSdk];

    _compressOutputPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exportVideoFile.mp4"];

    __weak typeof(self) myself = self;
    [_edittingSdk onCnVEAlbumWithSuperController:self albumType:kCNLiveONLYALBUMVIDEO callBlock:^(NSMutableArray<NSURL *> * _Nonnull urls) {
        AVURLAsset *asset = [AVURLAsset assetWithURL:[urls firstObject]];
        _compressAsset = asset;
        [myself initCompressView:asset exportPath:_compressOutputPath];
        
    } cancelBlock:^{
        _edittingSdk = nil;
        NSLog(@"取消压缩");
    }];
}

#pragma mark- 压缩设置
- (void) initCompressView:(AVURLAsset *) asset exportPath:(NSString *)exportPath{
    if(!_compressOutputPath){
        return;
    }
    
    _compressSettingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width , [UIScreen mainScreen].bounds.size.height)];
    _compressSettingView.backgroundColor = self.view.backgroundColor;
    
    float width = MIN(_compressSettingView.frame.size.width, _compressSettingView.frame.size.height);
    NSDictionary* information = [_edittingSdk getVideoInformation:asset];
    int videoWidth = [[information objectForKey:@"width"] intValue];
    int videoHeight = [[information objectForKey:@"height"] intValue];
    float videoFps = [[information objectForKey:@"fps"] floatValue];
    float videoBitrate = [[information objectForKey:@"bitrate"] floatValue];
    
    NSLog(@"%d %d %f %f",videoWidth,videoHeight,videoFps,videoBitrate);
    
    UILabel* currentVideoSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    currentVideoSizeLabel.center = CGPointMake(width/2, 80);
    currentVideoSizeLabel.text = [NSString stringWithFormat:@"视频分辨率为:%dX%d",videoWidth,videoHeight];
    currentVideoSizeLabel.textColor = [UIColor whiteColor];
    
    currentVideoSizeLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:currentVideoSizeLabel];
    
    UILabel* currentVideoFpsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    currentVideoFpsLabel.center = CGPointMake(width/2, 110);
    currentVideoFpsLabel.text = [NSString stringWithFormat:@"视频帧率为:%d",(int)videoFps];
    currentVideoFpsLabel.textColor = [UIColor whiteColor];
    
    currentVideoFpsLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:currentVideoFpsLabel];
    
    UILabel* currentVideoBitrateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    currentVideoBitrateLabel.center = CGPointMake(width/2, 140);
    currentVideoBitrateLabel.text = [NSString stringWithFormat:@"视频码率为:%.2fM",videoBitrate/1000000];
    currentVideoBitrateLabel.textColor = [UIColor whiteColor];
    
    currentVideoBitrateLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:currentVideoBitrateLabel];
    
    UILabel* changeVideoSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    changeVideoSizeLabel.center = CGPointMake(width/2, 170);
    changeVideoSizeLabel.text = [NSString stringWithFormat:@"改变视频分辨率"];
    changeVideoSizeLabel.textColor = [UIColor whiteColor];
    
    changeVideoSizeLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:changeVideoSizeLabel];
    
    UITextField* changeVideoWidtheField = [[UITextField alloc] initWithFrame:CGRectMake(125, 158, (width-140)/2 , 25)];
    changeVideoWidtheField.layer.borderColor = [UIColor whiteColor].CGColor;
    changeVideoWidtheField.layer.borderWidth = 1;
    changeVideoWidtheField.layer.cornerRadius = 1;
    changeVideoWidtheField.layer.masksToBounds = YES;
    changeVideoWidtheField.textAlignment = NSTextAlignmentCenter;
    changeVideoWidtheField.delegate = self;
    
    NSMutableAttributedString* attrstr1 = [[NSMutableAttributedString alloc] initWithString:@"默认1000"];
    [attrstr1 addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, attrstr1.length)];
    changeVideoWidtheField.attributedPlaceholder = attrstr1;
    changeVideoWidtheField.returnKeyType = UIReturnKeyDefault;
    changeVideoWidtheField.textColor = [UIColor whiteColor];
    [_compressSettingView addSubview:changeVideoWidtheField];
    
    
    UITextField* changeVideoHeightField = [[UITextField alloc] initWithFrame:CGRectMake(125 + (width-140)/2 + 5, 158, (width-140)/2 , 25)];
    changeVideoHeightField.layer.borderColor = [UIColor whiteColor].CGColor;
    changeVideoHeightField.layer.borderWidth = 1;
    changeVideoHeightField.layer.cornerRadius = 1;
    changeVideoHeightField.layer.masksToBounds = YES;
    changeVideoHeightField.delegate = self;
    NSMutableAttributedString* attrstr2 = [[NSMutableAttributedString alloc] initWithString:@"默认800"];
    [attrstr2 addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, attrstr2.length)];
    
    changeVideoHeightField.attributedPlaceholder = attrstr2;
    changeVideoHeightField.textAlignment = NSTextAlignmentCenter;
    changeVideoHeightField.returnKeyType = UIReturnKeyDefault;
    changeVideoHeightField.textColor = [UIColor whiteColor];
    
    [_compressSettingView addSubview:changeVideoHeightField];
    
    UILabel* changeVideoBitrateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    changeVideoBitrateLabel.center = CGPointMake(width/2, 200);
    changeVideoBitrateLabel.text = [NSString stringWithFormat:@"改变视频码率"];
    changeVideoBitrateLabel.textColor = [UIColor whiteColor];
    
    changeVideoBitrateLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:changeVideoBitrateLabel];
    
    UITextField* changeVideoBitrateField = [[UITextField alloc] initWithFrame:CGRectMake(125, 188, width-130, 25)];
    changeVideoBitrateField.layer.borderColor = [UIColor whiteColor].CGColor;
    changeVideoBitrateField.layer.borderWidth = 1;
    changeVideoBitrateField.layer.cornerRadius = 1;
    changeVideoBitrateField.layer.masksToBounds = YES;
    changeVideoBitrateField.delegate = self;
    changeVideoBitrateField.textAlignment = NSTextAlignmentCenter;
    NSMutableAttributedString* attrstr3 = [[NSMutableAttributedString alloc] initWithString:@"单位兆(M),默认6"];
    [attrstr3 addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, attrstr3.length)];
    
    changeVideoBitrateField.attributedPlaceholder = attrstr3;
    changeVideoBitrateField.returnKeyType = UIReturnKeyDefault;
    changeVideoBitrateField.textColor = [UIColor whiteColor];
    [_compressSettingView addSubview:changeVideoBitrateField];
    
    UILabel* progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    progressLabel.center = CGPointMake(width/2, 230);
    progressLabel.textColor = [UIColor whiteColor];
    progressLabel.text = @"压缩进度";
    progressLabel.textAlignment = NSTextAlignmentLeft;
    [_compressSettingView addSubview:progressLabel];
    
    UIProgressView* progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
    progressView.center = CGPointMake(width/2, 260);
    progressView.trackTintColor = [UIColor whiteColor];
    progressView.progressTintColor = [UIColor blueColor];
    
    [progressView setProgressViewStyle:UIProgressViewStyleDefault];
    [_compressSettingView addSubview:progressView];
    
    UIButton* compressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    compressBtn.backgroundColor =[UIColor whiteColor];
    compressBtn.frame = CGRectMake(0, 0, 100, 50);
    compressBtn.center = CGPointMake(width/2 - 100, 300);
    [compressBtn setTitle:@"压缩" forState:UIControlStateNormal];
    [compressBtn setTitleColor:UIColorFromRGB(0x7e8181) forState:UIControlStateNormal];
    compressBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    compressBtn.layer.cornerRadius = 4.0;
    compressBtn.layer.masksToBounds = YES;
#if 1
    __weak ViewController *myself = self;
    
    __weak typeof(compressBtn) weakCompressBtn = compressBtn;
    [compressBtn addTapBlock:^(UIButton *btn) {
        
        if(btn.selected){
            return ;
        }
        btn.selected = YES;
        weakCompressBtn.userInteractionEnabled = NO;
        [changeVideoHeightField resignFirstResponder];
        [changeVideoWidtheField resignFirstResponder];
        [changeVideoBitrateField resignFirstResponder];
        
        int w = [changeVideoWidtheField.text intValue];
        w = w==0?1000:w;
        w = w > 4000?4000:w;
        
        
        int h = [changeVideoHeightField.text intValue];
        h = h==0?800:h;
        h = h > 4000?4000:h;
        
        
        float b = [changeVideoBitrateField.text floatValue];
        b = (b==0.0)?6.0:b;
        
        _exportCfg.condenseVideoResolutionRatio = CGSizeMake(w, h);
        _exportCfg.videoBitRate = b;
        [_edittingSdk compressVideoAsset:asset
                              outputPath:exportPath
                               startTime:kCMTimeZero
                                 endTime:asset.duration
                              outputSize:_exportCfg.condenseVideoResolutionRatio
                           outputBitrate:_exportCfg.videoBitRate
                              supperView:myself
                           progressBlock:^(float prencent) {
                               NSLog(@"progress:%f",prencent);
                               dispatch_async(dispatch_get_main_queue(), ^{
                                   progressLabel.text = [NSString stringWithFormat:@"压缩进度%.2f%%",prencent*100.0];
                                   [progressView setProgress:prencent animated:YES];
                                   
                               });
                               
                           } callbackBlock:^(NSString *videoPath){
                               dispatch_async(dispatch_get_main_queue(), ^{
                                   
                                   [progressView removeFromSuperview];
                                   [progressLabel removeFromSuperview];
                                   
                                   NSLog(@"%f",[myself fileSizeAtPath:videoPath]);
                                   
                                   _compressSettingView.alpha = 0.0;
                                   
                                   PlayVideoController *playVC = [[PlayVideoController alloc] init];
                                   if(!(videoPath.length>0)){
                                       NSString *path = [[NSBundle mainBundle] pathForResource:@"testFile1" ofType:@"mov"];
                                       playVC.videoPath = path;
                                       
                                   }else{
                                       playVC.videoPath = videoPath;
                                   }
                                   btn.selected = NO;
                                   [myself.navigationController pushViewController:playVC animated:NO];
                                   _edittingSdk = nil;
                                   [myself releaseCompressSettingView];
                                   
                               });
                           } fail:^(NSError *error){
                               NSLog(@"%@",error);
                               btn.selected = NO;
                               _edittingSdk = nil;
                           }];
        
    }];
#endif
    
    [_compressSettingView addSubview:compressBtn];
    
    UIButton* cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(0, 0, 100, 50);
    cancelBtn.center = CGPointMake(width/2 + 100, 300);
    cancelBtn.backgroundColor = [UIColor whiteColor];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    
    cancelBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    cancelBtn.layer.cornerRadius = 4.0;
    cancelBtn.layer.masksToBounds = YES;
    [cancelBtn setTitleColor:UIColorFromRGB(0x7e8181) forState:UIControlStateNormal];
#if 1
    [cancelBtn addTapBlock:^(UIButton *btn) {
        NSLog(@"取消");
        [changeVideoHeightField resignFirstResponder];
        [changeVideoWidtheField resignFirstResponder];
        [changeVideoBitrateField resignFirstResponder];
        
        [_edittingSdk compressCancel];
        _edittingSdk= nil;
        _compressSettingView.hidden = YES;
        
    }];
    
#endif
    [_compressSettingView addSubview:cancelBtn];
    
    
    [self.navigationController.view addSubview:_compressSettingView];
    
}

- (float ) fileSizeAtPath:(NSString*) filePath{
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        long long size = [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
        float s = (float)size/1024.0/1024.0;
        
        return s;
    }
    return 0;
}

- (void)releaseCompressSettingView{
    [_compressSettingView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
        obj = nil;
    }];
    
    [_compressSettingView removeFromSuperview];
    _compressSettingView = nil;
}

#pragma mark- 将时间转换成字符串格式
- (NSString *) timeFormat: (float) seconds {
    if(seconds<=0){
        seconds = 0;
    }
    int hours = seconds / 3600;
    int minutes = seconds / 60;
    int sec = fabs(round((int)seconds % 60));
    if (hours>=1) {
        return [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, sec];
    }else{
        return [NSString stringWithFormat:@"%02i:%02i",minutes, sec];
    }
}
#pragma mark -
#pragma mark - UITableViewDelegate/UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [_functionList count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[_functionList[section] objectForKey:@"functionList"] count];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 44)];
    headView.backgroundColor = [UIColor clearColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 12, headView.frame.size.width - 60, 20)];
    
    titleLabel.font = [UIFont systemFontOfSize:18];
    titleLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
    titleLabel.textColor = [UIColor colorWithWhite:1 alpha:0.5];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.text = [_functionList[section] objectForKey:@"title"];
    titleLabel.layer.masksToBounds = YES;
    [headView addSubview:titleLabel];
    return headView;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *iCell = @"cell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iCell];
    cell.textLabel.text = [[_functionList[indexPath.section] objectForKey:@"functionList"] objectAtIndex:indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    if(indexPath.row == 1 && indexPath.section == 2){
        cell.textLabel.textColor = UIColorFromRGB(0x888888);
        
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            [self recordVideoWithType:indexPath.row];
            break;
            
        case 1:
            [self editVideoWithType:indexPath.row];
            break;
            
        case 2:
            if(indexPath.row == 1){
                return;
            }
            [self shortVideoEdit];
            break;
            
        case 3:
            [self trimVideoWithType:indexPath.row];
            
            break;
            
        case 4:
            [self onCnVEAlbumWithType:indexPath.row];
            break;
            
        case 5:
            [self compressVideo];
            break;

        default:
            break;
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat sectionHeaderHeight = 40;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    }
    else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}

#pragma mark -
#pragma mark -
- (void)loadListData {
    
    _functionList = [[NSMutableArray alloc] init];
    
    NSMutableArray *functions_1 = [[NSMutableArray alloc] init];
    NSMutableArray *functions_2 = [[NSMutableArray alloc] init];
    NSMutableArray *functions_3 = [[NSMutableArray alloc] init];
    NSMutableArray *functions_4 = [[NSMutableArray alloc] init];
    NSMutableArray *functions_5 = [[NSMutableArray alloc] init];
    NSMutableArray *functions_6 = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *functions_Dic1 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *functions_Dic2 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *functions_Dic3 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *functions_Dic4 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *functions_Dic5 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *functions_Dic6 = [[NSMutableDictionary alloc] init];
    
    [functions_1 addObject:@"(1) 正方形方式"];
    [functions_1 addObject:@"(2) 全屏方式"];
    [functions_1 addObject:@"(3) 全屏、正方形(自由切换)"];
    [functions_Dic1 setObject:@"录制/拍照" forKey:@"title"];
    [functions_Dic1 setObject:functions_1 forKey:@"functionList"];
    
    [functions_2 addObject:@"(1) 无相册选择,进入编辑"];
    [functions_2 addObject:@"(2) 从相册选择后进入编辑"];
    [functions_Dic2 setObject:@"视频编辑" forKey:@"title"];
    [functions_Dic2 setObject:functions_2 forKey:@"functionList"];
    
    [functions_3 addObject:@"(1) 15秒短视频"];
    [functions_Dic3 setObject:@"短视频(由视频编辑配置而成)" forKey:@"title"];
    [functions_Dic3 setObject:functions_3 forKey:@"functionList"];
    
    [functions_4 addObject:@"(1) 横屏视频"];
    [functions_4 addObject:@"(2) 竖屏视频"];
    [functions_4 addObject:@"(3) 正方形视频"];
    [functions_Dic4 setObject:@"视频截取" forKey:@"title"];
    [functions_Dic4 setObject:functions_4 forKey:@"functionList"];
    
    [functions_5 addObject:@"(1) 视频+图片"];
    [functions_5 addObject:@"(2) 仅视频"];
    [functions_5 addObject:@"(3) 仅图片"];
    [functions_Dic5 setObject:@"选择相册" forKey:@"title"];
    [functions_Dic5 setObject:functions_5 forKey:@"functionList"];
    
    [functions_6 addObject:@"(1) 视频压缩"];
    [functions_Dic6 setObject:@"视频压缩" forKey:@"title"];
    [functions_Dic6 setObject:functions_6 forKey:@"functionList"];
    
    [_functionList addObject:functions_Dic1];
    [_functionList addObject:functions_Dic2];
    [_functionList addObject:functions_Dic3];
    [_functionList addObject:functions_Dic4];
    [_functionList addObject:functions_Dic5];
    [_functionList addObject:functions_Dic6];
}

#pragma mark -
#pragma mark - lazy
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, kHEIGHT-64) style:UITableViewStyleGrouped];
        _tableView.backgroundView = nil;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end