gpt4 book ai didi

ios - 由于无法识别电影文件格式,无法打开视频文件

转载 作者:IT王子 更新时间:2023-10-29 08:16:37 24 4
gpt4 key购买 nike

我正在尝试根据 image magick 库提供的图像创建视频文件。一个一个地应用一些效果后,如不透明度差异,创建成功但 Quick time player 给出错误 “视频文件无法打开。电影的文件格式无法识别”.

我正在使用以下代码:

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

最佳答案

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

关于ios - 由于无法识别电影文件格式,无法打开视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14230825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com