2011-10-12 4 views
1

Mac 용 라이브 비디오 스트리밍을 만드는 응용 프로그램을 만들려고합니다. 나는 VLC와 다른 솔루션에 대해서 알고있다.QTKit, 실시간 스트리밍 용 비디오 캡처

끝으로 나는 QTKit을 사용하여 iSight에서 비디오를 녹화하려고 시도하고 있으며 일련의 작은 비디오 파일로 계속 저장하려고합니다. 그러나 녹음 내용은 파일 사이에 간격이있어 아주 연속적이지 않습니다.

기본적으로 타이머를 설정하기 만하면 특정 시간 간격으로 새 파일에 녹음을 시작하여 이전 녹음을 중지합니다. 또한 최대 녹음 길이를 설정하고 대리자 메서드를 사용하여 시도 ... didFinishRecording ... 및 ... willFinishRecording ... 같은 결과 (나는 이러한 경우의 차이를 실제로 견적 수 없습니다.).

이러한 작업을 어떻게 수행해야하는지 알고 계시다면 도와주십시오.

 
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
    QTCaptureSession *session = [[QTCaptureSession alloc] init]; 
    QTCaptureDevice *iSight = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo]; 
    [iSight open:nil]; 
    QTCaptureDeviceInput *myInput = [QTCaptureDeviceInput deviceInputWithDevice:iSight]; 
    output = [[QTCaptureMovieFileOutput alloc] init] ; //ivar, QTCaptureFileOutput 
    [output setDelegate:self]; 
    a = 0; //ivar, int 
    fileName = @"/Users/dtv/filerecording_"; //ivar, NSString 
    [session addOutput:output error:nil]; 
    [session addInput:myInput error:nil]; 
    [capview setCaptureSession:session]; //IBOutlet 
    [session startRunning]; 
    [output setCompressionOptions:[QTCompressionOptions compressionOptionsWithIdentifier:@"QTCompressionOptionsSD480SizeH264Video"] forConnection:[[output connections] objectAtIndex:0]]; 
    [output recordToOutputFileURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@%i.mov", fileName, a]] bufferDestination:QTCaptureFileOutputBufferDestinationOldFile]; 
    NSTimer *tmr = [NSTimer timerWithTimeInterval:5 target:self selector:@selector(getMovieLength:) userInfo:nil repeats:YES]; 
    [[NSRunLoop currentRunLoop] addTimer:tmr forMode:NSDefaultRunLoopMode]; 
}

‐ (void) getMovieLength:(NSTimer *) t { a++; [output recordToOutputFileURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@%i.mov", fileName, a]] bufferDestination:QTCaptureFileOutputBufferDestinationOldFile]; }

답변

2

브레이크 기본 메커니즘은 조각으로 촬영 된 영화가 있습니다 :

여기에 내 현재 코드입니다. 파일 크기 제한을 지정하기 위해 작품의 기간 또는

[QTCaptureFileOutput setMaximumRecordedFileSize:] 

을 지정

[QTCaptureFileOutput setMaximumRecordedDuration:] 

를 사용합니다. 이것은 당신이 조각을 절단 할 수

[QTCaptureFileOutput recordToOutputFileURL:] 

: 새 파일 이름을 설정할 수있는이 방법

[QTCaptureFileOutput_Delegate captureOutput: shouldChangeOutputFileAtURL: forConnections: dueToError:] 

: 한도는 대리자 메서드 호출할지에 도달

기록 된 영화의

[QTCaptureFileOutput_Delegate captureOutput : didFinishRecordingToOutputFileAtURL : forConnections : dueToError :]는 파일에 대한 레코딩이 실제로 완료된 후 조금 후에 호출됩니다. 이 방법을 사용하여 새 파일을 설정하면 최종 비디오에 간격이 생깁니다. 이 방법을 사용할 필요가 없다는 것을 의미하지는 않습니다. 이 방법은 영화의 일부가 사용될 준비가되었을 때 표시됩니다. 당신이 더 절단 정확한 필요한 경우

새 조각으로 녹음을 시작 할 때 정확한 영화 프레임을 지정

[QTCaptureFileOutput captureOutput: didOutputSampleBuffer: fromConnection:] 

를 사용할 수 있습니다. 그러나이 방법으로 작업하려면보다 구체적인 지식이 필요합니다.

+0

감사합니다. 불행히도 아직 확인할 수 없습니다. 확인할 수있는대로 받아 들일 것입니다. – Ibolit

+0

감사합니다. 이전보다 훨씬 부드럽게 작동합니다. 하지만 여전히 부드럽지는 않습니다. 당신이 언급 한 그 "더 구체적인 지식"은 무엇입니까? 내가 어디에서 찾을 수 있는지 말해 줄래? 감사합니다, Timofey. – Ibolit

+0

완전히 부드럽지 않다는 것은 무엇을 의미합니까? 그것은 잘 작동해야합니다. 좀 더 구체적인 지식이 필요하다고 말했을 때, 나는 당신이 퀵타임을 파는 데 얼마나 깊은 지 알지 못했습니다. 대부분의 경우 방법 I은 캡처 된 영화를 여러 조각으로 나누기에 충분하다고 설명합니다.그러나, 하나의 프레임으로 더 정확하게 잘라내기를 원한다면'[QTCaptureFileOutput captureOutput : didOutputSampleBuffer : fromConnection :]'메소드를 사용할 수 있습니다. 이 경우 버퍼에서 데이터를 가져 와서 분석해야합니다. 특별한 것은 없지만 문서에서 거의 모든 것을 얻을 수 있습니다. – Davyd

관련 문제