Skip to content

Commit

Permalink
Fixed regression in timeline start timecode detection
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed May 20, 2024
1 parent f7007e3 commit e4ee8f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
42 changes: 28 additions & 14 deletions Sources/MarkersExtractor/Extractors/FCPXMLMarkerExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
public let projectName: String?
public let timeline: FinalCutPro.FCPXML.AnyTimeline
public let timelineName: String
public let timelineStartTime: Timecode
public let timelineStartTimecode: Timecode
}

/// Returns the first timeline found in the FCPXML as well as contextual metadata.
Expand Down Expand Up @@ -127,22 +127,36 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
?? defaultTimelineName

// extract from origin element
guard let timelineStartTime = timeline.timelineStartAsTimecode() else {
logger.error(
"Could not determine timeline start timecode."
)
return nil
}
let timelineStartTimecode = startTimecode(for: timeline)

return TimelineContext(
library: library,
projectName: projectName,
timeline: timeline,
timelineName: timelineName,
timelineStartTime: timelineStartTime
timelineStartTimecode: timelineStartTimecode
)
}

/// Fetch the FCPXML timeline's frame rate, with fallbacks in case errors occur.
func startTimecode(for timeline: FinalCutPro.FCPXML.AnyTimeline) -> Timecode {
if let tc = timeline.timelineStartAsTimecode() {
logger.info(
"Timeline start timecode: \(tc.stringValue()) @ \(tc.frameRate.stringValueVerbose)."
)
return tc
} else if let frameRate = timeline.localTimecodeFrameRate() {
let tc = FinalCutPro.formTimecode(at: frameRate)
return tc
} else {
let tc = FinalCutPro.formTimecode(at: .fps30)
logger.warning(
"Could not determine timeline start timecode. Defaulting to \(tc.stringValue()) @ \(tc.frameRate.stringValueVerbose)."
)
return tc
}
}

public func extractMarkers(
context: TimelineContext
) async -> [Marker] {
Expand All @@ -158,7 +172,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
in: context.timeline,
library: context.library,
timelineName: context.timelineName,
timelineStartTime: context.timelineStartTime
timelineStartTimecode: context.timelineStartTimecode
)
}

Expand All @@ -167,7 +181,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
in: context.timeline,
library: context.library,
timelineName: context.timelineName,
timelineStartTime: context.timelineStartTime
timelineStartTimecode: context.timelineStartTimecode
)
}

Expand All @@ -185,7 +199,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
in timeline: FinalCutPro.FCPXML.AnyTimeline,
library: FinalCutPro.FCPXML.Library?,
timelineName: String,
timelineStartTime: Timecode
timelineStartTimecode: Timecode
) async -> [Marker] {
let extractedMarkers = await timeline.extract(
preset: .markers,
Expand All @@ -197,7 +211,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
$0,
parentLibrary: library,
timelineName: timelineName,
timelineStartTime: timelineStartTime
timelineStartTime: timelineStartTimecode
)
}
}
Expand All @@ -206,7 +220,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
in timeline: FinalCutPro.FCPXML.AnyTimeline,
library: FinalCutPro.FCPXML.Library?,
timelineName: String,
timelineStartTime: Timecode
timelineStartTimecode: Timecode
) async -> [Marker] {
let extractedCaptions = await timeline.extract(
preset: .captions,
Expand All @@ -218,7 +232,7 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
$0,
parentLibrary: library,
timelineName: timelineName,
timelineStartTime: timelineStartTime
timelineStartTime: timelineStartTimecode
)
}
}
Expand Down
19 changes: 0 additions & 19 deletions Sources/MarkersExtractor/MarkersExtractor Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@ import Foundation
import TimecodeKit

extension MarkersExtractor {
/// Fetch the FCPXML timeline's frame rate, with fallbacks in case errors occur.
func startTimecode(for timeline: FinalCutPro.FCPXML.AnyTimeline) -> Timecode {
if let tc = timeline.timelineStartAsTimecode() {
logger.info(
"Timeline start timecode: \(tc.stringValue(format: timecodeStringFormat)) @ \(tc.frameRate.stringValueVerbose)."
)
return tc
} else if let frameRate = timeline.localTimecodeFrameRate() {
let tc = FinalCutPro.formTimecode(at: frameRate)
return tc
} else {
let tc = FinalCutPro.formTimecode(at: .fps30)
logger.warning(
"Could not determine timeline start timecode. Defaulting to \(tc.stringValue(format: timecodeStringFormat)) @ \(tc.frameRate.stringValueVerbose)."
)
return tc
}
}

var timecodeStringFormat: Timecode.StringFormat {
s.enableSubframes ? [.showSubFrames] : .default()
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/MarkersExtractor/MarkersExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ extension MarkersExtractor {
)
}

let timelineStartTimecode: Timecode = startTimecode(for: context.timeline)

let outputURL = try makeOutputPath(forTimelineName: context.timelineName)

let media: ExportMedia?
Expand Down Expand Up @@ -105,7 +103,7 @@ extension MarkersExtractor {
// increments progress by 80%
let exportResult = try await export(
timelineName: context.timelineName,
timelineStartTimecode: timelineStartTimecode,
timelineStartTimecode: context.timelineStartTimecode,
media: media,
markers: markers,
outputURL: outputURL,
Expand Down

0 comments on commit e4ee8f5

Please sign in to comment.