Swift視頻錄製之設定視頻壓縮品質、解析度例子

來源:互聯網
上載者:User


在之前的小視頻錄製文章中,我們使用 AVAssetExportSession 將合并後的視頻壓縮輸出成一個最終的視頻檔案。當時使用的是高品質的壓縮(AVAssetExportPresetHighestQuality)。


let exporter = AVAssetExportSession(asset: composition,
                                    presetName:AVAssetExportPresetHighestQuality)!

當然除了AVAssetExportPresetHighestQuality,還有許多其它的設定視頻解析度(Export preset)供我們選擇使用。比如為了方便傳輸,節約頻寬,可以將視頻轉成低解析度。

1,固定解析度預設屬性

(1)AVAssetExportPreset640x480:設定視頻解析度640x480
(2)AVAssetExportPreset960x540:設定視頻解析度960x540
(3)AVAssetExportPreset1280x720:設定視頻解析度1280x720
(4)AVAssetExportPreset1920x1080:設定視頻解析度1920x1080
(5)AVAssetExportPreset3840x2160:設定視頻解析度3840x2160

2,相對品質預設屬性

(1)AVAssetExportPresetLowQuality:低品質
(2)AVAssetExportPresetMediumQuality:中等品質
(3)AVAssetExportPresetHighestQuality:高品質

這種設定方式,最終產生的視頻解析度與具體的拍攝裝置有關。比如 iPhone6 拍攝的視頻:
使用AVAssetExportPresetHighestQuality則視頻解析度是1920x1080(不壓縮)。
AVAssetExportPresetMediumQuality視頻解析度是568x320
AVAssetExportPresetLowQuality視頻解析度是224x128

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.