2016-07-08 67 views
9

我正在研究一個需要編輯視頻(設置疊加層)的應用程序。現在,雖然從iPhones拍攝的視頻編輯得很好,但從Android手機拍攝的視頻獲得編輯後空白。使用AVFoundation進行編輯後,android手機拍攝的視頻被破壞iOS

我無法想象會出現什麼問題。我會很感激立即的幫助。

這是方法之一(修剪功能)。

- (IBAction)cutButtonTapped:(id)sender { 

    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    hud.mode = MBProgressHUDModeText; 
    hud.labelText = @"Encoding..."; 

    [self.playButton setBackgroundImage:[UIImage imageNamed:@"video_pause.png"] forState:UIControlStateNormal]; 



    NSString *uniqueString = [[NSProcessInfo processInfo]globallyUniqueString]; 

//do this to export video 
    NSURL *videoFileUrl = [NSURL fileURLWithPath:[AppHelper userDefaultsForKey:@"videoURL"]]; 

    AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:nil]; 
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset]; 

    if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) { 

     self.exportSession_ = [[AVAssetExportSession alloc] 
          initWithAsset:anAsset presetName:AVAssetExportPresetPassthrough]; 
    // Implementation continues. 

    //  NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:@".mov"]]; 
      NSURL *furl = [self newURLWithName:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]]; 

    self.exportSession_.outputURL = furl; 
    self.exportSession_.outputFileType = AVFileTypeMPEG4; 

    CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale); 
    CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale); 
    CMTimeRange range = CMTimeRangeMake(start, duration); 
    CMTimeShow(self.exportSession_.timeRange.duration); 
    self.exportSession_.timeRange = range; 
    CMTimeShow(self.exportSession_.timeRange.duration); 

    [self.exportSession_ exportAsynchronouslyWithCompletionHandler:^{ 

     switch ([self.exportSession_ status]) { 
      case AVAssetExportSessionStatusFailed: 
       NSLog(@"Export failed: %@", [[self.exportSession_ error] localizedDescription]); 
       break; 
      case AVAssetExportSessionStatusCancelled: 
       NSLog(@"Export canceled"); 
       break; 
      default: 
       NSLog(@"NONE"); 
       dispatch_async(dispatch_get_main_queue(), ^{ 

//       [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:@".mov"]]; 
         [self playDocumentDirectoryVideoWithURLString:[uniqueString stringByAppendingString:[NSString stringWithFormat:@".%@",[videoFileUrl pathExtension]]]]; 

       }); 
     } 
    }]; 
} 

}

任何人都可以請幫我這個?

+0

有件事情我不明白:你有一個問題,你的iOS應用或做你有你的Android應用問題?我的意思是,我的理解是,當您想要在iPhone上編輯這些視頻時,您遇到了Android手機拍攝的視頻問題。但我認爲你的問題是:你的iOS應用運行良好,你的Android應用沒有。 – Randy

+0

在android應用程序中沒有這樣的問題.FFMPEG庫已用於整個視頻編輯過程。但在iOS應用程序中,我使用AVFoundation來完成所有視頻編輯任務(剪切,速度,覆蓋,合併)。適用於從iPhone拍攝的視頻,但不適用於從android拍攝的視頻。 – Reckoner

+0

你能告訴我們你的代碼嗎? – Randy

回答

1

首先,我建議您檢查duration & range值。這似乎與CMTime和解碼有關。 第二,嘗試用一個選項來初始化你AVURLAsset強制時間提取:

AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @(YES)}]; 
+0

仍是同樣的問題。 – Reckoner

+0

任何機會,你可以在處理之前和之後附加視頻? – dive

+0

是的,我會在今天晚些時候附上。但我想我已經找到了問題。問題是,當我嘗試調整指令層來調整視頻方向時,我遇到了這個問題。但問題是:爲什麼只有在android視頻? – Reckoner

相關問題