gpt4 book ai didi

ios - 减少 swift/iOS 中的视频大小以上传到服务器

转载 作者:搜寻专家 更新时间:2023-10-31 22:46:18 26 4
gpt4 key购买 nike

我正在使用 UIImagePickerController 从我的 swift iOS 应用程序中挑选视频。我正在保存此 URL,现在想将其转换为数据以发送到我的服务器进行存储,使用:

let messageVideoData = NSData(contentsOfURL: chosenVideoURL)

问题是文件太大了。对于在我的 iPhone 6s 上拍摄的 7 秒视频,分辨率为 1280、720,帧速率为 30,文件大小超过 4 MB。我注意到用 whatsapp 和其他聊天应用程序发送的相同图像减少到几百 KB。

减小外部存储文件大小的最佳方法是什么?该视频主要针对手机,因此可以将分辨率降低到 800 或更低。

我尝试将 UIImagePickerController 质量设置为:

picker.videoQuality = UIImagePickerControllerQualityType.Type640x480

但这只会将文件大小减小到 3.5 MB。

使用:

picker.videoQuality = UIImagePickerControllerQualityType.TypeLow

将分辨率降低到远低于预期的值。

我应该采取另一种方法来减小我的视频文件大小以便存储在我的服务器上吗?

最佳答案

试试这个压缩视频的答案。根据jojaba's answer :

If you are wanting to compress the video for remote sharing and to keep the original quality for local storage on the iPhone, you should look into AVAssetExportSession or AVAssetWriter.

Compress Video Without Low Quality

虽然这种方法是按照 Objective-C 的。

您还应该考虑阅读 iOS 如何管理 Assets .

关于ios - 减少 swift/iOS 中的视频大小以上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37542242/

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