ATH-MaaS/Pixelle-Video · error · RuntimeError

Failed to pad video

Error message

Failed to pad video: {error_msg}

What it means

_pad_video_to_duration catches ffmpeg.Error from the padding step (extending the last frame or adding black frames to reach target duration) and re-raises RuntimeError with ffmpeg's stderr. It signals the ffmpeg pad filtergraph failed, distinct from the trim failure at the same call site.

Solutions

  1. Inspect the stderr in the message for the specific filter/codec complaint
  2. Try the other pad_strategy ('black' vs 'freeze') if one fails on this codec
  3. Re-encode/normalize the input video to h264/yuv420p before padding
  4. Verify target_duration > 0 and ffmpeg supports the required filters (`ffmpeg -filters | grep tpad`)

Example fix

// before
service._pad_video_to_duration('clip.mkv', 12.5, pad_strategy='freeze')
// after
service._pad_video_to_duration('clip.mkv', 12.5, pad_strategy='black')  # fallback strategy
Defensive patterns

Strategy: fallback

Validate before calling

import shutil

def ffmpeg_available() -> bool:
    return shutil.which('ffmpeg') is not None

def validate_pad_target(duration: float) -> float:
    if not (duration > 0):
        raise ValueError(f'target_duration must be positive: {duration}')
    return duration

Try / catch

try:
    padded = service._pad_video_to_duration(video, target, pad_strategy='freeze')
except RuntimeError:
    padded = service._pad_video_to_duration(video, target, pad_strategy='black')

Prevention

When it happens

Trigger: merge_audio_video calls _pad_video_to_duration and ffmpeg fails: input codec/filter incompatibility with tpad or the freeze strategy, invalid target_duration (<= 0), unwritable output path, or missing ffmpeg binary.

Common situations: Videos with codecs the pad filter chain cannot handle (e.g. unusual pixel formats with 'freeze' strategy); duration values parsed from float rounding errors; ffmpeg build lacking needed filters.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/004a31268a4edea4. Report an issue: GitHub.

Appendix: source

Thrown at pixelle_video/services/video.py:1003

                
                (
                    ffmpeg
                    .output(
                        video_stream,
                        output,
                        vcodec='libx264',
                        preset='fast',
                        crf=23
                    )
                    .overwrite_output()
                    .run(capture_stdout=True, capture_stderr=True, quiet=True)
                )
            
            return output
        except ffmpeg.Error as e:
            error_msg = e.stderr.decode() if e.stderr else str(e)
            logger.error(f"FFmpeg error padding video: {error_msg}")
            raise RuntimeError(f"Failed to pad video: {error_msg}")

View on GitHub (pinned to 848b054e4f)