23

我正在尝试从图像魔术库提供的图像创建视频文件。像不透明度差异一样一一应用一些效果后,它已成功创建,但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
4

1 回答 1

0

QT Player 的信息量不是很大。通常,玩家会提供丢失的编解码器的名称。如果您生成该文件并在同一台计算机上以编程方式播放它,而您在 QT 播放它时不成功,那么,无论出于何种原因,程序库显然可以看到的编解码器(因为它使用了它)未在操作系统中注册。在 shell 中,您可以执行“文件”并获取文件类型以及可能的编解码器。如果没有,您应该能够使用 vlc、transcode 或 gstreamer 找到编解码器,然后按照 Apple 的说明将所需的编解码器直接下载并安装到操作系统中。

于 2017-01-20T06:33:20.340 回答