1
我嘗試基於收集圖像創建視頻。 圖像的大小保存在inputSize中。 視頻的大小保存在outputSize中。AVAssetWriterInput:如何獲得影片中圖像的正確縱橫比?
我希望視頻中的圖像方面適合全高。
但由於某些原因,我無法解釋,最終的視頻顯示全高度圖像(好),但橫向軸伸展。
我怎樣才能得到正確的寬度(與正確的長寬比)?
我的代碼片段如下:
static let videoW: CGFloat = 720
static let videoH: CGFloat = 1280
let videoRatio = videoW/videoH
var inputSize = CGSize(width: 480, height:700)
static let outputSize = CGSize(width: videoW, height: videoH)
if let videoWriter = videoWriter {
let videoSettings: [String : AnyObject] = [
AVVideoCodecKey : AVVideoCodecH264,
AVVideoWidthKey : MovieBuilder.outputSize.width,
AVVideoHeightKey : MovieBuilder.outputSize.height,
]
let videoWriterInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: videoSettings)
let sourceBufferAttributes = [String : AnyObject](dictionaryLiteral:
(kCVPixelBufferPixelFormatTypeKey as String, Int(kCVPixelFormatType_32ARGB)),
(kCVPixelBufferWidthKey as String, Float(inputSize.width)),
(kCVPixelBufferHeightKey as String, Float(inputSize.height))
)
您是對的。我現在像一種魅力。謝謝。 –