2011-07-06 75 views
1

我有簡單的視頻壓縮代碼在低質量conversion.I測試我的代碼在iOS 4與iOS 4.2.1。問題是當我測試我的代碼在設備上沒有斷點代碼無法創建視頻(它只是一個零kb文件或創建的空文件),但當我使用斷點逐行逐行檢查該代碼時,它會製作一個完美的壓縮視頻,它也可以在mac中的quicktime播放器上運行。壓縮後,我會製作zip這個視頻文件。AVAssetExportSession有和沒有斷點

NSURL *videoURL=[[self.videourlarray objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL]; 
     NSURL *outputURL = [NSURL fileURLWithPath:videoFile]; 

     [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; 
     AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil]; 
     AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; 
     exportSession.outputURL = outputURL; 
     exportSession.shouldOptimizeForNetworkUse = YES; 
     exportSession.outputFileType = AVFileTypeQuickTimeMovie; 
     [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
     { 
      NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error); 
      [exportSession release]; 
     }]; 

thanx的任何幫助......

+0

導出狀態是什麼?如果你不釋放exportSession,會發生什麼? –

+0

不釋放導出並且exportSession.status爲3且exportSession.error爲空後仍然沒有成功。 – Dhawal

+0

您的應用退出了嗎? –

回答

6

我認爲你需要確保你不被線程搞亂..(AVFoundation指導說,出口並不能保證在任何特定的運行線)。

使用這樣的塊。

[exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
    { 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error); 
      }); 

    }]; 

我會親自打電話從塊代表,但是我相信你簡單的日誌語句只是在這個例子中,你已經知道:)

+0

最後,這個dispatch_async適合我:) –

1

我有同樣的問題。經過幾個小時的調試,我發現我的音頻文件的擴展名全部是大寫的.M4A。降低字母將解決問題