gpt4 book ai didi

c - 由电影支持的 QTMovie 最初可以工作,但不能以其他方法工作

转载 作者:行者123 更新时间:2023-11-30 16:04:23 25 4
gpt4 key购买 nike

接下来是一个初始化方法。它从文件创建电影结构,着眼于提取原始像素进行处理,如 Apple QA1443 所示。 。然后将其包装在 QTMovie 中 – sourceMovie = [QTMovie movieWithQuickTimeMovie: ...] – 为了方便起见。

初始化这样一个对象后,调用第二个方法,我们尝试使用sourceMovie。然而,事实证明,任何尝试访问这里的 sourceMovie 都会导致 EXC_BAD_ACCESS 例如,NSLog(@"%@", sourceMovie) 是不可能的。这部电影似乎已被取消分配,但原因尚不清楚。

此外,在第二种方法中,获取 CVPixelBufferRef 的常用方法无法正常运行:QTVisualContextIsNewImageAvailable 似乎总是返回 NO,而 QTVisualContextCopyImageForTime 总是为您提供指向 0x00 的 imageBuffer。 (我想如果 QTMovie、Movie 或 VisualContext 以某种方式被释放,这并不奇怪。)

接下来的问题是,为什么第二种方法无法访问 sourceMovie ?它是否像看起来那样被取消分配?如果是这样,为什么?

现在是代码,对于长度,提前表示歉意。

// From the .h, we have the following inst var declarations:
Movie myMovie;
QTMovie *sourceMovie;
QTVisualContextRef visualContext;
CVPixelBufferRef imageBuffer;
pixels_xy sourceSize;
MovieAnalyzer *analyzer;

// And now to the @implementation...

-(id)initWithFileString:(NSString *)file {
if (self = [super init]) {
NSError *e;

// Bit of a hack - get the movie size using temporary QTMovie.
sourceMovie = [QTMovie movieWithFile:file error:&e];
if (e) {
[self release];
NSLog(@"Could not open movie.");
return nil;
}

NSSize movieSize = [[sourceMovie posterImage] size];
CGRect bounds = CGRectMake(0, 0, movieSize.width, movieSize.height);

// Save the size in pixels.
sourceSize.x = (int)movieSize.width, sourceSize.y = (int)movieSize.height;

CFStringRef movieLocation = (CFStringRef) file;

// Get a QT Visual Context, and create a movie inialized to use it for output.
visualContext = NULL;
OSStatus status = CreatePixelBufferContext(k32ARGBPixelFormat, &bounds, &visualContext);
if (noErr != status && NULL == visualContext) {
[self release];
NSLog(@"Problem initializing QT Visual Context.");
return nil;
}

/*** Instantiate the Movie ***/
myMovie = NULL;
Boolean trueValue = true;
QTNewMoviePropertyElement newMovieProperties[3] = {0};

// Setup movie location
newMovieProperties[0].propClass = kQTPropertyClass_DataLocation;
newMovieProperties[0].propID = kQTDataLocationPropertyID_CFStringPosixPath;
newMovieProperties[0].propValueSize = sizeof(CFStringRef);
newMovieProperties[0].propValueAddress = &movieLocation;

// Assign the visual context - could also be NULL
newMovieProperties[1].propClass = kQTPropertyClass_Context;
newMovieProperties[1].propID = kQTContextPropertyID_VisualContext;
newMovieProperties[1].propValueSize = sizeof(visualContext);
newMovieProperties[1].propValueAddress = &visualContext;

// Make the movie active
newMovieProperties[2].propClass = kQTPropertyClass_NewMovieProperty;
newMovieProperties[2].propID = kQTNewMoviePropertyID_Active;
newMovieProperties[2].propValueSize = sizeof(trueValue);
newMovieProperties[2].propValueAddress = &trueValue;

status = NewMovieFromProperties(3, newMovieProperties, 0, NULL, &myMovie);
if (status != noErr || myMovie == NULL) {
NSLog(@"Problem initializing theMovie"); // problem
[self release];
return nil;
}

// Create a new QTMovie with the Movie as its backing object
sourceMovie = [QTMovie movieWithQuickTimeMovie:myMovie disposeWhenDone:NO error:&e];
if (e) {
NSLog(@"Could not initialize QTMovie from Movie.");
[self release];
return nil;
}

[sourceMovie stepForward];
analyzer = [[MovieAnalyzer alloc] initWithColorString:"BGRA" andSourceSize:sourceSize];
}
return self;
}


-(NSImage*) supplyCalibrationImage {
NSLog(@"%x", &sourceMovie);

[sourceMovie stepForward]; // This fails!
....
}

最佳答案

[QTMovie movieWithQuickTimeMovie:disposeWhenDone:error:] 正在返回自动发布的影片。如果您希望它在该方法之后继续存在,则需要保留它。

关于c - 由电影支持的 QTMovie 最初可以工作,但不能以其他方法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3153476/

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