代码之家  ›  专栏  ›  技术社区  ›  Benji XVI

一部电影支持的QTMovie最初起作用,但在另一种方法中不起作用

  •  0
  • Benji XVI  · 技术社区  · 15 年前

    Apple QA1443 . 这是包装在一部电影 sourceMovie = [QTMovie movieWithQuickTimeMovie: ...] 为了方便。

    sourceMovie . 然而,事实证明 有人试图在这里访问sourceMovie吗 NSLog(@"%@", sourceMovie) 这是不可能的。这部电影似乎被取消了发行权,尽管还不清楚原因。

    此外,在第二种方法中,获取CVPixelBufferRef的常用方法不能正常工作:QTVisualContextIsNewImageAvailable似乎总是返回NO,而QTVisualContextCopyImageForTime总是给您一个指向0x00的imageBuffer(如果qtmoine、Movie或visualContext以某种方式被释放,我想这并不奇怪。)

    那么问题是,为什么 源电影 第二种方法无法访问?是不是像看上去的那样被取消分配了?如果是,为什么?

    现在是密码了,我提前为长度道歉。

    // 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!
        ....
    }
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   JWWalker    15 年前

    [QTMovie movieWithQuickTimeMovie:disposeWhenDone:error:]