2016-07-12 2 views
-2

NSUrlConnectionを使用してオーディオをダウンロードし、デバイスに保存するように管理しました。今私はこの(私は推測.mp3)ファイルを.mp4ビデオファイルに変換したいと思います。オーディオからビデオへの変換

+0

を手に入れました –

答えて

-1

ユーチューブとFBでの.mp3形式を許可していないので、私は解決策

let soundFileUrl = audioURL 
    let recordAsset: AVURLAsset = AVURLAsset(URL: soundFileUrl, options: nil) 

    let mixComposition: AVMutableComposition = AVMutableComposition() 
    let recordTrack: AVMutableCompositionTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: CMPersistentTrackID()) 

    let tracks1 = recordAsset.tracksWithMediaType(AVMediaTypeAudio) 
    let assetTrack1:AVAssetTrack = tracks1[0] 

    let audioDuration:CMTime = assetTrack1.timeRange.duration 
    do 
    { 
     try recordTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, audioDuration), ofTrack: assetTrack1, atTime: kCMTimeZero) 

    } catch { 
    } 

    let assetExport = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetPassthrough)! 
    assetExport.outputFileType = AVFileTypeQuickTimeMovie 
    assetExport.outputURL = savePathUrl 
    assetExport.shouldOptimizeForNetworkUse = true 

    assetExport.exportAsynchronouslyWithCompletionHandler({ 

     switch assetExport.status { 
     case AVAssetExportSessionStatus.Failed: 
      print("failed \(assetExport.error)") 
     case AVAssetExportSessionStatus.Cancelled: 
      print("cancelled \(assetExport.error)") 
     default: 
      print("complete\(savePathUrl)") 
     } 
    }) 
関連する問題