2011-03-04 4 views
3

다음 코드를 사용하여 배열 (takenImages)에 저장된 이미지 시퀀스에서 비디오를 만듭니다. 지속 시간은 프레임 지속 시간 (초)입니다.avfoundation : appendPixelBuffer withPresentationTime, 어댑터가 준비되지 않았습니다.

모든 것이 라이브러리에 저장됩니다.

내 문제는 디버거를 사용하여 실행하면 비디오가 완벽하게 저장되지만 디버거없이 실행하면 비디오가 완전히 저장되지 않는다는 것입니다. 첫 번째 프레임 만 저장되었습니다.

appending 0 attemp 0 
appending 1 attemp 0 
adaptor not ready 2, 0 
adaptor not ready 2, 1 
adaptor not ready 2, 2 
adaptor not ready 2, 3 
adaptor not ready 2, 4 
adaptor not ready 2, 5 
adaptor not ready 2, 6 
adaptor not ready 2, 7 
adaptor not ready 2, 8 
adaptor not ready 2, 9 
adaptor not ready 2, 10 
adaptor not ready 2, 11 
adaptor not ready 2, 12 
adaptor not ready 2, 13 
adaptor not ready 2, 14 
adaptor not ready 2, 15 
adaptor not ready 2, 16 
adaptor not ready 2, 17 
adaptor not ready 2, 18 
adaptor not ready 2, 19 
adaptor not ready 2, 20 
adaptor not ready 2, 21 
adaptor not ready 2, 22 
adaptor not ready 2, 23 
adaptor not ready 2, 24 
adaptor not ready 2, 25 
adaptor not ready 2, 26 
adaptor not ready 2, 27 
adaptor not ready 2, 28 
adaptor not ready 2, 29 
error appending image 2 times 30 
adaptor not ready 3, 0 
adaptor not ready 3, 1 
adaptor not ready 3, 2 
adaptor not ready 3, 3 
adaptor not ready 3, 4 
adaptor not ready 3, 5 
adaptor not ready 3, 6 
adaptor not ready 3, 7 
adaptor not ready 3, 8 
adaptor not ready 3, 9 
adaptor not ready 3, 10 
adaptor not ready 3, 11 
adaptor not ready 3, 12 
adaptor not ready 3, 13 
adaptor not ready 3, 14 
adaptor not ready 3, 15 
adaptor not ready 3, 16 
adaptor not ready 3, 17 
adaptor not ready 3, 18 
adaptor not ready 3, 19 
adaptor not ready 3, 20 
adaptor not ready 3, 21 
adaptor not ready 3, 22 
adaptor not ready 3, 23 
adaptor not ready 3, 24 
adaptor not ready 3, 25 
adaptor not ready 3, 26 
adaptor not ready 3, 27 
adaptor not ready 3, 28 
adaptor not ready 3, 29 
error appending image 3 times 30 
adaptor not ready 4, 0 
adaptor not ready 4, 1 
adaptor not ready 4, 2 
adaptor not ready 4, 3 
adaptor not ready 4, 4 
adaptor not ready 4, 5 
adaptor not ready 4, 6 
adaptor not ready 4, 7 
adaptor not ready 4, 8 
adaptor not ready 4, 9 
adaptor not ready 4, 10 
adaptor not ready 4, 11 
adaptor not ready 4, 12 
adaptor not ready 4, 13 
adaptor not ready 4, 14 
adaptor not ready 4, 15 
adaptor not ready 4, 16 
adaptor not ready 4, 17 
adaptor not ready 4, 18 
adaptor not ready 4, 19 
adaptor not ready 4, 20 
adaptor not ready 4, 21 
adaptor not ready 4, 22 
adaptor not ready 4, 23 
adaptor not ready 4, 24 
adaptor not ready 4, 25 
adaptor not ready 4, 26 
adaptor not ready 4, 27 
adaptor not ready 4, 28 
adaptor not ready 4, 29 
error appending image 4 times 30 

어떤 제안 :

int timescale = duration * [takenImages count]; 

    for (int i = 0; i < [takenImages count]; i++) { 
     CVPixelBufferRef buffer = NULL; 

     buffer = [self pixelBufferFromCGImage:[[takenImages objectAtIndex:i] CGImage]]; 

     BOOL append_ok = NO; 
     int j = 0; 
     while (!append_ok && j < 30) { 
      if (adaptor.assetWriterInput.readyForMoreMediaData) { 
       printf("appending %d attemp %d\n", i, j); 
       append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(i*duration,timescale)]; 
      } else { 
       printf("adaptor not ready %d, %d\n", i, j); 
       [NSThread sleepForTimeInterval:0.1]; 
      } 
      j++; 
     } 

     if (!append_ok) { 
      printf("error appending image %d times %d\n", i, j); 
     } 

    } 

이 (디버거를) 실행 후 내가 콘솔이 무엇인지의 예입니다?

미리 감사드립니다.

바이
마소

답변

1

writerInput.expectsMediaDataInRealTime = YES;

+0

감사합니다.이 설명서를 추가했는데 (설명서도 확인했는데 제 경우에는 분명히 필요합니다) 결과가 하나 더 추가되었습니다. 어댑터가 다시 준비되지 않습니다. – Tommaso

5

버퍼를 설정할 때이 방법을 사용하십시오.

[adaptor appendPixelBuffer:buffer withPresentationTime:presentTime]; 
if(buffer) 
    CVBufferRelease(buffer); 
[NSThread sleepForTimeInterval:0.05]; 
+0

Jeff에게 감사드립니다. 작동합니다! 모든 이미지는 첫 번째 시도에서 추가되었습니다! – Tommaso

+1

왜 작동합니까? – Praxiteles

+0

나에게 꼭 맞는 작업 :) –

1

당신의 writerInput 객체에 requestMediaDataWhenReadyOnQueue:usingBlock:를 사용하는 것이 더 적절하다. 다시 입력 할 준비가되면 블록을 다시 호출합니다.

+1

아직도 제대로 작동하려면 잠을 사용해야했습니다. 무서운. –

-1

루프 내부의 코드에 @autoreleasepool을 사용하십시오. 이렇게하면 루프가 끝날 때까지 모든 루프를 해제하는 대신 각 루프 내의 사용하지 않는 메모리가 해제됩니다.

+0

이 고려 사항은 의견 섹션에 더 좋습니다. – AlexeyVMP

관련 문제