7

मैं जिसमें मैं विशेष रूप से अंत बिंदु करने के लिए विशेष रूप से प्रारंभ बिंदु से रिकॉर्ड किए गए वीडियो ट्रिम करने के लिए के रूप में दर्ज करें या उपयोगकर्ता द्वारा चयनित किसी कार्य पर काम कर रहा हूँ के लिए तेज में एक वीडियो ट्रिम करने के लिए। मुझे ऐसा कैसे करना चाहिए। जैसा कि मैंने पहले UIVideoEditorController का उपयोग किया था, लेकिन मैं डिफ़ॉल्ट दृश्य का उपयोग नहीं करना चाहता हूं और मैं सीधे वीडियो को ट्रिम करना चाहता हूं।कैसे एक विशेष समय

let FinalUrlTosave = NSURL(string: "\(newURL)") 
    exportSession!.outputURL=FinalUrlTosave 
    exportSession!.shouldOptimizeForNetworkUse = true 
    // exportSession.outputFileType = AVFileTypeQuickTimeMovie 
    exportSession!.outputFileType = AVFileTypeQuickTimeMovie; 
    let start:CMTime 
    let duration:CMTime 
    var st = starttime.doubleValue 
    var ed = endTime.doubleValue 
    start = CMTimeMakeWithSeconds(st, 600) 
    duration = CMTimeMakeWithSeconds(ed, 600) 
    // let timeRangeForCurrentSlice = CMTimeRangeMake(start, duration) 
    let range = CMTimeRangeMake(start, duration); 
    exportSession!.timeRange = range 

     exportSession!.exportAsynchronouslyWithCompletionHandler({ 
     switch exportSession!.status{ 
     case AVAssetExportSessionStatus.Failed: 

      print("failed \(exportSession!.error)") 
     case AVAssetExportSessionStatus.Cancelled: 
      print("cancelled \(exportSession!.error)") 
     default: 
      print("complete....complete") 
      //    self.SaveVideoToPhotoLibrary(destinationURL1!) 

     } 
    }) 

मैं इसका उपयोग करके अपना लक्ष्य प्राप्त करने की कोशिश कर रहा हूं लेकिन सफल नहीं रहा हूं।

त्रुटि संदेश:

वैकल्पिक विफल रहा है (त्रुटि डोमेन = NSURLErrorDomain कोड = -1100 " अनुरोध किया गया URL इस सर्वर पर नहीं मिला था।" UserInfo = {NSErrorFailingURLStringKey = file: /// var/मोबाइल/कंटेनर/डेटा/एप्लिकेशन/E68D3BFD-6923-4EA6-9FB3-C020CE4AA9D4/दस्तावेज़/पल/jGq_9AUFa47s2ZiiPP4x.mp4, NSErrorFailingURLKey = फ़ाइल: /// var/mobile/कंटेनर/डेटा/एप्लिकेशन/E68D3BFD-6923-4EA6- 9 एफबी 3-सी 020 सी 4 एए 9 डी 4/दस्तावेज़/पल/jGq_9AUFa47s2ZiiPP4x.mp4, NSLocalizedDescription = अनुरोध किया गया URL इस सर्वर पर नहीं मिला था।, NSUnderlyingError = 0x1553c220 {Err या डोमेन = एन

त्रुटि दूसरी बार हुआ:

में विफल रहा है वैकल्पिक (त्रुटि डोमेन = NSURLErrorDomain कोड = -3000 " फ़ाइल नहीं बना सकता" UserInfo = {NSUnderlyingError = 0x14e00000 {त्रुटि डोमेन = NSOSStatusErrorDomain कोड = -12,124 "(शून्य)"}, NSLocalizedDescription = फ़ाइल})

+0

यह कैसे असफल रहा है? त्रुटि क्या है? – hola

+0

मैं newURL पैरामीटर के लिए एक यूआरएल पास कर रहा हूं और यह हमेशा असफल त्रुटि ब्लॉक में जा रहा है ... –

+0

हाँ लेकिन * त्रुटि संदेश * क्या है? – Moritz

उत्तर

12

मैं इस पद्धति का उपयोग मेरी समाधान नहीं बनाया जा सकता है और यह एक आकर्षण की तरह काम करता ....

func cropVideo(sourceURL1: NSURL, statTime:Float, endTime:Float) 
{ 
    let manager = NSFileManager.defaultManager() 

    guard let documentDirectory = try? manager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) else {return} 
    guard let mediaType = "mp4" as? String else {return} 
    guard let url = sourceURL1 as? NSURL else {return} 

    if mediaType == kUTTypeMovie as String || mediaType == "mp4" as String { 
     let asset = AVAsset(URL: url) 
     let length = Float(asset.duration.value)/Float(asset.duration.timescale) 
     print("video length: \(length) seconds") 

     let start = statTime 
     let end = endTime 

     var outputURL = documentDirectory.URLByAppendingPathComponent("output") 
     do { 
      try manager.createDirectoryAtURL(outputURL, withIntermediateDirectories: true, attributes: nil) 
      let name = Moment.newName() 
      outputURL = outputURL.URLByAppendingPathComponent("\(name).mp4") 
     }catch let error { 
      print(error) 
     } 

     //Remove existing file 
     _ = try? manager.removeItemAtURL(outputURL) 


     guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {return} 
     exportSession.outputURL = outputURL 
     exportSession.outputFileType = AVFileTypeMPEG4 

     let startTime = CMTime(seconds: Double(start ?? 0), preferredTimescale: 1000) 
     let endTime = CMTime(seconds: Double(end ?? length), preferredTimescale: 1000) 
     let timeRange = CMTimeRange(start: startTime, end: endTime) 

     exportSession.timeRange = timeRange 
     exportSession.exportAsynchronouslyWithCompletionHandler{ 
      switch exportSession.status { 
      case .Completed: 
       print("exported at \(outputURL)") 
       self.saveVideoTimeline(outputURL) 
      case .Failed: 
       print("failed \(exportSession.error)") 

      case .Cancelled: 
       print("cancelled \(exportSession.error)") 

      default: break 
      } 
     } 
    } 
} 
+1

शानदार उत्तर! @ पारव भास्कर –

+0

धन्यवाद यह काम करता है, लेकिन आउटपुट वीडियो में ऑडियो नहीं है। – user3306145

संबंधित मुद्दे