Skip to content

bug: Black frame appears at end of rendered video (FFmpeg/editly sizing issue) #148

Description

@SecurityQQ

Bug Report

Description

Some rendered videos have a black frame at the end. This appears to be a duration/sizing mismatch in the FFmpeg pipeline (editly layer) — when the source clip doesn't perfectly fill the expected duration, a black frame gets appended to pad the remaining time.

Reproduction

Example video with black last frame:
https://su.varg.ai/renders/1772764472485_yyzfle0c.mp4

Root cause (needs investigation)

Likely one of:

  1. Editly clip duration rounding — the clip duration in the editly spec is slightly longer than the actual source video, causing FFmpeg to pad with black
  2. FFmpeg trim filtercutTo or duration calculation results in a fractional-frame overshoot
  3. Concat demuxer — when concatenating clips, a duration mismatch between the editly spec and the actual media causes a black frame gap
  4. FPS mismatch — source video FPS doesn't divide evenly into the target duration, leaving a partial frame that renders as black

Where to investigate

  • templates/sdk/src/ai-sdk/providers/editly/index.ts — clip duration calculation (cutTo - cutFrom), trim filters, concat logic
  • FFmpeg filter chain construction — check if -shortest or padding flags are involved
  • Check if tpad or similar filter is being applied implicitly

Expected behavior

Videos should end cleanly on the last real frame with no black padding. If a source clip is slightly shorter than the specified duration, the last frame should be held (freeze frame) rather than showing black.

Suggested fix directions

  • Add -shortest flag to FFmpeg output if not already present
  • Clamp clip durations to actual source media duration
  • Use tpad=stop_mode=clone to freeze the last frame instead of showing black
  • Investigate rounding strategy for frame-accurate trimming

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions