-
Notifications
You must be signed in to change notification settings - Fork 125
feat: Support for video-to-animated-image conversion with frame sampling #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support for video-to-animated-image conversion with frame sampling #273
Conversation
d7d5c5a to
ebd2ad6
Compare
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.
ebd2ad6 to
c6efeb7
Compare
| @@ -0,0 +1,483 @@ | |||
| package lilliput | |||
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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.