2013-01-09 4 views
16

イメージmagickライブラリで指定されたイメージからビデオファイルを作成しようとしています。不透明度の違いのようにいくつかのエフェクトを1つずつ適用した後、正常に作成されますが、Quick time playerはエラー" video file could not be opened. The movie's file format isn't recognized "を返します。ムービーのファイル形式が認識されないためビデオファイルを開くことができませんでした

私は、次のコードを使用しています:

double d = 0.00; 

- (void)posterizeImageWithCompression:(id)sender { 

    // Here we use JPEG compression. 
    NSLog(@"we're using JPEG compression"); 

    MagickWandGenesis(); 
    magick_wand = NewMagickWand(); 
    magick_wand = [self magiWandWithImage:[UIImage imageNamed:@"iphone.png"]]; 

    MagickBooleanType status; 

    status = MagickSetImageOpacity(magick_wand, d); 

    if (status == MagickFalse) { 
     ThrowWandException(magick_wand); 
    } 
    if (status == MagickFalse) { 
     ThrowWandException(magick_wand); 
    } 
    size_t my_size; 
    unsigned char * my_image = MagickGetImageBlob(magick_wand, &my_size); 
    NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size]; 
    free(my_image); 
    magick_wand = DestroyMagickWand(magick_wand); 
    MagickWandTerminus(); 
    UIImage * image = [[UIImage alloc] initWithData:data]; 

    d = d + 0.05; 
    if (status == MagickFalse) { 
     ThrowWandException(magick_wand); 
    } 

    NSData *data1; 

    NSArray *paths; 

    NSString *documentsDirectory,*imagePath ; 

    UIImage *image1 = image; 

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    documentsDirectory = [paths objectAtIndex:0]; 

    imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%f.png",d]]; 

    data1 = UIImagePNGRepresentation(image1); 

    if (d <= 1.0) { 

     [data1 writeToFile:imagePath atomically:YES]; 

     [imageViewButton setImage:image forState:UIControlStateNormal]; 

     // If ready to have more media data 
     if (assetWriterPixelBufferAdaptor.assetWriterInput.readyForMoreMediaData) { 
      CVReturn cvErr = kCVReturnSuccess; 
      // get screenshot image! 
      CGImageRef image1 = (CGImageRef) image.CGImage; 

      // prepare the pixel buffer 
      CVPixelBufferRef pixelsBuffer = NULL; 

      // Lock pixel buffer address 
      CVPixelBufferLockBaseAddress(pixelsBuffer, 0); 

      // pixelsBuffer = [self pixelBufferFromCGImage:image1]; 

      CVPixelBufferUnlockBaseAddress(pixelsBuffer, 0); 

      CFDataRef imageData= CGDataProviderCopyData(CGImageGetDataProvider(image1)); 
      NSLog (@"copied image data"); 
      cvErr = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, 
                FRAME_WIDTH, 
                FRAME_HEIGHT, 
                kCVPixelFormatType_32BGRA, 
                (void*)CFDataGetBytePtr(imageData), 
                CGImageGetBytesPerRow(image1), 
                NULL, 
                NULL, 
                NULL, 
                &pixelsBuffer); 
      NSLog (@"CVPixelBufferCreateWithBytes returned %d", cvErr); 

      // calculate the time 
      CFAbsoluteTime thisFrameWallClockTime = CFAbsoluteTimeGetCurrent(); 
      CFTimeInterval elapsedTime = thisFrameWallClockTime - firstFrameWallClockTime; 
      NSLog (@"elapsedTime: %f", elapsedTime); 
      CMTime presentationTime = CMTimeMake (elapsedTime * TIME_SCALE, TIME_SCALE); 

      // write the sample 
      BOOL appended = [assetWriterPixelBufferAdaptor appendPixelBuffer:pixelsBuffer withPresentationTime:presentationTime]; 

      if (appended) { 
       NSLog (@"appended sample at time %lf", CMTimeGetSeconds(presentationTime)); 
      } else { 
       NSLog (@"failed to append"); 
       [self stopRecording]; 
      } 

      // Release pixel buffer 
      CVPixelBufferRelease(pixelsBuffer); 
      CFRelease(imageData); 
     } 
    } 


} 

、それはまたのようなエラーが表示さ...

VideoToolbox`vt_Copy_32BGRA_2vuyITU601 + 91 and 
VideoToolbox`vtPixelTransferSession_InvokeBlitter + 574 and 
VideoToolbox`VTPixelTransferSessionTransferImage + 14369 and 
VideoToolbox`VTCompressionSessionEncodeFrame + 1077 and 
MediaToolbox`sbp_vtcs_processSampleBuffer + 599 
+0

画像から動画を作成したいですか? –

+0

この機能でffmpegを試してみましたか? – Swati

+0

私はそれが間違ったpresentationTimeのためかもしれないと思う。 'TIME_SCALE'に与えられた価値と最終的なムービーがあると期待しているFPSは何ですか? – uchiha

答えて

1

QT Playerは非常に有益されていません。通常、プレイヤーは不足しているコーデックの名前を提供します。ファイルを生成し、それをQTで再生できなかったのと同じコンピュータ上でプログラムで再生した場合、何らかの理由でプログラムライブラリが明らかに見ることができるコーデックが使用されているため、OSに登録されていません。シェルでは、 "ファイル"を作成して、ファイルタイプと場合によってはコーデックを取得することができます。そうでない場合は、vlc、transcode、またはgstreamerでコーデックを見つけ、必要なコーデックをOSに直接ダウンロードしてインストールするためのAppleの指示に従ってください。

関連する問題