Skip to content

Effort free video editing!

Read markers when importing FCP7 XML, FCPXML and EDL

WyattBlue115a946524ba
diff --git a/docs/src/docs/v3.md b/docs/src/docs/v3.md
index 3b87296f..94477a1f 100644
--- a/docs/src/docs/v3.md
+++ b/docs/src/docs/v3.md
@@ -144,12 +144,21 @@ From the command line, `--marker` sets them in the input's time, and auto-editor
| Export | Written as | Keeps |
|---|---|---|
| `premiere-otio` | markers on the timeline's stack | name, note, color, span |
-| `premiere`, `resolve-fcp7` | sequence markers | name, note, span |
+| `premiere` | sequence markers | name, note, color (pink as purple), span |
+| `resolve-fcp7` | sequence markers | name, note, span |
| `final-cut-pro`, `resolve` | markers on the clip each starts during; a span ends with its clip | name, note, span |
| `edl` | `* LOC:` comments at the record time | name, color (orange as yellow, purple and pink as magenta) |
| `shotcut` | timeline markers | name, color, span |
| `kdenlive` | timeline guides, with a category per color | name, color, span |
+Importing reads them back:
+
+| Import | Read from | Gets |
+|---|---|---|
+| FCP7 XML | the sequence's markers, and each clip's where the clip plays | name, note, span; from Premiere's, the color too |
+| FCPXML | markers on the storyline's clips and gaps and on connected clips, where the clip plays | name, note, span; a to-do marker is `red`, a completed one `green`, a chapter marker `orange` |
+| EDL | `* LOC:` comments, and the events of a Resolve marker list | name, color; from Resolve's, the note and span too |
+
A media export writes named markers as chapters: a span's own length, or for a point, up to the next chapter. `--no-chapters` leaves them out.
```json
diff --git a/src/exports/drops.nim b/src/exports/drops.nim
index 88400748..deffb97a 100644
--- a/src/exports/drops.nim
+++ b/src/exports/drops.nim
@@ -132,7 +132,7 @@ proc exportDrops*(tl: v3, kind: ExportKind): seq[string] {.raises: [].} =
# Every editor export carries markers, but not every part of one: OTIO
# alone has a place for all of it.
if tl.markers.len > 0:
- if kind in {exFinalCutPro, exResolve, exPremiere, exResolveFcp7} and
+ if kind in {exFinalCutPro, exResolve, exResolveFcp7} and
tl.markers.anyIt(it.color != mcBlue):
result.add "marker colors"
if kind in {exEdl, exShotcut, exKdenlive} and tl.markers.anyIt(it.note != ""):
diff --git a/src/exports/fcp7.nim b/src/exports/fcp7.nim
index fef08d46..7c977084 100644
--- a/src/exports/fcp7.nim
+++ b/src/exports/fcp7.nim
@@ -4,7 +4,7 @@ from std/math import ceil, round
when defined(windows):
import std/strutils
-import ../[action, ffmpeg, media, timeline]
+import ../[action, ffmpeg, log, media, timeline]
import ../util/[fun, rational]
import ../lib/speedmap
@@ -729,14 +729,26 @@ proc fcp7WriteXml*(name, output: string, resolve: bool, tl: v3) =
media.add audio
sequence.add media
- # A sequence's markers come after its media. `out` is -1 for a point; the
- # format has no place for a color.
+ # A sequence's markers come after its media. `out` is -1 for a point. The
+ # format has no place for a color; Premiere adds its own, as 0xAABBGGRR.
for m in tl.markers:
let marker = newElement("marker")
marker.add elem("comment", m.note)
marker.add elem("name", m.name)
marker.add elem("in", $m.start)
marker.add elem("out", (if m.dur > 0: $(m.start + m.dur) else: "-1"))
+ if not resolve:
+ # The eight colors Premiere gives a marker; it has no pink.
+ let color = case m.color
+ of mcBlue: 0xFFFC8D42'u32
+ of mcRed: 0xFF362CD2'u32
+ of mcOrange: 0xFF246FE9'u32
+ of mcYellow: 0xFF2BA1D0'u32
+ of mcGreen: 0xFF378671'u32
+ of mcCyan: 0xFFD6F419'u32
+ of mcPurple, mcPink: 0xFFB18BAF'u32
+ of mcWhite: 0xFFFFFFFF'u32
+ marker.add elem("pproColor", $color)
sequence.add marker
xmeml.add sequence
diff --git a/src/imports/edl.nim b/src/imports/edl.nim
index aaa6c51f..32f9577f 100644
--- a/src/imports/edl.nim
+++ b/src/imports/edl.nim
@@ -1,7 +1,8 @@
## CMX 3600 edit decision lists: cut, dissolve and wipe events on V and
## A1 to A4, `M2` speed changes, and the `* FROM CLIP NAME`, `* TO CLIP NAME`,
## `* SOURCE FILE` and `* EFFECT NAME` comments that name the media and the
-## transitions.
+## transitions. Markers come from Avid's `* LOC:` comments and from the
+## events of a Resolve marker list.
##
## An EDL carries no frame rate. The one asked for with `--frame-rate` is
## used; otherwise the first video file's, or failing that one guessed from
@@ -34,9 +35,18 @@ type
files: seq[string]
m2: seq[(string, float64)] # reel, source frames a second
drop: bool # the FCM in force
+ marks: bool # a Resolve marker list's event: a marker's place, not a clip
+
+ Loc = object # a marker, before the frame rate is known
+ tc: Timecode
+ drop: bool
+ dur: int64
+ name, note: string
+ color: MarkerColor
Parsed = object
events: seq[Event]
+ locs: seq[Loc]
anyDrop: bool
maxFrame: int64
@@ -101,6 +111,57 @@ func parseEventLine(text: string, line: var Line): bool =
line.dur = numAt(1)
true
+func locColor(word: string): (bool, MarkerColor) =
+ ## The marker color for an Avid locator's, or Resolve's with its
+ ## "ResolveColor" prefix taken off.
+ case word.toLowerAscii
+ of "blue": (true, mcBlue)
+ of "red": (true, mcRed)
+ of "yellow", "lemon": (true, mcYellow)
+ of "green", "mint": (true, mcGreen)
+ of "cyan", "sky": (true, mcCyan)
+ of "magenta", "pink", "fuchsia", "rose": (true, mcPink)
+ of "purple", "lavender": (true, mcPurple)
+ of "orange", "sand", "cocoa": (true, mcOrange)
+ of "white", "cream": (true, mcWhite)
+ of "black": (true, mcBlue)
+ else: (false, mcBlue)
+
+func parseLoc(text: string, drop: bool, loc: var Loc): bool =
+ ## `timecode COLOR name`, the color and the name each optional.
+ let toks = text.splitWhitespace(maxsplit = 1)
+ if toks.len == 0 or not parseTimecode(toks[0], loc.tc): return false
+ loc.drop = drop
+ if toks.len > 1:
+ let rest = toks[1].splitWhitespace(maxsplit = 1)
+ let (known, color) = locColor(rest[0])
+ if known:
+ loc.color = color
+ if rest.len > 1: loc.name = rest[1].strip()
+ else:
+ loc.name = toks[1].strip()
+ true
+
+func parseResolveMarker(l: string, loc: var Loc): bool =
+ ## `note |C:ResolveColorBlue |M:name |D:frames`, the line under each event
+ ## of the marker list Resolve exports.
+ let c = l.find("|C:")
+ if c < 0: return false
+ let m = l.find("|M:", c)
+ if m < 0: return false
+ let d = l.rfind("|D:")
+ if d < m: return false
+ var word = l[c + 3 ..< m].strip()
+ if word.startsWith("ResolveColor"): word = word[len("ResolveColor") .. ^1]
+ loc.color = locColor(word)[1]
+ loc.note = l[0 ..< c].strip()
+ loc.name = l[m + 3 ..< d].strip()
+ var frames: int64
+ # Resolve counts a point as one frame long.
+ if parseInt64(l[d + 3 .. ^1].strip(), frames) and frames > 1:
+ loc.dur = frames
+ true
+
proc parse(text: string): Parsed =
var drop = false
var skipMetadata = false
@@ -114,6 +175,14 @@ proc parse(text: string): Parsed =
drop = "DROP" in upper and "NON" notin upper
result.anyDrop = result.anyDrop or drop
continue
+ var mark: Loc
+ if parseResolveMarker(l, mark):
+ if result.events.len > 0 and not skipMetadata:
+ mark.tc = result.events[^1].lines[0].tcs[2]
+ mark.drop = result.events[^1].drop
+ result.locs.add mark
+ result.events[^1].marks = true
+ continue
if skipMetadata and (l[0] == '*' or upper.startsWith("M2") or
upper.startsWith("AUD")):
continue
@@ -130,6 +199,9 @@ proc parse(text: string): Parsed =
result.events[^1].files.add value("SOURCE FILE:")
elif cu.startsWith("EFFECT NAME:"):
result.events[^1].effect = value("EFFECT NAME:")
+ elif cu.startsWith("LOC:"):
+ var loc: Loc
+ if parseLoc(value("LOC:"), drop, loc): result.locs.add loc
continue
if upper.startsWith("M2"):
# `M2 REEL fps source-in`; a reel with spaces is joined back.
@@ -385,6 +457,8 @@ proc resolveSources(p: var Parsed, edlDir: string, interner: var StringInterner)
## Each line's media: its `SOURCE FILE`, else its clip name, else its reel,
## relative to the EDL.
for ev in p.events.mitems:
+ # A marker list's events name no media.
+ if ev.marks and ev.fromClip == "" and ev.files.len == 0: continue
for i, line in ev.lines.mpairs:
if line.reel.toUpperAscii == "BL": continue
let incoming = i > 0 and line.trans in {trDissolve, trWipe}
@@ -442,6 +516,13 @@ proc edlRead*(path: string, interner: var StringInterner,
for ev in parsed.events:
im.importEvent(ev)
+ var markers: seq[Marker]
+ for loc in parsed.locs:
+ let at = im.rec(loc.tc, loc.drop)
+ if at >= 0:
+ markers.add Marker(start: at, dur: loc.dur, name: loc.name, note: loc.note,
+ color: loc.color)
+ markers.sort(proc (a, b: Marker): int = cmp(a.start, b.start))
result = v3(tb: tb, bg: RGBColor(red: 0, green: 0, blue: 0), sr: 48000,
res: (1920'i32, 1080'i32), effects: im.effects)
@@ -452,6 +533,7 @@ proc edlRead*(path: string, interner: var StringInterner,
result.a.add track.clips
if result.v.len == 0 and result.a.len == 0:
error "EDL places no clips"
+ result.markers = markers
var layout = "stereo"
for src in sources:
let mi = probed[src]
diff --git a/src/imports/fcp11.nim b/src/imports/fcp11.nim
index 899569f8..b1aec271 100644
--- a/src/imports/fcp11.nim
+++ b/src/imports/fcp11.nim
@@ -14,7 +14,7 @@ const fcp11Tags = ["fcpxml", "resources", "format", "asset", "media-rep",
"clip", "video", "audio", "gap", "transition", "filter-video",
"filter-audio", "param", "timeMap", "timept", "adjust-volume", "metadata",
"md", "array", "string", "conform-rate", "audio-channel-source", "caption",
- "text", "text-style", "text-style-def"]
+ "text", "text-style", "text-style-def", "marker", "chapter-marker"]
type
Asset = object
@@ -40,6 +40,7 @@ type
effectIndex: EffectIndex
lanes: Table[int, seq[Placed]] # connected clips by lane
captions: seq[(string, CaptionTrack)] # by role, in order of appearance
+ markers: seq[Marker]
dropped: CountTable[string]
func uiName(tag: string): string =
@@ -217,6 +218,25 @@ proc readCaption(r: var Reader, n: XmlNode, start: int64) =
r.captions.add (role, CaptionTrack(lang: langOfRole(role),
cues: @[Caption(start: start, dur: dur, text: text)]))
+proc readMarkers(r: var Reader, n: XmlNode, start: int64) =
+ ## The markers on `n`, which starts at timeline frame `start`. They are in
+ ## its own time, and one outside the part of it that plays isn't shown.
+ let length = r.frames(n.attrSeconds("duration"))
+ for c in n:
+ if c.kind != xnElement or c.tag notin ["marker", "chapter-marker"]: continue
+ let local = r.frames(c.attrSeconds("start") - n.attrSeconds("start"))
+ if local < 0 or local >= length or start + local < 0: continue
+ # Final Cut Pro's markers are a frame long: only a longer one is a span.
+ let dur = r.frames(c.attrSeconds("duration"))
+ # A marker's kind is told apart by color in Final Cut Pro, so keep that.
+ let color =
+ if c.tag == "chapter-marker": mcOrange
+ elif c.attr("completed") == "0": mcRed
+ elif c.attr("completed") == "1": mcGreen
+ else: mcBlue
+ r.markers.add Marker(start: start + local, dur: (if dur > 1: dur else: 0),
+ name: c.attr("value"), note: c.attr("note"), color: color)
+
proc readConnected(r: var Reader, parent: XmlNode, parentStart: int64) =
## Clips connected to `parent`, which starts at timeline frame `parentStart`.
## Their offsets are in the parent's own time, which begins at its start.
@@ -231,8 +251,9 @@ proc readConnected(r: var Reader, parent: XmlNode, parentStart: int64) =
if c.tag == "spine":
r.dropped.inc "connected storyline"
continue
- if c.attr("enabled") == "0": continue
let start = parentStart + r.frames(c.attrSeconds("offset") - origin)
+ r.readMarkers(c, start)
+ if c.attr("enabled") == "0": continue
if c.tag == "caption":
r.readCaption(c, start)
continue
@@ -356,6 +377,7 @@ proc fcp11ReadXml*(path: string, interner: var StringInterner): v3 =
for n in spine:
if n.kind != xnElement: continue
let start = r.frames(n.attrSeconds("offset") - tcStart)
+ if n.tag != "transition": r.readMarkers(n, start)
case n.tag
of "asset-clip", "clip":
var item = StoryItem(kind: skGap)
@@ -455,6 +477,8 @@ proc fcp11ReadXml*(path: string, interner: var StringInterner): v3 =
for t in result.at[0].mitems: t.kind = tkDissolve
result.validateTransitions()
+ r.markers.sort(proc(a, b: Marker): int = cmp(a.start, b.start))
+ result.markers = r.markers
result.effects = r.effects
result.templateFile = result.firstSource
result.updateNumberOfSrc()
diff --git a/src/imports/fcp7.nim b/src/imports/fcp7.nim
index e4824dff..33486501 100644
--- a/src/imports/fcp7.nim
+++ b/src/imports/fcp7.nim
@@ -13,7 +13,8 @@ const fcp7Tags = ["xmeml", "sequence", "media", "video", "audio", "track",
"effectid", "effecttype", "parameter", "parameterid", "value", "valuemin",
"valuemax", "keyframe", "when", "rate", "timebase", "ntsc", "duration",
"pathurl", "masterclipid", "pproTicksIn", "pproTicksOut", "alphatype",
- "pixelaspectratio", "anamorphic", "logginginfo", "colorinfo", "comments"]
+ "pixelaspectratio", "anamorphic", "logginginfo", "colorinfo", "comments",
+ "marker", "comment", "pproColor"]
func readTbNtsc(tb: int, ntsc: bool): AVRational =
if ntsc:
@@ -289,13 +290,47 @@ proc generatorColor(effect: XmlNode): (bool, RGBColor) =
return (true, color)
(false, color)
+func fromPproColor(value: int64): MarkerColor =
+ ## The marker color nearest Premiere's, which it writes as 0xAABBGGRR.
+ const premiere = [(mcBlue, 0x428DFC), (mcRed, 0xD22C36), (mcOrange, 0xE96F24),
+ (mcYellow, 0xD0A12B), (mcGreen, 0x718637), (mcCyan, 0x19F4D6),
+ (mcPurple, 0xAF8BB1), (mcWhite, 0xFFFFFF)]
+ let (r, g, b) = (value and 0xFF, (value shr 8) and 0xFF, (value shr 16) and 0xFF)
+ var best = high(int64)
+ for (color, rgb) in premiere:
+ let (dr, dg, db) = (r - (rgb shr 16), g - ((rgb shr 8) and 0xFF), b - (rgb and 0xFF))
+ let dist = dr * dr + dg * dg + db * db
+ if dist < best:
+ best = dist
+ result = color
+
+proc readMarker(node: XmlNode): (bool, Marker) =
+ ## A marker, in its sequence's or its clip's frames. `<out>` is -1 for a
+ ## point.
+ var marker: Marker
+ var stop = -1'i64
+ marker.start = -1
+ for c in node:
+ if c.kind != xnElement: continue
+ case c.tag
+ of "name": marker.name = c.innerText.strip()
+ of "comment": marker.note = c.innerText.strip()
+ of "in": marker.start = xmlInt(c, -1, maxFrames)
+ of "out": stop = xmlInt(c, -1, maxFrames)
+ of "pproColor": marker.color = fromPproColor(xmlInt(c, 0, high(uint32).int64))
+ else: discard
+ marker.dur = max(0'i64, stop - marker.start)
+ (marker.start >= 0, marker)
+
proc parseTrack(trackNode: XmlNode, files: var Table[string, FileInfo],
effects: var seq[Actions], effectIndex: var EffectIndex,
interner: var StringInterner, audio: bool, res: (int32, int32),
tb: AVRational, dropped: var CountTable[string]):
- tuple[clips: seq[Clip], transitions: seq[Transition], laterChannels: bool] =
+ tuple[clips: seq[Clip], transitions: seq[Transition], laterChannels: bool,
+ markers: seq[Marker]] =
## `laterChannels` is set when every audio clip names a channel past the
## first of its stream, as on the per-channel tracks resolve-fcp7 writes.
+ ## `markers` are the clips' own, placed on the timeline.
result.laterChannels = audio
var items: seq[XmlNode]
for c in trackNode:
@@ -323,7 +358,7 @@ proc parseTrack(trackNode: XmlNode, files: var Table[string, FileInfo],
var trackIndex = 1'i64
var clipTb = tb
var acts: seq[Action]
- var filterNodes: seq[XmlNode]
+ var filterNodes, markerNodes: seq[XmlNode]
for ci in trackChild:
if ci.kind != xnElement: continue
@@ -340,6 +375,7 @@ proc parseTrack(trackNode: XmlNode, files: var Table[string, FileInfo],
of "sequence": nested = true
of "enabled": enabled = ci.innerText.strip() != "FALSE"
of "filter": filterNodes.add ci
+ of "marker": markerNodes.add ci
of "rate": clipTb = readRate(ci)
of "sourcetrack":
for st in ci:
@@ -441,6 +477,18 @@ proc parseTrack(trackNode: XmlNode, files: var Table[string, FileInfo],
elif inExt > 0: max(0'i64, outVal - outExt - dur)
elif ticksIn >= 0: int64(round(ticksIn.float / ticksPerFrame / speed))
else: inVal
+ # A clip carries all of its media's markers, in the media's frames:
+ # those in the part it plays show on the timeline. A ramp or a reversed
+ # clip moves through its media unevenly, so theirs are left out.
+ if rampOffset < 0 and not remap.ramp and not remap.reverse and speed > 0.0:
+ for mn in markerNodes:
+ let (ok, m) = readMarker(mn)
+ if not ok: continue
+ let at = startVal + int64(round(m.start.float64 * scale / speed)) - offset
+ if at < startVal or at >= endVal: continue
+ let span = int64(round(m.dur.float64 * scale / speed))
+ result.markers.add Marker(start: at, dur: min(span, endVal - at),
+ name: m.name, note: m.note, color: m.color)
let e = effectIndex.intern(effects, newActions(acts))
var stream = 0'i16
if audio:
@@ -467,6 +515,7 @@ proc fcp7ReadXml*(path: string, interner: var StringInterner): v3 =
var tb = AVRational(num: 30, den: 1)
var mediaNode: XmlNode = nil
+ var markers: seq[Marker]
for child in seqNode:
if child.kind != xnElement: continue
@@ -475,6 +524,9 @@ proc fcp7ReadXml*(path: string, interner: var StringInterner): v3 =
tb = readRate(child)
of "media":
mediaNode = child
+ of "marker":
+ let (ok, marker) = readMarker(child)
+ if ok: markers.add marker
else: discard
if mediaNode == nil:
@@ -509,8 +561,9 @@ proc fcp7ReadXml*(path: string, interner: var StringInterner): v3 =
elif sc.tag == "height": h = xmlInt(sc, 1, high(int32)).int32
res = (w, h)
of "track":
- let (clips, transitions, _) = parseTrack(vidChild, files, effects,
- effectIndex, interner, audio = false, res, tb, dropped)
+ let (clips, transitions, _, clipMarkers) = parseTrack(vidChild, files,
+ effects, effectIndex, interner, audio = false, res, tb, dropped)
+ markers.add clipMarkers
if clips.len > 0:
vobjs.add clips
vtrans.add transitions
@@ -530,8 +583,10 @@ proc fcp7ReadXml*(path: string, interner: var StringInterner): v3 =
of "track":
let idx = audChild.attr("currentExplodedTrackIndex")
if idx != "" and idx != "0": continue
- let (clips, transitions, laterChannels) = parseTrack(audChild, files,
- effects, effectIndex, interner, audio = true, res, tb, dropped)
+ let (clips, transitions, laterChannels, clipMarkers) = parseTrack(
+ audChild, files, effects, effectIndex, interner, audio = true, res, tb,
+ dropped)
+ markers.add clipMarkers
# Clips play whole streams, which the stream's first-channel track
# already holds.
if clips.len > 0 and not laterChannels:
@@ -546,6 +601,10 @@ proc fcp7ReadXml*(path: string, interner: var StringInterner): v3 =
result.vt = vtrans
result.at = atrans
result.validateTransitions()
+ # A clip's video and each of its audio channels repeat its markers.
+ markers.sort(proc (a, b: Marker): int = cmp(a.start, b.start))
+ for m in markers:
+ if m notin result.markers: result.markers.add m
result.templateFile = result.firstSource
result.updateNumberOfSrc()
# The layout of the first audio clip's stream, as rendering its source would.