Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. [self dismissModalViewControllerAnimated:NO];
  2.  
  3. // Handle movie capture
  4. NSURL *movieURL = [info objectForKey:
  5. UIImagePickerControllerMediaURL];
  6.  
  7. NSData *data = [NSData dataWithContentsOfURL:movieURL];
  8.  
  9. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  10. NSString *documentsDirectory = [paths objectAtIndex:0];
  11. NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"];
  12.  
  13. BOOL success = [data writeToFile:tempPath atomically:NO];
  14.  
  15. if (success)
  16. {
  17. NSLog(@"VIdeo Successfully written");
  18. }
  19. else
  20. {
  21. NSLog(@"VIdeo Wrting failed");
  22. }
  23.  
  24.  
  25. NSURL *uploadURL = [NSURL fileURLWithPath:[[NSTemporaryDirectory() stringByAppendingPathComponent:@"1234"] stringByAppendingString:@".mp4"]];
  26.  
  27. // Compress movie first
  28. [self convertVideoToLowQuailtyWithInputURL:movieURL outputURL:uploadURL];
  29.  
  30. while ([videoWriterInput isReadyForMoreMediaData])
  31. {
  32.  
  33. CMSampleBufferRef sampleBuffer;
  34.  
  35. if ([videoReader status] == AVAssetReaderStatusReading &&
  36. (sampleBuffer = [videoReaderOutput copyNextSampleBuffer]))
  37. {
  38.  
  39. [videoWriterInput appendSampleBuffer:sampleBuffer];
  40. CFRelease(sampleBuffer);
  41. }
  42.  
  43. else
  44. {
  45. [videoWriterInput markAsFinished];
  46.  
  47. if ([videoReader status] == AVAssetReaderStatusCompleted)
  48.  
  49. [videoWriter startSessionAtSourceTime:kCMTimeZero];
  50.  
  51. dispatch_queue_t processingQueue = dispatch_queue_create("processingQueue2", NULL);
  52.  
  53. [audioWriterInput requestMediaDataWhenReadyOnQueue:processingQueue usingBlock:^{
  54.  
  55. while (audioWriterInput.readyForMoreMediaData)
  56. {
  57. CMSampleBufferRef sampleBuffer;
  58.  
  59. if ([audioReader status] == AVAssetReaderStatusReading &&
  60. (sampleBuffer = [audioReaderOutput copyNextSampleBuffer])) {
  61.  
  62. [audioWriterInput appendSampleBuffer:sampleBuffer];
  63. CFRelease(sampleBuffer);
  64. }
  65.  
  66. else
  67. {
  68.  
  69. [audioWriterInput markAsFinished];
  70.  
  71. if ([audioReader status] == AVAssetReaderStatusCompleted)
  72. {
  73. [videoWriter finishWritingWithCompletionHandler:^()
  74. {
  75. NSLog(@"Output URl : %@",outputURL);
  76. }];
  77. }
  78. }
  79. }
  80.  
  81. }
  82. ];
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement