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
として画面を保存することができましたが、私が作成したものの映画を入手したいと思います。
私はRGBAデータを送信していると思いますが、間違っている可能性があります。私はAVAssetWriterInputPixelBufferAdaptorを使用しています。問題は、ピクセルバッファのプールを送信していないということです。私はそれをどうやってやるのか分からない。 – SnowJack
AVAssetWriterInputPixelBufferAdaptorを使用している場合は、質問を更新する必要があります。 –