gpt4 book ai didi

ios - 从 UTI 获取视频文件类型格式

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:11:37 27 4
gpt4 key购买 nike

我正在构建一个使用 AVFoundation 的视频编辑应用程序。当用户导入他们的视频(通过 NSOpenPanel 文件浏览器)时,我只想让他们选择 AVFoundation 支持的可接受的视频格式。

您可以通过调用 AVURLAsset 上的 audioVisualTypes() 来检索那些接受的格式。但是,这些格式包含很多我不需要的乱码/东西,例如:

 "public.mpeg",


"dyn.ah62d46dzqm0gw23sqf40k4pts3y1g7pbru00g55ssvw067b4gq81q4peqz1w88brrz2de7a",
"public.dv-movie",
"public.pls-playlist",

"dyn.ah62d46dzqm0gw23sqf40k4pts3y1g7pbru00g55ssvw067b4gq80c6durvy0g2pyrf106p50r3wc62pusb0gnpxrsbw0s7pwru",
"public.aac-audio",

有没有人知道如何将它们解析为一个简单的文件扩展名数组?谢谢

最佳答案

您想使用函数 UTTypeCopyPreferredTagWithClass。在 Playground 上试试这个

import MobileCoreServices
import AVFoundation

let avTypes = AVURLAsset.audiovisualTypes()

let anAVType = avTypes[0]

if let ext = UTTypeCopyPreferredTagWithClass(anAVType as CFString,kUTTagClassFilenameExtension)?.takeRetainedValue() {
print("The AVType \(anAVType) has extension '\(ext)'")
}
else {
print("Can't find the extension for the AVType '\(anAVType)")
}

print("\n")

let avExtensions = avTypes.map({UTTypeCopyPreferredTagWithClass($0 as CFString,kUTTagClassFilenameExtension)?.takeRetainedValue() as String? ?? ""})

print("All extensions = \(avExtensions)\n")

avExtensions = avExtensions.filter { $0.isEmpty == false }

print("All extensions filtered = \(avExtensions)\n")

print("First extension = '\(avExtensions[0])'")
print("Second extension = '\(avExtensions[1])'")
print("Third extension = '\(avExtensions[2])'")

结果:

The AVType AVFileType(_rawValue: public.pls-playlist) has extension 'pls'


All extensions = ["pls", "", "aifc", "m4r", "", "", "wav", "", "", "3gp", "3g2", "", "", "", "flac", "avi", "m2a", "", "aa", "", "aac", "mpa", "", "", "", "", "", "m3u", "mov", "aiff", "ttml", "", "m4v", "", "", "amr", "caf", "m4a", "mp4", "mp1", "", "m1a", "mp4", "mp2", "mp3", "itt", "au", "eac3", "", "", "webvtt", "", "", "vtt", "ac3", "m4p", "", "", "mqv"]

All extensions filtered = ["pls", "aifc", "m4r", "wav", "3gp", "3g2", "flac", "avi", "m2a", "aa", "aac", "mpa", "m3u", "mov", "aiff", "ttml", "m4v", "amr", "caf", "m4a", "mp4", "mp1", "m1a", "mp4", "mp2", "mp3", "itt", "au", "eac3", "webvtt", "vtt", "ac3", "m4p", "mqv"]

First extension = 'pls'
Second extension = 'aifc'
Third extension = 'm4r'

关于ios - 从 UTI 获取视频文件类型格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45395033/

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