2015-09-20 85 views
2

我試圖使用AVAssetWriterInput裁剪我在我的應用程序的屏幕錄像中閱讀的視頻。這是我目前的配置。AVAssetWriterInput目前不支持AVVideoScalingModeFit - IOS錯誤

NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
              [NSNumber numberWithInt:320], AVVideoCleanApertureWidthKey, 
              [NSNumber numberWithInt:480], AVVideoCleanApertureHeightKey, 
              [NSNumber numberWithInt:10], AVVideoCleanApertureHorizontalOffsetKey, 
              [NSNumber numberWithInt:10], AVVideoCleanApertureVerticalOffsetKey, 
              nil]; 


NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
              [NSNumber numberWithInt:3], AVVideoPixelAspectRatioHorizontalSpacingKey, 
              [NSNumber numberWithInt:3],AVVideoPixelAspectRatioVerticalSpacingKey, 
              nil]; 

NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
           [NSNumber numberWithInt:960000], AVVideoAverageBitRateKey, 
           [NSNumber numberWithInt:1],AVVideoMaxKeyFrameIntervalKey, 
           videoCleanApertureSettings, AVVideoCleanApertureKey, 
           videoAspectRatioSettings, AVVideoPixelAspectRatioKey, 
           AVVideoProfileLevelH264BaselineAutoLevel, AVVideoProfileLevelKey, 
           nil]; 

NSDictionary *videoSettings = @{AVVideoCodecKey:AVVideoCodecH264, 
           AVVideoCompressionPropertiesKey:codecSettings, 
           AVVideoScalingModeKey:AVVideoScalingModeResizeAspectFill, 
           AVVideoWidthKey:[NSNumber numberWithInt:320], 
           AVVideoHeightKey:[NSNumber numberWithInt:480]}; 

_videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; 

我收到以下錯誤:「AVAssetWriterInput目前不支持AVVideoScalingModeFit」

這是使用這個庫的人常犯的錯誤,但我無法找到實際解決的辦法。我只是看到有人說:「我終於明白了」而不解釋它。問題肯定與這一行有關:「AVVideoScalingModeKey:AVVideoScalingModeResizeAspectFill」,它告訴AVAssetWriter裁剪視頻並保持寬高比。任何人都知道這個解決方案?

回答

0

本身沒有「解決方案」。這只是不受支持。您需要使用核心圖像或VTPixelTransferSession或任何適合您的管道的比例來自行縮放視頻幀。