1. 程式人生 > >-[AVComposition URL]: unrecognized selector sent to instance

-[AVComposition URL]: unrecognized selector sent to instance

 [manager requestAVAssetForVideo:PHAsset
                           options:videoRequestOptions
                     resultHandler:^(AVAsset * avasset, AVAudioMix * audioMix, NSDictionary * info) {}];
程式碼報錯:原因是
avasset  可能是AVURLAsset  與 AVComposition , 直接呼叫 【avasset URL】,當選取的視訊 是慢動作視訊,huicrash;

解決思路:

1、過濾慢動作視訊

//載入視訊
+ (void)loadVideos {
 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    ALAssetsLibrary *videolibrary = [[ALAssetsLibrary alloc] init];
    __block NSMutableArray *reList=[NSMutableArray array];
    __block BOOL flag=true;
    [videolibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if (group) {
            [group setAssetsFilter:[ALAssetsFilter allVideos]];
            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                if (result) {
                    BDHKUGCVideoInfoItem *videoInfo=[[BDHKUGCVideoInfoItem alloc] init];
                    videoInfo.thumbnail = [UIImage imageWithCGImage:result.thumbnail];
                    videoInfo.videoURL = result.defaultRepresentation.url;
                    NSInteger duration = [[result valueForProperty:ALAssetPropertyDuration] integerValue];
                    videoInfo.duration = [NSDate durationWithSeconds:duration];
                    videoInfo.name = result.defaultRepresentation.filename;
                    videoInfo.size = result.defaultRepresentation.size; //Bytes
                    videoInfo.format = [result.defaultRepresentation.filename pathExtension];
                    videoInfo.creationDate = [result valueForProperty:ALAssetPropertyDate];
                    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[videoInfo.videoURL] options:nil];
                    PHAsset *phAsset = fetchResult.firstObject;
                    [[PHImageManager defaultManager] requestAVAssetForVideo:phAsset options:nil
                                                              resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) {
                                                                  //視訊上傳不支援慢視訊
                                                                  if (avAsset && [avAsset isKindOfClass:[AVURLAsset class]]) {
                                                                      if(videoInfo.thumbnail && videoInfo.videoURL && duration>7) {
                                                                          [reList addObject:videoInfo];
                                                                      }
                                                                  }
                                                              }];
                }
            }];
        } else {
            //沒有更多的group時,即可認為已經載入完成。
            if(flag) {//防止重複通知
                dispatch_async(dispatch_get_main_queue(), ^{
                    //*******
                    //按建立時間倒序
                    NSSortDescriptor *creationDateDesc = [NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO];
                    NSArray *descriptorArray = [NSArray arrayWithObjects:creationDateDesc, nil];
                    NSArray *sortedArray = [reList sortedArrayUsingDescriptors: descriptorArray];
                    //*******
                    //通知返回資料
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"ugc_camera_result_notif" object:sortedArray];
                });
                flag = false;
            }
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"error=%@",error);
        //增加錯誤返回處理
        if(flag) {//防止重複通知
            dispatch_async(dispatch_get_main_queue(), ^{
                NSArray *sortedArray = [[NSArray alloc] init];
                //通知返回資料
                [[NSNotificationCenter defaultCenter] postNotificationName:@"ugc_camera_result_notif" object:sortedArray];
            });
            flag = false;
        }
    }];
  });
}

2、將選取的視訊儲存到本地,上傳視訊使用

//Output URL
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths.firstObject;
NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"mergeSlowMoVideo-%d.mov",arc4random() % 1000]];
NSURL *url = [NSURL fileURLWithPath:myPathDocs];

//Begin slow mo video export
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;

[exporter exportAsynchronouslyWithCompletionHandler:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (exporter.status == AVAssetExportSessionStatusCompleted) {
            NSURL *URL = exporter.outputURL;
            NSData *videoData = [NSData dataWithContentsOfURL:URL];

             // Upload
             [self uploadSelectedVideo:video data:videoData];
         }
    });
}];
參考地址:https://overflow.buffer.com/2016/02/29/slow-motion-video-ios/

相關推薦

-[AVComposition URL]: unrecognized selector sent to instance

