Example Usage for getting markers from Timeline at specific CMTime? #25
Replies: 1 comment
-
There's a very simple way to scrape all markers from a timeline with one line of code. You need to acquire the project element first, then run the extraction and store the results to query later. After that, extracted markers will have absolute timecode positions you can access as I haven't tested this code, but in theory it should work. It truncates subframes in case markers aren't exactly on a frame start so it can compare against the class FCPXMLMarkerLocator {
let markers: [FinalCutPro.FCPXML.ExtractedMarker]
init?(xmlString: String) async throws {
guard let data = xmlString.data(using: .utf8) else { return nil }
let fcpxml = try FinalCutPro.FCPXML(fileContent: data)
guard let project = fcpxml.allProjects().first else { return nil }
markers = await project.extract(preset: .markers)
}
func markers(at cmTime: CMTime) -> [FinalCutPro.FCPXML.ExtractedMarker] {
markers.filter {
$0.timecode()?
.roundedDown(toNearest: .frames)
.cmTimeValue == cmTime
}
}
} The |
Beta Was this translation helpful? Give feedback.
-
Let's say I want to get all the markers at a specific
CMTime
reference in a FCPXML.Here's an example FCPXML (it's been dragged directly from a Project in the Browser):
How would I go about this?
Beta Was this translation helpful? Give feedback.
All reactions