ios 用swift修改帧率和比特率

dxxyhpgq  于 2023-08-08  发布在  iOS
关注(0)|答案(1)|浏览(144)

我正在使用返回.mov的相机录制视频,然后我将该视频导出为.mp4,并使用以下代码更改质量以减小视频的大小...

func convertMOVtoMP4(inputURL: URL, outputURL: URL, completion: @escaping (Bool) -> Void) {
        let asset = AVURLAsset(url: inputURL)
        
        DispatchQueue.main.async {
            guard let exportSession = AVAssetExportSession(asset: asset,
                                                           presetName: AVAssetExportPreset960x540) else {
                completion(false)
                return
            }
            
            exportSession.outputURL = outputURL
            exportSession.outputFileType = .mp4
            exportSession.shouldOptimizeForNetworkUse = true
            
            exportSession.exportAsynchronously {
                switch exportSession.status {
                case .completed:
                    completion(true)
                default:
                    completion(false)
                }
            }
        }
    }

字符串
如何在导出mp4中的视频时修改帧速率和比特率.

kuhbmx9i

kuhbmx9i1#

let videoSettings:[String:Any] = [
        AVVideoCompressionPropertiesKey: [AVVideoAverageBitRateKey: self.bitrate],
        AVVideoCodecKey: AVVideoCodecType.h264,
        AVVideoHeightKey: videoTrack.naturalSize.height,
        AVVideoWidthKey: videoTrack.naturalSize.width,
        AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill
    ]

let bitrate: NSNumber = NSNumber(value: 1250000) // *** you can change this number to increase/decrease the quality. The more you increase, the better the video quality but the the compressed file size will also increase

字符串
我更新了我的答案

相关问题