2016-07-07 9 views
9

मेरे पास छवियों की एक सरणी है जिसमें से मैं इन छवियों को अनुक्रम में एक के बाद एक वीडियो बनाकर एक वीडियो बनाना चाहता हूं। मैं एक अलग प्रकार की एनीमेशन जोड़ना चाहता हूं जब छवि बदल जाती है। कोको ढांचे के साथ उद्देश्य-सी में इस कार्यक्षमता को प्राप्त करने के लिए मुझे कुछ विधि या कोई समाधान सुझाएं।छवियों का उपयोग करते हुए वीडियो बनाने के दौरान छवि परिवर्तन पर एनीमेशन जोड़ने के लिए

यहाँ छवियों की वीडियो बनाने के लिए कोड काम कर रहा है, लेकिन कृपया सुझाव है कि हम कैसे छवियों चेतन वीडियो बना जबकि:

-(void)createVideoFromImages:(NSString *) path withSize:(CGSize) size 
{ 
    NSError *error = nil; 

    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: 
            [NSURL fileURLWithPath:path] fileType:AVFileTypeMPEG4 
                   error:&error]; 
    NSParameterAssert(videoWriter); 

    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
            AVVideoCodecH264, AVVideoCodecKey, 
            [NSNumber numberWithInt:size.width], AVVideoWidthKey, 
            [NSNumber numberWithInt:size.height], AVVideoHeightKey, 
            nil]; 


    AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput 
              assetWriterInputWithMediaType:AVMediaTypeVideo 
              outputSettings:videoSettings]; 

    AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor 
                assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput 
                sourcePixelBufferAttributes:nil]; 

    NSParameterAssert(videoWriterInput); 

    NSParameterAssert([videoWriter canAddInput:videoWriterInput]); 
    videoWriterInput.expectsMediaDataInRealTime = YES; 
    [videoWriter addInput:videoWriterInput]; 
    //Start a session: 
    [videoWriter startWriting]; 
    [videoWriter startSessionAtSourceTime:kCMTimeZero]; 

    //Video encoding 
    CVPixelBufferRef buffer = NULL; 

    //convert uiimage to CGImage. 
    int frameCount = 0; 

    for(int i = 0; i<[arrPicture count]; i++) 
    { 
     buffer = [self bufferImageFromCGImage:[[arrPicture objectAtIndex:i] CGImage] size:size]; 

     __block BOOL append_ok = NO; 
     int j = 0; 
     while (!append_ok && j < 30) 
     { 
      if (adaptor.assetWriterInput.readyForMoreMediaData) 
      { 
       printf("appending %d attemp %d\n", frameCount, j); 

       CMTime frameTime = CMTimeMake(frameCount,(int32_t)1); 
       append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:frameTime]; 

       // CVPixelBufferPoolRef bufferPool = adaptor.pixelBufferPool; 
       // NSParameterAssert(bufferPool != NULL); 
       [NSThread sleepForTimeInterval:0.05]; 

      } 
      else 
      { 
       printf("adaptor not ready %d, %d\n", frameCount, j); 
       [NSThread sleepForTimeInterval:0.1]; 
      } 
      j++; 
     } 
     if (!append_ok) 
     { 
      printf("error appending image %d times %d\n", frameCount, j); 
     } 
     frameCount++; 
     CVBufferRelease(buffer); 
    } 

    [videoWriterInput markAsFinished]; 
    [videoWriter finishWritingWithCompletionHandler:^{ 
     NSLog(@"Finished writing...checking completion status..."); 
     if (videoWriter.status != AVAssetWriterStatusFailed && videoWriter.status == AVAssetWriterStatusCompleted) 
     { 
      NSLog(@"Video writing succeeded."); 

      // Move video to camera roll 
      // NOTE: You cannot write directly to the camera roll. 
      // You must first write to an iOS directory then move it! 
      NSURL *videoTempURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@", path]]; 
     } else 
     { 
      NSLog(@"Video writing failed: %@", videoWriter.error); 
     } 
    }]; 
} 


-(CVPixelBufferRef) bufferImageFromCGImage:(CGImageRef)image size:(CGSize)size 
{ 
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
          [NSNumber numberWithBool:YES],  kCVPixelBufferCGImageCompatibilityKey, 
          [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey, 
          nil]; 
    CVPixelBufferRef pxbuffer = NULL; 
    CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, size.width, 
              size.height, kCVPixelFormatType_32ARGB, (__bridge CFDictionaryRef) options, 
              &pxbuffer); 
    status=status;//Added to make the stupid compiler not show a stupid warning. 
    NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL); 

    CVPixelBufferLockBaseAddress(pxbuffer, 0); 
    void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer); 
    NSParameterAssert(pxdata != NULL); 

    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef context = CGBitmapContextCreate(pxdata, size.width, 
               size.height, 8, 4*size.width, rgbColorSpace, 
               kCGImageAlphaNoneSkipFirst); 
    NSParameterAssert(context); 

    //CGContextTranslateCTM(context, 0, CGImageGetHeight(image)); 
    //CGContextScaleCTM(context, 1.0, -1.0);//Flip vertically to account for different origin 
    long width,height; 
    if (CGImageGetWidth(image) > self.view.frame.size.width) { 
     width = self.view.frame.size.width; 
    }else{ 
     width = self.view.frame.size.width; // CGImageGetWidth(image); 
    } 

    if (CGImageGetHeight(image) > self.view.frame.size.height) { 
     height = self.view.frame.size.height; 
    }else{ 
     height = self.view.frame.size.height -64 ;// CGImageGetHeight(image); 
    } 
    CGContextDrawImage(context, CGRectMake(0, 0, width, 
              height), image); 
    CGColorSpaceRelease(rgbColorSpace); 
    CGContextRelease(context); 

    CVPixelBufferUnlockBaseAddress(pxbuffer, 0); 

    return pxbuffer; 
} 
+0

क्या आपने इसे हल किया? मुझे जिन मुद्दों का सामना करना पड़ा .. –

+0

@ हितेश-नोप, फिर भी मुझे इसके लिए कोई समाधान नहीं मिला है। अगर आपको समाधान मिलेगा तो मुझे बताएं। –

+0

मुझे लगता है कि यह FFMPEG का उपयोग कर संभव है .. लेकिन मुझे इसके बारे में कोई और जानकारी नहीं है। http://stackoverflow.com/questions/17380033/how-to-include-ffmpeg-library-in-iphone-project –

उत्तर

0

यह संभव नहीं है अपने कोड का उपयोग कर छवि चेतन करने के लिए इनके द्वारा वीडियो

संसाधित करते समय लेकिन वहाँ एक विचार आप स्क्रीन रिकॉर्ड कर सकते हैं एनीमेशन स्क्रीन
012 रिकॉर्ड करने के लिए उपयोग इस कोड को खेलते समय एनिमेटेड छवियों

की वीडियो बनाने के लिए है

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

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