I try to create a video based on a collection images. The size of the images is hold in inputSize. The size of the video is hold in outputSize.
I'd like the images aspect fit with full height in the video.
But for some reasons I can't explain, the final video shows full height image (good) but a stretched on the horizontal axis.
How can I get the right width (with the right aspect ratio)?
My code snippet as follows:
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))
)
Hello in your video settings try adding this to part of your dictionary
AVVideoScalingModeKey : AVVideoScalingModeResizeAspectFill.
The source bufferAttributes should also reflect the same size as the video settings