Skip to content

fix(encode): reject a codec the container cannot hold, before rendering - #194

Merged
LeadcodeDev merged 1 commit into
mainfrom
fix/codec-container-guard
Aug 12, 2026
Merged

fix(encode): reject a codec the container cannot hold, before rendering#194
LeadcodeDev merged 1 commit into
mainfrom
fix/codec-container-guard

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #191.

What

$ rustmotion render -f c.json -o out.mp4 --codec prores
[vf#0:0 @ 0x...] Task finished with error code: -22 (Invalid argument)
[out#0/mp4 @ 0x...] Nothing was written into output file, because at least one
                    of its streams received no packets.

The codec/container pair was never validated: rustmotion rendered every frame, handed the result to ffmpeg, and passed ffmpeg's internals through. No output file was produced.

--codec prores is the documented recommendation for dark gradients (CLAUDE.md) and .mp4 is the default extension, so the two together are a natural mistake — and the cost of discovering it was a complete render.

After

$ rustmotion render -f c.json -o out.mp4 --codec prores
Error: codec 'prores' cannot be written into a .mp4 file — use -o <file>.mov,
       or drop --codec for H.264

$ rustmotion render -f c.json -o out.mov --codec prores    # 28 KB, written

How

check_codec_container is a pure lookup in encode::video::formats, called before the first frame in both cmd_render and cmd_watch. Design choices worth flagging:

  • An unknown codec passes through. Second-guessing ffmpeg would block combinations it supports; the check only refuses pairs it knows are wrong.
  • gif / png-seq / raw are left alone — they have their own encode path and never reach the ffmpeg muxer.
  • The message names the working container rather than restating the failure.

Tests

Five, no ffmpeg needed: prores/mp4 refused with .mov named, the documented pairs accepted, vp9/mp4 refused, unknown codecs passed through, own-path containers untouched.

cargo test --workspace green, cargo fmt --check and cargo clippy --all-targets -- -D warnings clean.

rustmotion render --codec prores -o out.mp4 rendered the whole video, handed
it to ffmpeg, and surfaced ffmpeg's internals:

    [vf#0:0] Task finished with error code: -22 (Invalid argument)
    [out#0/mp4] Nothing was written into output file, because at least one of
                its streams received no packets.

with no output file to show for it. The pair was never checked. --codec prores
is the documented recommendation for dark gradients and .mp4 is the extension
everyone types, so the combination is a natural mistake, and the cost of
finding out was a full render.

check_codec_container is a pure lookup run before the first frame in both
cmd_render and cmd_watch. It names what works rather than restating the
failure. An unknown codec passes through untouched — guessing would block
combinations ffmpeg supports — and gif/png-seq/raw never reach the muxer.
@LeadcodeDev
LeadcodeDev merged commit 43d1d1a into main Aug 12, 2026
3 checks passed
@LeadcodeDev
LeadcodeDev deleted the fix/codec-container-guard branch August 12, 2026 15:25
LeadcodeDev added a commit that referenced this pull request Aug 12, 2026
The guard added in #194 ran before cmd_render's single-frame branch, so

    rustmotion render -f s.json -o f.png --frame 0

failed with "codec 'h264' cannot be written into a .png file". A --frame
still is written by render_single_frame and never reaches an encoder, so the
codec is not part of that operation — the check does not apply.

This is a regression I shipped in #194: every local check passed because none
of them exercised --frame, which is the documented way to preview a scene.
@LeadcodeDev LeadcodeDev added the bug Something isn't working label Aug 12, 2026
@LeadcodeDev LeadcodeDev self-assigned this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--codec prores into a .mp4 dumps raw ffmpeg errors and writes nothing

1 participant