gpt4 book ai didi

ios - 修改了分辨率设置的 AVAssetExportSession

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:32:23 50 4
gpt4 key购买 nike

AVAssetExportSession 将预设作为其初始化参数之一:

AVAssetExportSession(asset: AVAsset, presetName: String)

其中预设是 AVAssetExportPreset640x480AVAssetExportPreset1920x1080 等设置。但是,如果我想使用自定义分辨率(比如 250x400)进行编码,是否有办法做到这一点?如果可以,怎么做?

最佳答案

这些导出选项已定义,无法让您使用自定义分辨率进行编码。或者,您可以尝试这种方法

func exportVideo(asset:AVAsset, renderedWidth: CGFloat, renderedHeight: CGFloat, exportCompletionHandler: (() -> Void)?) {
let videoTrack: AVAssetTrack = asset.tracksWithMediaType(AVMediaTypeVideo)[0]

let videoComposition = AVMutableVideoComposition()
videoComposition.frameDuration = CMTimeMake(1, 30)
videoComposition.renderSize = CGSizeMake(renderedWidth, renderedHeight)

let instruction: AVMutableVideoCompositionInstruction = AVMutableVideoCompositionInstruction.init()
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30))

let transformer: AVMutableVideoCompositionLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack);
//Apply any transformer if needed
//

instruction.layerInstructions = [transformer]
videoComposition.instructions = [instruction]

//Create export path
let exportPath: NSURL = NSURL(fileURLWithPath: "export_path_here")
//

let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)
exporter?.videoComposition = videoComposition
exporter?.outputURL = exportPath
exporter?.outputFileType = AVFileTypeQuickTimeMovie

exporter?.exportAsynchronouslyWithCompletionHandler({ () -> Void in
//Do sth when finished
if let handler = exportCompletionHandler {
handler()
}
})
}

希望对您有所帮助。

引用:https://www.one-dreamer.com/cropping-video-square-like-vine-instagram-xcode/

关于ios - 修改了分辨率设置的 AVAssetExportSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730710/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com