我正在尝试使用 image magick 库提供的图像创建视频文件。在逐渐应用一些效果(如不透明度差异)之后,它会成功创建,但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)
QT播放器的信息量不大。通常,玩家将提供丢失的编解码器的名称。如果您生成文件并在同一台计算机上以QT播放不成功的方式进行编程,那么,无论出于何种原因,程序库显然可以看到的编解码器(因为它使用它)未在操作系统中注册。在shell中,你可以做一个&#34;文件&#34;并获取文件类型和可能的编解码器。如果没有,您应该能够找到带有vlc,转码或gstreamer的编解码器,然后按照Apple的说明将所需的编解码器直接下载并安装到操作系统中。