Skip to content

Fix fcp11 warnings/errors #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions auto_editor/exports/fcp11.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@ def make_name(src: FileInfo, tb: Fraction) -> str:
return "FFVideoFormatRateUndefined"


def parseSMPTE(val: str, fps: Fraction, log: Log) -> int:
if len(val) == 0:
return 0
try:
parts = val.split(":")
if len(parts) != 4:
raise ValueError(f"Invalid SMPTE format: {val}")

hours, minutes, seconds, frames = map(int, parts)

if (
hours < 0
or minutes < 0
or minutes >= 60
or seconds < 0
or seconds >= 60
or frames < 0
):
raise ValueError(f"Invalid SMPTE values: {val}")

if frames >= fps:
raise ValueError(f"Frame count {frames} exceeds fps {fps}")

total_frames = (hours * 3600 + minutes * 60 + seconds) * fps + frames
return int(round(total_frames))
except (ValueError, ZeroDivisionError) as e:
log.error(f"Cannot parse SMPTE timecode '{val}': {e}")


def fcp11_write_xml(
group_name: str, version: int, output: str, resolve: bool, tl: v3, log: Log
) -> None:
Expand Down Expand Up @@ -83,12 +112,14 @@ def fraction(val: int) -> str:
height=f"{tl.res[1]}",
colorSpace=get_colorspace(one_src),
)

startPoint = parseSMPTE(one_src.timecode, tl.tb, log)
r2 = SubElement(
resources,
"asset",
id=f"r{i * 2 + 2}",
name=one_src.path.stem,
start="0s",
start=fraction(startPoint),
hasVideo="1" if one_src.videos else "0",
format=f"r{i * 2 + 1}",
hasAudio="1" if one_src.audios else "0",
Expand All @@ -115,12 +146,14 @@ def fraction(val: int) -> str:
spine = SubElement(sequence, "spine")

def make_clip(ref: str, clip: Clip) -> None:
startPoint = parseSMPTE(clip.src.timecode, tl.tb, log)

clip_properties = {
"name": proj_name,
"ref": ref,
"offset": fraction(clip.start),
"offset": fraction(clip.start + startPoint),
"duration": fraction(clip.dur),
"start": fraction(clip.offset),
"start": fraction(clip.offset + startPoint),
"tcFormat": "NDF",
}
asset = SubElement(spine, "asset-clip", clip_properties)
Expand Down
13 changes: 12 additions & 1 deletion auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FileInfo:
path: Path
bitrate: int
duration: float
timecode: str # in SMPTE
videos: tuple[VideoStream, ...]
audios: tuple[AudioStream, ...]
subtitles: tuple[SubtitleStream, ...]
Expand Down Expand Up @@ -165,12 +166,22 @@ def init(self, path: str, log: Log) -> FileInfo:
ext = sub_exts.get(codec, "vtt")
subtitles += (SubtitleStream(codec, ext, s.language),)

def get_timecode() -> str:
for d in cont.streams.data:
if (result := d.metadata.get("timecode")) is not None:
return result
for v in cont.streams.video:
if (result := v.metadata.get("timecode")) is not None:
return result
return "00:00:00:00"

timecode = get_timecode()
bitrate = 0 if cont.bit_rate is None else cont.bit_rate
dur = 0 if cont.duration is None else cont.duration / bv.time_base

cont.close()

return FileInfo(Path(path), bitrate, dur, videos, audios, subtitles)
return FileInfo(Path(path), bitrate, dur, timecode, videos, audios, subtitles)

def __repr__(self) -> str:
return f"@{self.path.name}"