2016-09-08 1 views
1

iOSでは、カメラロールからビデオを再生したいと思っています。多くの理由から、各フレームでOpenGLの処理を行う必要があります。ビデオカメラから来てではなく、カメラロールここカメラロールのビデオからGL_LUMINANCEは取得できますが、GL_LUMINANCE_ALPHAは取得できないのはなぜですか?

からの映像から必要最低限​​を維持しようと、コードのとき

私のコードは動作します。 ^動作しません。ここに

// Creating _textureCache 
CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, _glContext, NULL, &_textureCache); 

// Reading the video track 
NSDictionary *settings = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}; 
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo]; 
_assetReaderTrackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTracks.firstObject outputSettings:settings]; 
NSError *assetReaderCreationError; 
_assetReader = [[AVAssetReader alloc] initWithAsset:asset error:&assetReaderCreationError]; 
[_assetReader addOutput:_assetReaderTrackOutput]; 
[_assetReader startReading]; 

フレームごと(タイマーベース)

if (_assetReader.status == AVAssetReaderStatusReading) { 
    sampleBuffer = [_assetReaderTrackOutput copyNextSampleBuffer]; 
    CVImageBufferRef cameraFrame = CMSampleBufferGetImageBuffer(sampleBuffer); 

    // This works 
    CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, _textureCache, cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE, bufferWidth, bufferHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); 

    // This doesn't work (err 6833) 
    CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, _textureCache, cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, bufferWidth, bufferHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &luminanceTextureRef); 

最後の行:ユーザーの後AVAssetReaderTrackOutput_textureCacheの設定

は、カメラロールからビデオを選択します。私はエラー6833を取得します。私はこれを発見したCVOpenGLESTextureCacheCreateTextureFromImage returns error 6683しかし、それ以上取得することはできません。

私は別の設定を試しましたが(kCVPixelFormatType_32BGRAを他の列挙型に置き換えて)、どこにでも置くことはできません。どんな助け?

EDIT:

