2016-12-16 4 views
1

AVAssetWriterVideoInput을 사용하여 파일에 버퍼를 추가하고 있습니다.AVAssetWriterVideoInput을 사용하여 비디오 파일에 프레임을 추가하지 못했습니다. 끝 부분에 문서화되지 않은 오류 -12738이 발생합니다.

if (_assetWriter.status == AVAssetWriterStatusWriting) { 
    // If the asset writer status is writing, append sample buffer to its corresponding asset writer input 
    if (mediaType == AVMediaTypeVideo) { 
     if (_assetWriterVideoInput.readyForMoreMediaData) { 
     if (![_assetWriterVideoInput appendSampleBuffer:sampleBuffer]) { 
      NSLog(@"error: %@", [_assetWriter.error localizedFailureReason]); 
      NSLog(@"error: %@", [_assetWriter.error localizedRecoveryOptions]); 
      NSLog(@"error: %@", [_assetWriter.error localizedDescription]); 
      NSLog(@"error: %@", [_assetWriter.error domain]); 
      NSLog(@"error: %@", [_assetWriter.error userInfo]); 
     } else 
      NSLog(@"frame saved"); 
     } 
    } 

모든 사과 문서 예상대로, 분명, 어떤 documentation에 발견되지

if (![_assetWriterVideoInput appendSampleBuffer:sampleBuffer]) { 

unknown error 코드 -12738 실패이 라인 :이 코드가 있습니다.

또한 AVFoundation 내에 알려지지 않은 오류에 대한 코드가 많고 시스템이 -12738 코드를 선택하는 경우 알 수없는 것보다 더 많이 알 수 있다는 간단한 이유 때문에 알 수없는 오류라고 의심됩니다.

저장되는 파일을 보면 버퍼/프레임이 저장되지 않기 때문에 0 메가 바이트가 유지됩니다.

AVAssetWriterVideoInput

은 다음과 같이 작성 :이 추가됩니다

CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(currentFormatDescription); 
    NSUInteger numPixels = dimensions.width * dimensions.height; 
    NSUInteger bitsPerSecond; 

    // Assume that lower-than-SD resolutions are intended for streaming, and use a lower bitrate 
    NSUInteger bitsPerPixel = 11.4; // This bitrate matches the quality produced by AVCaptureSessionPresetHigh. 

    bitsPerSecond = numPixels * bitsPerPixel; 

    NSDictionary *videoCompressionSettings = @{AVVideoCodecKey     : AVVideoCodecH264, 
              AVVideoWidthKey     : @(dimensions.width), 
              AVVideoHeightKey     : @(dimensions.height), 
              AVVideoCompressionPropertiesKey : @{ AVVideoAverageBitRateKey  : @(bitsPerSecond), 
                        AVVideoMaxKeyFrameIntervalKey : @(30)} }; 

    if ([_assetWriter canApplyOutputSettings:videoCompressionSettings forMediaType:AVMediaTypeVideo]) 
    { 
    // Intialize asset writer video input with the above created settings dictionary 
    _assetWriterVideoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoCompressionSettings]; 
    _assetWriterVideoInput.expectsMediaDataInRealTime = YES; 

버퍼는, 다음과 같은 특징이 있습니다 :

CMSampleBuffer 0x1009e12a0 retainCount: 1 allocator: 0x1b762cbb8 
    invalid = NO 
    dataReady = YES 
    makeDataReadyCallback = 0x0 
    makeDataReadyRefcon = 0x0 
    formatDescription = <CMVideoFormatDescription 0x[0x1b762cbb8]> { 
    mediaType:'vide' 
    mediaSubType:'BGRA' 
    mediaSpecific: { 
     codecType: 'BGRA'  dimensions: 1920 x 1080 
    } 
    extensions: {<CFBasicHash 0x17087c2c0 [0x1b762cbb8]>{type = immutable dict, count = 2, 
entries => 
    0 : <CFString 0x1b1c6d460 [0x1b762cbb8]>{contents = "Version"} = <CFNumber 0xb000000000000022 [0x1b762cbb8]>{value = +2, type = kCFNumberSInt32Type} 
    2 : <CFString 0x1b1c6d3e0 [0x1b762cbb8]>{contents = "CVBytesPerRow"} = <CFNumber 0xb00000000001e002 [0x1b762cbb8]>{value = +7680, type = kCFNumberSInt32Type} 
} 
} 
} 
    sbufToTrackReadiness = 0x0 
    numSamples = 1 
    sampleTimingArray[1] = { 
     {PTS = {290309939228910/1000000000 = 290309.939}, DTS = {INVALID}, duration = {INVALID}}, 
    } 
    imageBuffer = 0x170321180 

I have a sample code here 문제를 선택하십시오. 이 코드는 4K로 비디오를 촬영할 준비가되어 있습니다. 장치가 그것을 할 수없는 경우 라인 AVCaptureSessionPreset3840x2160을 AVCaptureSessionPresetHigh inside ProcessadorVideo.m`로 변경하십시오. 샘플 코드는 비디오 스트림에서 사각형을 자르고 만화 효과를 적용합니다. 감사합니다.

+0

'startSessionAtSourceTime'을 (를) 호출 하시겠습니까? –

+0

다른 질문 (http://stackoverflow.com/a/41207678/22147)과 비슷한 문제입니까? –

+0

지연 응답을 위해 미안 : 아니오. 그것을 시도했다. 문제가 지속됩니다. – SpaceDog

답변

1

샘플을 시도했지만 오류 -12783을 재현 할 수 없습니다. 그러나 또 다른 오류 -12780이 있습니다. 나는 그것 때문에 아이폰 6s를 잘 모르겠다.

어쨌든 -12780 오류를 수정할 수 있습니다. 오래된 타임 스탬프로 인해이 문제가 발생했습니다. 디버깅 목적으로 앱에 몇 가지 로그를 추가했습니다. 00 : 35.809590 NotWriting [16,829 : 3,116,125] 401051199680,537 2017년 1월 26일 15에서 시작 : 00 : 35.809986 NotWriting [16,829을 : 3,116,125] 타임 스탬프 부가 비디오 버퍼 401051199680,537 2,017

2017년 1월 26일 15 이하 참조 -01-26 15 : 00 : 35.810008 NotWriting [16829 : 3116125] presentationTimeStamp가 마지막 프레임 타임 스탬프보다 작으므로 실패 할 수 있습니다. 2017-01-26 15 : 00 : 35.815605 NotWriting [16829 : 3116125] 오류 : 알 수없는 오류가 발생했습니다. (-12780)

버퍼를 작성할 때 프레젠테이션 타임 스탬프가 마지막으로 작성한 프레임보다 큰지 확인해야 쓰기가 실패합니다. 다음 로직을 사용하여 수표를 추가 할 수 있습니다.

CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); 
     if(CMTIME_COMPARE_INLINE(presentationTimeStamp, <=, lastpresentationTimeStamp)) 
     { 
      NSLog(@"presentationTimeStamp is less than last frame timestamp, So rejecting frame"); 
      return; 
     } 
     lastpresentationTimeStamp = presentationTimeStamp; 
+0

감사합니다. 훌륭한! – SpaceDog