admin管理员组文章数量:1287655
My program needs to read video metadata to find out the creation date in local time for the video when and where it was recorded. How do I do that?
I've gotten as far as:
// Create an AVAsset for the video file
let asset = AVURLAsset(url: fileURL)
print("Loaded AVURLAsset \(String(describing: asset))")
if let creationDate = try await asset.load(.creationDate) {
if let dateValue = try await creationDate.load(.dateValue) {
print("Creation date from metadata: \(dateValue)")
} else {
print("No parsable creation ate from metadata")
}
} else {
print("No creation ate from metadata")
}
However, the creationDate is in UTC. If I compare to the file creation date:
Creation date from metadata: 2025-02-23 19:14:20 +0000
Creation date for file: 2025-02-23 11:14:28 -0800
How do I find out that specific video's local time or timezone when it was recorded?
Please note that I don't want to convert the UTC time to local time based on the timezone of the computer running the program, I want to use the specific local time or timezone of the video in question. For instance, the video could have been recorded in a different timezone compared to where my computer happens to be in right now.
My program needs to read video metadata to find out the creation date in local time for the video when and where it was recorded. How do I do that?
I've gotten as far as:
// Create an AVAsset for the video file
let asset = AVURLAsset(url: fileURL)
print("Loaded AVURLAsset \(String(describing: asset))")
if let creationDate = try await asset.load(.creationDate) {
if let dateValue = try await creationDate.load(.dateValue) {
print("Creation date from metadata: \(dateValue)")
} else {
print("No parsable creation ate from metadata")
}
} else {
print("No creation ate from metadata")
}
However, the creationDate is in UTC. If I compare to the file creation date:
Creation date from metadata: 2025-02-23 19:14:20 +0000
Creation date for file: 2025-02-23 11:14:28 -0800
How do I find out that specific video's local time or timezone when it was recorded?
Please note that I don't want to convert the UTC time to local time based on the timezone of the computer running the program, I want to use the specific local time or timezone of the video in question. For instance, the video could have been recorded in a different timezone compared to where my computer happens to be in right now.
Share Improve this question edited Feb 24 at 3:08 HangarRash 15.1k5 gold badges19 silver badges55 bronze badges asked Feb 24 at 2:40 VillahousutVillahousut 1451 gold badge1 silver badge14 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0If the timezone has been added to the video asset meta data (eg using AVMutableMetadataItem), then you could try using this code to find it:
func test() async {
let fileURL = URL(string: "https://sample-videos/video321/mp4/720/big_buck_bunny_720p_1mb.mp4")!
let asset = AVURLAsset(url: fileURL)
print("---> asset \(asset)\n")
do {
let meta = try await asset.load(.metadata)
print("---> metadata: \(meta)\n")
let creationDates = AVMetadataItem.metadataItems(
from: meta,
filteredByIdentifier: monIdentifierCreationDate)
print("---> creationDates: \(creationDates)\n")
for item in meta {
if let key = itemmonKey?.rawValue {
let value = try await item.load(.value)
print("---> key: \(key) value: \(value)")
} else {
print("Unknown")
}
}
} catch {
print(error)
}
}
Note, with the given example, this did not give any dates or timezone.
本文标签: swiftIn AVFoundationhow do I find out the timezone of the creationDateStack Overflow
版权声明:本文标题:swift - In AVFoundation, how do I find out the timezone of the creationDate? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741296611a2370855.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
creationDate.load(.stringValue)
? – HangarRash Commented Feb 24 at 3:14timezone
from a Date that you get in yourdateValue
. ADate
is "A specific point in time, independent of any calendar or time zone." In other words alwaysUTC
timezone. – workingdog support Ukraine Commented Feb 24 at 3:30nil
for the string value. According to the documentation forcreationDate
, the date value is derived from the string value. I thought maybe the original string value would contain the original timezone in it. – HangarRash Commented Feb 25 at 4:05