[manager requestAVAssetForVideo:PHAsset options:videoRequestOptions resultHandler:^(AVAss

[UIApplication openURL:options:completionHandler:]: unrecognized selector sent to instance

有用 lec ica value selector sent har div option 最近看日誌發現有用戶點擊跳轉閃退的問題,查了一下原因是下面的方法是在ios 10系統以後才支持的,如果用戶是ios 10以下系統會崩潰 [[UIApplication shared

【IOS】無法識別類別拓展方法unrecognized selector sent to instance的解決方法

有時在開發中會發現無法識別拓展類別的新增方法,總是識別原檔案的方法,而原檔案中是沒有新添方法的,於是在動態呼叫拓展方法時丟出了unrecognized selector sent to instance的錯誤。 解決方法是在Xcode的Build Settings下Othe

NSCFType unrecognized selector sent to instance等問題

看到這些問題,其實列印的很清楚,就是NSCFType找不到某個方法,但瞬間又疑惑了,NSCFType是什麼鬼,自己也沒呼叫這個類,後來網上查了一下,大部分的資料是說,也就是說,instance物件過早的釋放掉了,指標雖然還是指向那塊記憶體地址,但記憶體實際已經被釋放掉了,自然

問題人生[20160330] -[NSCFString containsString:]: unrecognized selector sent to instance 0x7f9902724da0

進行字串搜尋比對時用到的方法 containsString,在iOS7中執行時發生崩潰: -[NSCFString containsString:]: unrecognized selector sent to instance 0x7f9902724da0 查詢API

unrecognized selector sent to instance出現的原因和解決方案

造成unrecognized selector sent to instance iphone,大部分情況下是因為物件被提前release了,在你心裡不希望他release的情況下,指標還在,物件已經不在了。很多時候,是因為init初始化函式中,對屬性賦值沒有使用self

xcode 執行出現類似-[__NSCFString objectForKey:]: unrecognized selector sent to instance的除錯方法

1.在程式中任意的.m檔案(最好在特定的檔案中,如為解決此類問題單獨建一個統一的.m檔案)中新增類似以下程式碼 @implementation NSString (NSStringDebug) -(void) objectForKey:(NSString*) str 

-[__NSCFConstantString size]: unrecognized selector sent to instance 0xce18c0

原[btn setImage:@"iconfont-liaotian" forState:UIControlStateNormal]; 改[btn setImage:[UIImage imageName

出現“unrecognized selector sent to instance”問題原因之一及解決方法。

對於iPhone開發初學者來說,很想實現自己在iPhone上的第一個小程式,準備工作就緒侯就信心滿滿的開始了!一般來說大家可能都是從Hello World做起吧。 反正我是的,:),如果按照文件上的說明去做,一般也不會出現什麼問題。也建議初學者這樣開始,畢竟會增強我們自己的

-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x1744523c0

出現這種報錯,我之前也很疑惑,但看一下錯誤資訊後明白了,我的可變陣列被改成不可變陣列了,不能使用addobject來新增資料,所以我就找程式碼中哪裡別修改了,發現對陣列做去重處理的時候被改變的讓後改成這樣就好了,mutablecopy方法是將就不可變陣列轉換為可變陣列,然後就

[UIImageView setImageWithURL:]: unrecognized selector sent to instance解決辦法

Common Problems Using dynamic image size with UITableViewCell UITableView determins the size of the image by the first image set for a cell. If your rem

unrecognized selector sent to instance

問題原因是:我的storyboard中的介面class中沒有關聯自己的類:FendianTBV,關聯好後傳值就再無問題了 ios 開發中我從一個介面往另一個storyboard介面傳值時出現了這個問題

使用Masonry報unrecognized selector sent to instance的錯

問題的來源:       現在我公司有兩個專案,A專案(使用xcode的版本比較舊),B專案(使用最新的xcode版本);       B專案是使用cocoaPods管理第三方庫,並加了一些第三方庫。

unrecognized selector sent to instance問題原因之一及解決方法。

1. 自己遇到的問題: 2015-05-28 15:46:53.046 test[5298:146142] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:

iOS呼叫分類時異常unrecognized selector sent to class

執行程式時寫的分類拋異常,也沒看懂異常是什麼意思,後來在分類中再新增新方法時發現.m檔案取不到.h檔案中的方法名,原來是分類檔案建立的有問題,具體原因還不知道。對unrecognized selector sent t

objective-c-常見問題-encodeWithCoder -unrecognized selector sent

-[XXXXXXX(你定義的類) encodeWithCoder:]: unrecognized selector sent to instance 0x8ec89e0' 這個問題字面意思,就是你定義的的類的encodeWithCoder:方法找不到 既然是出現了

Argument of '#selector' refers to instance method 'changeScale(byReactingTo:)' that is not exposed t

swfit 4 的新特性, 今天編譯程式碼發現了這個問題,查了下,修正很簡單在相關類前加: @objcMembers! As of Swift 4 you'll start seeing the error "Argument of '#selector' ref

iOS記憶體錯誤EXC_BAD_ACCESS的解決方法(message sent to deallocated instance)

iOS開發,最鬱悶的莫過於程式毫無徵兆地就崩潰了,用bt命令打出呼叫棧,給出的是一堆系統EXC_BAD_ACCESS的資訊,根本沒辦法定位問題出現在哪裡。通常這樣的崩潰出現,原因一般就是:呼叫了已經釋放的記憶體空間,或者說重複釋放了某個地址空間。而怎樣定位到這個地址呢,可以通過編輯xcode的scheme,新

message sent to deallocated instance 除錯

常常程式一長,哪邊就不小心多release了一次 這時候編譯器就只會告訴你:BAD_ACCESS,然後程式就死了 剛開始會google到去Argument加個NSZombieEnabled YES 會多吐一點東西讓你把bug除掉 今天遇到加了這個後error messag

使用redis做一次投票活動中tomcat 啟動一段時間後宕機redis.clients.jedis.exceptions.JedisDataException: value sent to redi

一個微信投票活動中專案扔tomcat中跑起來 ,後來投票後不間斷老司機,當時十分費解  ,小專案沒用日誌略坑,只能檢視tomcat日誌,於是看到日誌記錄報錯如下 Jun 17, 2017 7:52:53 AM org.apache.catalina.core.Standar