2013-09-01 5 views
3

GPUImage 위에 iOS에서 비디오 녹화를 구현하려고합니다.AVCaptureSession 이미지 크기 (GPUImage 사용)

은 내가 GPUImageVideoCamera을하고 난 다음과 같이 기록 설정하려고 :

-(void)toggleVideoRecording { 
if (!self.recording) { 
    self.recording = true; 
    GPUImageMovieWriter * mw = [self createMovieWriter: self.filter1]; 

    [self.filter1 addTarget:mw]; 
    mw.shouldPassthroughAudio = YES; 
    [mw startRecording]; 
} 
else { 
    self.recording = false; 
    [self finishWritingMovie]; 
} 

}

-(GPUImageMovieWriter *) createMovieWriter:(GPUImageFilter *) forFilter { 
    NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/CurrentMovie.m4v"]; 
    unlink([pathToMovie UTF8String]); 
    NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; 

    GPUImageMovieWriter * mw = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:forFilter->currentFilterSize]; 
    self.movieWriter = mw; 
    self.movieURL = movieURL; 

    return mw; 
} 

이 실제로 대부분 작동합니다. 그러나 MoviewWriter에는 입력 미디어의 CGSize가 필요하며 VideoCamera에서 가져 오는 방법을 모르겠습니다. 먼저 카메라가 sessionPreset : AVCaptureSessionPresetHigh를 사용하기 때문에 크기가 다양합니다. 이는 장치의 기능에 따라 달라진다는 것을 의미합니다. 둘째로 오리엔테이션은 관련 CGSize를 변경합니다. 사용자가 가로 모드로 녹화를 시작하면 치수를 조 변경하고 싶습니다.

바닐라 CoreVideo로이를 수행하는 방법을 알고있는 사람이라면 GPUImageVideoCamera에서 AVCaptureSession을 가져올 수 있습니다. (하지만 AVCaptureSession 용 API를 읽었으므로 유망한 것으로 보지 않았습니다.)

이 문제를 처리하는 샘플 프로젝트를 참조해도 도움이 될 것입니다.

답변

7

실제로 캡처 세션에서 치수를 가져올 수 있습니다. 방법은 다음과 같습니다.

// self.videoCamera is a GPUImageVideoCamera 

AVCaptureVideoDataOutput *output = [[[self.videoCamera captureSession] outputs] lastObject]; 
NSDictionary* outputSettings = [output videoSettings]; 

long width = [[outputSettings objectForKey:@"Width"] longValue]; 
long height = [[outputSettings objectForKey:@"Height"] longValue]; 

if (UIInterfaceOrientationIsPortrait([self.videoCamera outputImageOrientation])) { 
    long buf = width; 
    width = height; 
    height = buf; 
} 

GPUImageMovieWriter * mw = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(width, height)]; 
+0

답장을 보내 주셔서 감사합니다. 여기서 Xamarin을 사용하면 바인딩이 AVCapureVideoOutput.videoSettings를 래핑하므로 코드가 약간 다릅니다. 참조 용 샘플 코드 :'AVCaptureVideoDataOutput output = camera.CaptureSession.Outputs.OfType (). Last(); int h = output.UncompressedVideoSetting.Height ?? 0; int w = output.UncompressedVideoSetting.Width ?? 0; 만약 (h == 0 || w == 0) 새로운 InvalidOperationException을 던지면 ("캡처 세션에서 비디오 출력 크기를 가져 오지 못했습니다"), –