0

参考链接,我正在尝试在 OpenGL 中渲染视频。但我得到的是黑屏而不是视频帧。以下是我调用渲染视频的方法。

 NSURL * url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"intro_i-phone" ofType:@"mp4"]];
        mAsset = [[AVURLAsset alloc] initWithURL:url options:NULL];

        NSArray * tracks = [mAsset tracksWithMediaType:AVMediaTypeVideo];

        mTrack = [tracks objectAtIndex:0];

        NSLog(@"Tracks: %i", [tracks count]);

        NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
        NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
        NSDictionary * settings = [[NSDictionary alloc] initWithObjectsAndKeys:value, key, nil];

        mOutput = [[AVAssetReaderTrackOutput alloc]
                   initWithTrack:mTrack outputSettings:settings];

        mReader = [[AVAssetReader alloc] initWithAsset:mAsset error:nil];
        [mReader addOutput:mOutput];
        [mReader startReading];

        CMSampleBufferRef sampleBuffer = [mOutput copyNextSampleBuffer];
        CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
        CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

        glGenTextures(1,&tID);
        glBindTexture(GL_TEXTURE_2D, tID);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 100, 100, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(pixelBuffer));
        CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );
        CFRelease(sampleBuffer);

谁能弄清楚我做错了什么?谢谢

4

0 回答 0