frame <CVPixelBuffer 0x1565796b0 width=720 height=1280 bytesPerRow=2880 pixelFormat=BGRA iosurface=0x158300048 attributes=<CFBasicHash 0x156578a40 [0x1a115e150]>{type = immutable dict, count = 1, 
entries => 
    0 : <CFString 0x19ca7fca8 [0x1a115e150]>{contents = "PixelFormatDescription"} = <CFBasicHash 0x156551460 [0x1a115e150]>{type = immutable dict, count = 15, 
entries => 
    1 : <CFString 0x19ca7fae8 [0x1a115e150]>{contents = "CGImageCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    2 : <CFString 0x19ca801a8 [0x1a115e150]>{contents = "FillExtendedPixelsCallback"} = <CFData 0x156569340 [0x1a115e150]>{length = 24, capacity = 24, bytes = 0x0000000000000000484e1f85010000000000000000000000} 
    5 : <CFString 0x19ca7fee8 [0x1a115e150]>{contents = "ContainsAlpha"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    6 : <CFString 0x19ca7fac8 [0x1a115e150]>{contents = "CGBitmapContextCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    7 : <CFString 0x19ca7ffa8 [0x1a115e150]>{contents = "BitsPerBlock"} = <CFNumber 0xb000000000000202 [0x1a115e150]>{value = +32, type = kCFNumberSInt32Type} 
    8 : <CFString 0x19ca7ffc8 [0x1a115e150]>{contents = "BlackBlock"} = <CFData 0x156568660 [0x1a115e150]>{length = 4, capacity = 4, bytes = 0x000000ff} 
    9 : <CFString 0x19ca7fbc8 [0x1a115e150]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    10 : <CFString 0x19ca7fc08 [0x1a115e150]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    11 : <CFString 0x19ca80088 [0x1a115e150]>{contents = "CGBitmapInfo"} = <CFNumber 0xb000000000020042 [0x1a115e150]>{value = +8196, type = kCFNumberSInt32Type} 
    12 : <CFString 0x19ca7fba8 [0x1a115e150]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    13 : <CFString 0x19ca7fbe8 [0x1a115e150]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
    14 : <CFString 0x19ca800a8 [0x1a115e150]>{contents = "ContainsYCbCr"} = <CFBoolean 0x1a115e6d8 [0x1a115e150]>{value = false} 
    15 : <CFString 0x19ca7fe88 [0x1a115e150]>{contents = "PixelFormat"} = <CFNumber 0xb000000424752412 [0x1a115e150]>{value = +1111970369, type = kCFNumberSInt32Type} 
    16 : <CFString 0x19ca80108 [0x1a115e150]>{contents = "ComponentRange"} = <CFString 0x19ca80148 [0x1a115e150]>{contents = "FullRange"} 
    21 : <CFString 0x19ca800c8 [0x1a115e150]>{contents = "ContainsRGB"} = <CFBoolean 0x1a115e6c8 [0x1a115e150]>{value = true} 
} 

} 
propagatedAttachments=<CFBasicHash 0x156579910 [0x1a115e150]>{type = mutable dict, count = 5, 
entries => 
    0 : <CFString 0x19ca7f688 [0x1a115e150]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x19ca7f6c8 [0x1a115e150]>{contents = "ITU_R_601_4"} 
    1 : <CFString 0x19ca7f7e8 [0x1a115e150]>{contents = "CVImageBufferTransferFunction"} = <CFString 0x19ca7f6a8 [0x1a115e150]>{contents = "ITU_R_709_2"} 
    2 : <CFString 0x19cab2690 [0x1a115e150]>{contents = "MetadataDictionary"} = <CFBasicHash 0x15654c060 [0x1a115e150]>{type = mutable dict, count = 3, 
entries => 
    0 : <CFString 0x19cab9970 [0x1a115e150]>{contents = "SNR"} = <CFNumber 0x156515ad0 [0x1a115e150]>{value = +20.18363643733977141892, type = kCFNumberFloat64Type} 
    1 : <CFString 0x19cab7cb0 [0x1a115e150]>{contents = "ExposureTime"} = <CFNumber 0x1565623b0 [0x1a115e150]>{value = +0.01000000000000000021, type = kCFNumberFloat64Type} 
    2 : <CFString 0x19cab9950 [0x1a115e150]>{contents = "SensorID"} = <CFNumber 0xb000000000002372 [0x1a115e150]>{value = +567, type = kCFNumberSInt32Type} 
} 

    5 : <CFString 0x19ca7f768 [0x1a115e150]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x19ca7f6a8 [0x1a115e150]>{contents = "ITU_R_709_2"} 
    6 : <CFString 0x19ca7f828 [0x1a115e150]>{contents = "CVImageBufferChromaLocationTopField"} = <CFString 0x19ca7f888 [0x1a115e150]>{contents = "Center"} 
} 
nonPropagatedAttachments=<CFBasicHash 0x1565798d0 [0x1a115e150]>{type = mutable dict, count = 0, 
entries => 
} 
> 
Failed to create IOSurface image (texture) 
+0

あなたは 'NSLog(@ frame:%@"、cameraFrame);をカメラとファイルの両方のフレームにつけて出力をあなたの質問に追加できますか? –

答えて

1

あなたのAVAssetReaderTrackOutput outputOptionsためkCVPixelFormatType_420YpCbCr8BiPlanarVideoRangeまたはkCVPixelFormatType_420YpCbCr8BiPlanarFullRangeのいずれかを使用する必要があります。

これもデバイスで試してみます。シミュレータはこれらのフォーマットをサポートするために使用されていませんが、変更されている可能性があります。

+1

kCVPixelFormatType_420YpCbCr8BiPlanarFullRangeは正常に機能します。 – Thomas

関連する問題