2011-11-10 11 views
0

OpenGLプロジェクトをスクリーンキャプチャするためにAVAssetWriterを作成しようとしています。私はAVAssetWriterまたはAVAssetWriterInputPixelBufferAdaptorを書いたことがないので、正しく動作したかどうかはわかりません。クラスのAVAssetWriterInputPixelBufferAdaptorへのOpenGLビューのキャプチャ

- (id) initWithOutputFileURL:(NSURL *)anOutputFileURL { 
    if ((self = [super init])) { 
     NSError *error; 
     movieWriter = [[AVAssetWriter alloc] initWithURL:anOutputFileURL fileType:AVFileTypeMPEG4 error:&error]; 
     NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
             AVVideoCodecH264, AVVideoCodecKey, 
             [NSNumber numberWithInt:640], AVVideoWidthKey, 
             [NSNumber numberWithInt:480], AVVideoHeightKey, 
             nil]; 
     writerInput = [[AVAssetWriterInput 
         assetWriterInputWithMediaType:AVMediaTypeVideo 
         outputSettings:videoSettings] retain]; 
     writer = [[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:writerInput sourcePixelBufferAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,nil]]; 

     [movieWriter addInput:writerInput]; 
     writerInput.expectsMediaDataInRealTime = YES; 
    } 

    return self; 
} 

その他のパーツ:assetwriterがによって開始され

- (void)getFrame:(CVPixelBufferRef)SampleBuffer:(int64_t)frame{ 
    frameNumber = frame; 
    [writer appendPixelBuffer:SampleBuffer withPresentationTime:CMTimeMake(frame, 24)]; 
} 

- (void)startRecording { 
    [movieWriter startWriting]; 
    [movieWriter startSessionAtSourceTime:kCMTimeZero]; 
} 

- (void)stopRecording { 
    [writerInput markAsFinished]; 
    [movieWriter endSessionAtSourceTime:CMTimeMake(frameNumber, 24)]; 
    [movieWriter finishWriting]; 
} 

glReadPixels(0, 0, 480, 320, GL_RGBA, GL_UNSIGNED_BYTE, buffer); 
    for(int y = 0; y <320; y++) { 
    for(int x = 0; x <480 * 4; x++) { 
     int b2 = ((320 - 1 - y) * 480 * 4 + x); 
     int b1 = (y * 4 * 480 + x); 
     buffer2[b2] = buffer[b1]; 
    } 
}  
pixelBuffer = NULL; 
CVPixelBufferCreateWithBytes (NULL,480,320,kCVPixelFormatType_32BGRA,buffer2,1920,NULL,0,NULL,&pixelBuffer); 
[recorder getFrame:pixelBuffer :framenumber]; 
    framenumber++; 

注:

NSURL *outputFileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]]; 
    recorder = [[GLRecorder alloc] initWithOutputFileURL:outputFileURL]; 

ビューはこのように記録されています

pixelBufferは、CVPixelBufferRefです。
framenumberは、int64_tです。
bufferおよびbuffer2は、GLubyteである。

私はエラーは発生しませんが、録音を完了するとファイルがありません。ヘルプやヘルプへのリンクがあれば、大いに感謝します。 OpenGLはカメラからのライブフィードを利用しています。私はUIImageとして画面を保存することができましたが、私が作成したものの映画を入手したいと思います。

答えて

0

RGBAフレームを作成する場合は、AVAssetWriterInputPixelBufferAdaptorを使用して書き込む必要があると思います。このクラスはピクセルバッファのプールを管理することになっていますが、実際にデータをYUVにマッサージしているという印象を受けます。

これがうまくいくと、色がすべてスワップされていることがわかると思います。ピクセルシェーダーを書いてBGRAに変換する必要があるかもしれません。あるいは、CPU上でそれをやります。あなた次第。

+0

私はRGBAデータを送信していると思いますが、間違っている可能性があります。私はAVAssetWriterInputPixelBufferAdaptorを使用しています。問題は、ピクセルバッファのプールを送信していないということです。私はそれをどうやってやるのか分からない。 – SnowJack

+0

AVAssetWriterInputPixelBufferAdaptorを使用している場合は、質問を更新する必要があります。 –

0

ここで答えが見つかりました:Saving to library 私は決してビデオをcarmeraロールに保存しませんでした。

カメラロールで作成されたファイルの名前を変更するために時間を費やさなければならなかったので、常にそれ自体を保存したり、同じファイルを何度も何度も保存したりしませんでした。

関連する問題