Skip to content

Conversation

@skidder
Copy link
Contributor

@skidder skidder commented Oct 30, 2025

Enables extraction of multiple frames from video sources (MP4, MOV, WEBM) at configurable sample intervals to produce animated image outputs (animated WebP, GIF). Introduces VideoFrameSampleInterval option to control frame sampling rate and extends decoder with VideoDecoder interface for multi-frame extraction. Also improves memory alignment handling for better SIMD performance.

@skidder skidder force-pushed the skidder/video-to-animated-webp branch 5 times, most recently from d7d5c5a to ebd2ad6 Compare October 31, 2025 21:33
Enables extraction of multiple frames from video sources (MP4, MOV, WEBM) at configurable
sample intervals to produce animated image outputs (animated WebP, GIF). Introduces
VideoFrameSampleInterval option to control frame sampling rate and extends decoder with
VideoDecoder interface for multi-frame extraction. Also improves memory alignment handling
for better SIMD performance.
@skidder skidder force-pushed the skidder/video-to-animated-webp branch from ebd2ad6 to c6efeb7 Compare October 31, 2025 21:52
@@ -0,0 +1,483 @@
package lilliput
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing there are third party libs like "testify" that can provide more idiomatic asserts, but given our direction with go it's probably not in scope. Just noting.

return h.contentLength
}

// calculateAlignedStride computes a 32-byte aligned stride for the given width and channel count.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm used to seeing a function called to detect the actual memory alignment requirements of the platform.

32 byte alignment will probably work but isn't strictly correct unless we explicitly assume the data type is 8 bits per pixel, plus the buffer should be allocated with some sort of aligned malloc function.

Maybe we add some sort of comment re: the platforms we're expecting this function to work with or have tested with otherwise.

avcodec.cpp Outdated
int video_stream_index;

// Multi-frame extraction state
float frame_sample_interval; // Interval between frames in seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my instinct is to use integers for exact precision unless there's a specific need for floats.

int delay_ms = (int)(delay_seconds * 1000.0);
// Validate delay is reasonable (between 1ms and 60 seconds)
// Use sample interval if delay is out of bounds
if (delay_ms > 0 && delay_ms <= 60000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the output delay per frame? if so arguably 1ms is pretty low. What's a reasonable default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, yeah, in practice we'll use something like 100-200ms. I don't think we want to have a default since the feature is enabled by specifying a positive non-zero value.

Change VideoFrameSampleInterval from float64 seconds to int milliseconds across the codebase. This provides more precision and clearer semantics for frame sampling intervals.

- Update avcodec decoder to track frame_sample_interval_ms as int
- Update Go API to use VideoFrameSampleIntervalMs int
- Update all test cases to use millisecond values
- Fix outdated documentation comments
@skidder skidder requested a review from LostVector November 5, 2025 23:28
@skidder skidder merged commit 686cbce into discord:master Nov 7, 2025
5 checks passed
@skidder skidder deleted the skidder/video-to-animated-webp branch November 7, 2025 16:25
skidder added a commit that referenced this pull request Dec 2, 2025
skidder added a commit that referenced this pull request Dec 2, 2025
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