Rendering and export
Exports run in a separate process, frametrellis-render, so that a crash in an encoder can never
take down the editor or lose unsaved work.
Export dialog ─► ExportController ─► RenderJob ──QProcess──► frametrellis-render
▲ (argument list, │ loads the snapshot,
│ no shell) │ RenderRunner (MLT)
└──── "@ft {json}" lines ◄┘ progress / result
Development: sequential export presets
The development batch controller runs one RenderJob at a time using a copy
of the Project captured at batch initiation. It accepts two to five distinct
known preset identifiers, validates each output and refuses any existing
destination. The base filename is suffixed with the preset ID to avoid
collisions. FPS, project-frame range and audio-enable choice are shared;
resolution, CRF, encoder speed, upscaling and bitrate come from each preset.
Every item uses the existing helper, output probing and atomic replace protocol.
The next item starts on the Qt event loop after the prior job has emitted
its terminal signals; never delete a RenderJob from its own stateChanged
handler. Before each queued launch the output path is checked again. The helper also
uses an explicit refuse-existing-output mode at final publication: Windows
MoveFileExW without replace-existing, or a same-directory atomic hard-link
followed by removal of the temporary file on POSIX. If the destination is
created during rendering, the verified new file is not allowed to replace it.
On a filesystem that cannot create hard links, no-replace publication fails
safely rather than falling back to a non-atomic copy.
Failures and cancellations stop subsequent launches. Already completed outputs are never deleted. The queue is an in-memory UI operation, not crash-persistent background scheduling. The editor autosaves recent changes before capturing the batch, while further edits do not enter already queued items. Aggregate progress is (completed jobs + current-job progress) / total jobs, with an independent terminal batch state. These changes are development-only pending full integrated Windows testing; they do not resolve the native export crashes.
RenderJob state machine
Idle ─► Starting ─► Running ─► Succeeded
│ │ └──► Failed
│ └─────► Cancelling ─► Cancelled / Succeeded / Failed
└────► Failed / Cancelling
Succeeded, Failed, Cancelled ─► Starting (retry)
RenderJob::canTransition enforces these transitions and is unit-tested.
What the runner does
- Validates the settings again (empty timeline, offline media, output path rules).
- Picks the first available encoder from
libx264,libopenh264,h264_mf,h264_videotoolbox,mpeg4. - Computes the output canvas, respecting an optional no-upscale policy so a quick 1080p preset does not enlarge a smaller project. The timeline graph is always built at the original project FPS, preserving clip positions, source trims, keyframes, transitions, audio and subtitles.
- When Export FPS differs, a second MLT profile and a
timeremaplink convert the graph by timestamp to the output FPS. The link duplicates or drops picture frames as needed and resamples audio frame boundaries without speeding up or slowing down the edit. Rational NTSC rates (e.g. 30000/1001) remain exact. Progress counts use the output FPS and rounded-up frame count; the project snapshot remains unchanged. - Encodes with MLT's
avformatconsumer to a hidden.<name>.<token>.part.mp4next to the destination (H.264yuv420pwith CRF and speed preset, AAC audio,+faststart). - Verifies the result by probing it: it must be a video with the expected width, height, FPS and original timeline duration before the existing destination is changed.
- Atomically replaces the destination (
rename/MoveFileExW). An existing file is never touched unless the export succeeded.
Export reliability and diagnostics
The renderer exclusively reserves its private temporary output before creating the avformat consumer. Existing files, directories and dangling symbolic links cannot be used as temporary output. The publication step refuses missing, empty or symbolic-link partials, nonregular destinations and paths in different directories. These checks protect against accidental collisions; they are not a sandbox against another process deliberately modifying files in the output directory.
The helper reports a reservation event immediately after exclusive creation, before constructing the encoder. The editor only removes a failed job's regular partial file after receiving a reservation with that job's exact token. If the helper refuses a collision, sends the wrong token, or exits before reporting ownership, the editor leaves the file alone. A crash between creation and acknowledgement may leave an orphaned partial file; preservation is safer than deleting an unclaimed file.
The editor distinguishes the OS process starting from a valid renderer start message. When all output frames have been reported but the helper has not exited, the dialog indicates finalization and verification instead of implying that the file is ready. After 60 seconds without an advancing frame or a valid start, the progress text describes the delay and offers cancellation. Duplicate progress messages do not restart that timer. This is informational: slow media and long encodes are not automatically killed. The existing cancellation watchdog remains responsible for a helper that refuses to stop.
The single-export controller owns the active job before it emits its initial Starting state. An immediate Cancel therefore reaches the current job, including before the process has a writable stdin pipe. Terminal notifications are deferred until the job's signal stack unwinds, so a completion handler can reset or retry without destroying an executing RenderJob. A pending terminal notification keeps the controller busy until it is delivered.
Failure diagnostics include the last accepted frame count, elapsed time, encoder, valid-start and completion status, together with the existing bounded stderr tail. An empty encoder output additionally reports the selected canvas, FPS and audio option. These diagnostics help investigate startup/encoder faults without claiming that all native failures have been resolved.
Cancellation: the job writes cancel to the helper's stdin (the helper also stops when stdin is
closed, for example because the editor crashed, and on SIGINT/SIGTERM). The helper stops the
consumer and deletes the partial file. If it does not exit within the grace period it is killed.
A cooperating helper exits with the dedicated cancellation code (3); the editor also records
its own watchdog-initiated kill as cancellation. A helper that instead reports a nonzero
failure or crashes during cancellation is Failed, not silently marked Cancelled: its exit
code and bounded stderr remain available for debugging. Tests exercise both paths without
using real media or intentionally generating a native crash dump.
The render helper supports --fps match (default), whole-number rates, decimals
such as 29.97 (normalised to 30000/1001) and exact fractions such as
--fps 24000/1001. Requests outside 1–240 fps fail validation. No output FPS
change can modify the saved project frame rate.
Protocol
One JSON object per line on stdout, each prefixed with @ft so that unrelated output from
libraries cannot be mistaken for an event:
@ft {"event":"reserved","token":"<render-token>"}
@ft {"event":"started","encoder":"libx264","total":250}
@ft {"event":"progress","frame":120,"total":250}
@ft {"event":"finished","output":"/path/out.mp4"}
@ft {"event":"error","message":"…","detail":"…"}
@ft {"event":"cancelled"}
Exit codes: 0 success, 1 failure, 2 bad arguments, 3 cancelled.
Read-only project inspection
The render helper can inspect a saved project without starting MLT, decoding media, rendering an export or modifying the project:
frametrellis-render --inspect-project --project /path/to/edit.ftproj
It emits a single @ft JSON project_inspection event containing track,
clip and media availability counts, the sequence dimensions (sequenceWidth,
sequenceHeight), the exact rational frameRate (for example 30000/1001),
durationFrames, and a formatted durationTimecode. The timecode uses the
same automatic drop-frame convention as the editor at 29.97/59.94 fps.
Selected fields from a 160x90, 25 fps, 40-frame sequence are shown below;
the actual event also includes the remaining project summary fields:
@ft {"event":"project_inspection","sequenceWidth":160,"sequenceHeight":90,"frameRate":"25/1","durationFrames":40,"durationTimecode":"00:00:01:15"}
The event is additive and intended for local tools and preflight scripts. It contains no source file paths or imported media names. It reports saved project state, not whether a future export will succeed; offline/used media counts can help identify missing sources before rendering.
Known engine quirks handled here
- MLT's parallel frame rendering in the avformat consumer (
real_time < 0) produced corrupt (NaN) audio with MLT 7.22 on Linux and MLT 7.40 on Windows, which made the AAC encoder fail. FrameTrellis therefore renders frames sequentially (real_time = 0); the video encoder still uses several threads. The v1.2.2 quick presets use FFmpeg/libx264's faster encoder modes, not parallel frame rendering. - MSYS2's MLT lists the libraries of its "plus" module (FFTW, libebur128) as optional. Without
them the module does not load and the
affinetransition is missing, so the Windows build installs and bundles them. MLT'scompositetransition is not used as a fallback because it draws black frames with current releases. - MLT 7.42 with FFmpeg 6.1 registers
avfilter.eqbut cannot run it; the engine runs a one-frame self-test at startup and hides picture adjustments when it fails. - MLT's FFmpeg producer returns blank frames for repeated seeks in still images, so stills use FrameTrellis' own Qt-based MLT producer.
This page is generated from docs/architecture/rendering.md in the repository. Found a mistake? Open an issue.