Skip to content

feat: add -bg-anim flag for per-frame 1-bit animation backgrounds#8

Open
Lufftre wants to merge 1 commit into
Eyevinn:mainfrom
Lufftre:feat/bg-anim
Open

feat: add -bg-anim flag for per-frame 1-bit animation backgrounds#8
Lufftre wants to merge 1 commit into
Eyevinn:mainfrom
Lufftre:feat/bg-anim

Conversation

@Lufftre
Copy link
Copy Markdown

@Lufftre Lufftre commented Feb 19, 2026

Summary

  • Add -bg-anim <file> flag to hi264gen for loading 1-bit animation files as per-frame backgrounds
  • New BitAnim loader in pkg/yuv/bitanim.go reads gzip-compressed packed-bit frames with nearest-neighbor scaling to any output resolution
  • Works with all output formats (264, mp4, y4m, yuv, png, jpg) and composes with text overlay

Format

The .bitanim format is a gzip-compressed binary: 4-byte header (uint16le width, uint16le height in macroblocks) followed by ceil(W*H/8) bytes per frame (1 bit per block, MSB first). Frame count is inferred from data length.

Usage

# Default resolution from animation (width*16 x height*16)
hi264gen -bg-anim animation.bitanim -n 100 -fps 30 -o output.mp4

# Custom resolution (auto-scales)
hi264gen -bg-anim animation.bitanim -w 512 -h 384 -n 100 -fps 30 -o output.mp4

# With text overlay
hi264gen -bg-anim animation.bitanim -w 512 -h 384 -n 100 -fps 30 -text "%03d" -o output.mp4

Test plan

  • All existing tests pass
  • Verified with synthetic 4x3 3-frame test animation (checkerboard/white/black)
  • Tested all output formats: .264, .mp4, .y4m, .png
  • Verified round-trip through hi264dec and ffmpeg
  • Mutual exclusivity with -gi, -gp/-gc, -smpte validated

Load gzip-compressed .bitanim files (uint16le width/height header +
packed 1-bit frames) and use them as per-frame background patterns.
Nearest-neighbor scaling to any output resolution. Compatible with
all output formats and text overlay.
@tobbee
Copy link
Copy Markdown
Collaborator

tobbee commented Feb 21, 2026

Nice extension. However, you need to add some tests, e.g. using a sample file in testdata in order to get the same level of test coverage as the repo currently has.

Is this format used somewhere else, so that there is some example content? Otherwise it may be good to add some script or program to generate it, e.g. by using ffmpeg with an appropriate filter to get the 1-bit content, and then some extra processing steps after that.

One could of course think about many other extensions, but I think that most of them could hopefully be done by using the projects API and not extending the CLI apps themselves. Extending to beyond palette of colors requires some changes, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants