Skip to content

fix(shotcut): set tractor out= before melt render to avoid 4-hour output#92

Open
jarrodcolburn wants to merge 2 commits intoHKUDS:mainfrom
jarrodcolburn:fix/melt-tractor-duration
Open

fix(shotcut): set tractor out= before melt render to avoid 4-hour output#92
jarrodcolburn wants to merge 2 commits intoHKUDS:mainfrom
jarrodcolburn:fix/melt-tractor-duration

Conversation

@jarrodcolburn
Copy link

Summary

  • When clips are added to the timeline, the MLT <tractor> element is created with out="00:00:00.000" and never updated
  • The background track defaults to out="04:00:00.000" (a Shotcut convention for an open-ended timeline)
  • Without an explicit tractor out, melt falls back to the longest track and renders a ~4-hour file instead of the actual content duration

Fix

Added _set_tractor_out() helper in export.py that runs before writing the temp MLT file for melt rendering:

  1. Calculates real content duration by summing entry in/out spans and blank lengths across all non-background playlists
  2. Sets out= on the tractor element
  3. Caps the background playlist entry and black producer to the same duration so melt doesn't extend the render to the 4-hour default

Test Plan

  • 110 unit tests passing (uv run --with pytest python -m pytest cli_anything/shotcut/tests/test_core.py)
  • export render on a project with a 6-second clip produces a 6-second output (previously produced ~500s)
  • Multi-segment projects: tractor out = sum of all clip durations

🤖 Generated with Claude Code

J. Courtland Colburn and others added 2 commits March 16, 2026 18:07
When clips are added to the timeline, the MLT tractor element is created
with out="00:00:00.000" and never updated. The background track defaults to
out="04:00:00.000" (a Shotcut convention). Without an explicit tractor out,
melt falls back to the longest track and renders a ~4-hour file instead of
the actual content duration.

Fix: calculate the real content duration from all non-background playlists
(summing entry in/out spans and blank lengths), then set out= on the tractor,
background playlist entry, and black producer before writing the temp MLT.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 16, 2026 22:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Shotcut/MLT exports rendered via melt producing excessively long (≈4-hour) outputs by ensuring the main <tractor> and background elements have a correct out= matching actual timeline content duration.

Changes:

  • Added _set_tractor_out() to compute timeline duration from playlists and set tractor out=.
  • Invoked _set_tractor_out() before writing the temp .mlt used by melt.
  • Added .worktrees/ to .gitignore.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
shotcut/agent-harness/cli_anything/shotcut/core/export.py Computes/sets tractor and background out= before melt render to avoid 4-hour default background duration.
shotcut/agent-harness/.gitignore Ignores .worktrees/ directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

elif child.tag == "blank":
try:
total += timecode_to_frames(child.get("length", "0"), fps_num, fps_den)
except Exception:
Comment on lines +452 to +465
if max_frames > 0:
out_tc = frames_to_timecode(max_frames - 1, fps_num, fps_den)
tractor.set("out", out_tc)
# Cap the background track to the same duration so melt doesn't
# extend the render to the 4-hour background default.
bg_playlist = mlt_xml.find_element_by_id(session.root, "background")
if bg_playlist is not None:
for entry in bg_playlist.findall("entry"):
entry.set("out", out_tc)
black_producer = session.root.find(".//producer[@id='black']")
if black_producer is not None:
black_producer.set("out", out_tc)


Comment on lines +473 to +476
# Fix tractor out before rendering — without this melt renders the full
# 4-hour background track instead of the actual content duration.
_set_tractor_out(session)

Comment on lines +415 to +421
def _set_tractor_out(session: Session) -> None:
"""Set tractor out= to actual timeline duration before passing to melt.

The tractor is created with out="00:00:00.000" and never updated as clips
are added. Without this fix, melt falls back to the longest track in the
multitrack — the 4-hour black background — and renders a 4-hour file.
"""
Comment on lines +442 to +443
in_f = timecode_to_frames(child.get("in", "0"), fps_num, fps_den)
out_f = timecode_to_frames(child.get("out", "0"), fps_num, fps_den)
@yuh-yang
Copy link
Collaborator

are all items in the test plan passed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants