Repository navigation
Reject video frames whose size or pixel format differs from the encoder - #109
Merged
Merged
Conversation
A filter such as scale with eval=frame can shrink frames mid-stream. FFmpeg 9.0.2 and older pass such a frame to encoders that read it at the size they opened with. FFmpeg 9.0.3 rejects it, but a source build links the host FFmpeg, so exmpeg checks each frame itself and returns :unsupported.
This was referenced Dec 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before
A source build against FFmpeg 9.0.2, a 320x240 clip, and
video_filter: "scale=w='if(lt(n,5),iw,iw/2)':h='if(lt(n,5),ih,ih/2)':eval=frame":Problem
A
:video_filtercan shrink the frames mid-stream. exmpeg opens the encoder once at the size of the first frames, and FFmpeg 9.0.2 and older hand it the smaller frame anyway.mpeg4,libvpx-vp9, andffv1return ok, and only x264 notices that the frame's stride is too small for its width.FFmpeg 9.0.3 rejects such a frame, so the precompiled NIFs of 0.8.0 return
:encode_error. A source build links the host FFmpeg, and Arch still ships 9.0.2.After
The README now says to use FFmpeg 9.0.3 or newer for untrusted input in a source build.
Cause, design, tests
transcode.rs:drain_filter_and_encodesent every buffersink frame to the encoder. The encoder takes its size and pixel format from the buffersink once, after the graph config, so nothing compared later frames with it. The gap exists since the first release, which added:video_filter.The check compares each frame's width, height, and pixel format with the encoder right before
send_frame. It returnsunsupported, because the output stream has one size, and the same error fits a source whose resolution changes under a filter that keeps the size. A build-time floor of FFmpeg 9.0.3 would also close this, but it would break every source build on Arch and the dev setup inAGENTS.mduntil Arch ships 9.0.3. The other encoder paths don't need the check:extract_frameallocates its own frame at the encoder's size, and the audio paths keep FFmpeg's ownframe_sizecheck.The new integration test
transcode returns an error when a :video_filter changes the frame size mid-streamfailed with{:ok, _}against FFmpeg 9.0.2 before the fix and passes after. The full suite passes with 110 tests, and so do clippy, rustfmt, and credo.I also diffed
libavfilterof 9.0.2 and 9.0.3 and found no new filter and no new option that opens a file, sofilter_io.rsstays as it is. The diff is 51 lines.