longitachi / ZLPhotoBrowser

Wechat-like image picker. Support select photos, videos, gif and livePhoto. Support edit image and crop video. 微信样式的图片选择器,支持预览/相册内拍照及录视频、拖拽/滑动选择,编辑图片/视频,支持多语言国际化等功能;
MIT License
4.71k stars 950 forks source link

增加一个videoCodeType属性,解决因为视频编码不同导致安卓或者pc端无法播放的问题 #831

Closed GPX-NSlog closed 11 months ago

GPX-NSlog commented 11 months ago

在不同版本的系统中AVVideoCodecType的默认值不同导致安卓端无法播放

// 在startRecord方法中查看默认的AVVideoCodecType
        if #available(iOS 11.0, *) {
            let outputSettings = [AVVideoCodecKey: AVVideoCodecType.h264]
            if let connection = movieFileOutput.connection(with: .video) {
                let dict1 = movieFileOutput.outputSettings(for: connection)
                print(dict)
                movieFileOutput.setOutputSettings(outputSettings, for: connection)
                let dict2 = movieFileOutput.outputSettings(for: connection)
                print(dict1)
            }
        }

输出结果:

dict1:  ["AVVideoCompressionPropertiesKey": {
    AllowFrameReordering = 1;
    AllowOpenGOP = 1;
    AverageBitRate = 7651584;
    ExpectedFrameRate = 30;
    MaxKeyFrameIntervalDuration = 1;
    MaxQuantizationParameter = 41;
    MinimizeMemoryUsage = 1;
    Priority = 80;
    ProfileLevel = "HEVC_Main_AutoLevel";
    RealTime = 1;
    RelaxAverageBitRateTarget = 1;
    SoftMinQuantizationParameter = 18;
}, "AVVideoHeightKey": 1080, "AVVideoWidthKey": 1920, "AVVideoCodecKey": hvc1]

dict2: ["AVVideoCompressionPropertiesKey": {
    AllowFrameReordering = 0;
    AverageBitRate = 15303168;
    ExpectedFrameRate = 30;
    H264EntropyMode = CABAC;
    MaxKeyFrameIntervalDuration = 1;
    Priority = 80;
    ProfileLevel = "H264_High_AutoLevel";
    QuantizationScalingMatrixPreset = 3;
    RealTime = 1;
}, "AVVideoWidthKey": 1920, "AVVideoCodecKey": avc1, "AVVideoHeightKey": 1080]
longitachi commented 11 months ago
image

有两条评论,你少看了一条。 另一个地方也加上 @available(iOS 11.0, *) 就好了,本身这个属性就是给11.0之后的系统用的,这两个地方加下就好了