fix(encode): pad odd dimensions so H.264 encode produces web-ready video - #21
Merged
Merged
Conversation
aris-encode failed on odd-sized ARIS clips (e.g. 924x1765) because libx264 with yuv420p requires even width and height. The encoder failed to open and wrote a 0-byte file, yet the CLI still reported success and exited 0. - Pad each dimension up to the next even number before libx264 (adds at most a 1px border, no rescaling). - Set pix_fmt=yuv420p and movflags=+faststart for reliable browser playback. - Re-raise ffmpeg errors instead of swallowing them (the docstring already documents this), and fix the malformed error log call. - Make the encode CLI count failures and exit non-zero, mirroring aris-convert. - Add a regression test that encodes a real odd-dimension (63x65) clip.
4 tasks
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.
Problem
aris-encode --video-codec h264silently fails on ARIS clips with odddimensions (e.g. 924×1765, a common sonar frame size). libx264 with
yuv420prequires even width and height, so ffmpeg fails to open theencoder:
Worse, the failure was silent:
encode_video_with_h264_codeccaught theffmpeg.Errorand returned normally, and the CLI exited0while leaving a0-byte output file. A whole batch looked successful but produced empty files.
Discovered while converting a 107-clip ARIS selection (all 924×1765) for web
playback — every output was empty.
Fix
pad=ceil(iw/2)*2:ceil(ih/2)*2(adds at most a 1px border, no rescaling). Even-sized inputs are unchanged.
pix_fmt=yuv420pandmovflags=+faststartfor reliablein-browser playback (moov atom moved to the front for progressive streaming).
ffmpeg.Error(the docstring alreadydocuments
Raises: ffmpeg.Error) and fix the malformed error-log call.aris-encodenow counts failures and exits non-zero,mirroring
aris-convert.Test
Adds
test_encodes_odd_dimension_video, which builds a real odd-dimension(63×65) clip the way pyARIS does (MJPEG frames piped to mpeg4 —
cv2.VideoWritersilently rounds odd dims down to even) and asserts the output is non-empty with
even dimensions. This test fails on
mainand passes with the fix.All 77 unit tests pass;
ruff checkandruff format --checkclean.