Repository navigation
feat: decode video files from memory and accept them in the server's vid_gen #2447
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
base: master
Are you sure you want to change the base?
Changes from all commits
5156025
da4399b
c295016
2afdaea
24fb989
d66e31d
d1747d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include "api.h" | ||
|
|
||
| #include "dgl/ops/video.h" | ||
|
|
||
| sd_status_t sd_video_decode(const void* data, | ||
| size_t size, | ||
| int fps, | ||
| size_t max_frames, | ||
| sd_tensor_t** frames_out, | ||
| sd_tensor_t** samples_out, | ||
| uint32_t* sample_rate_out) { | ||
| if (frames_out) | ||
| *frames_out = nullptr; | ||
| if (samples_out) | ||
| *samples_out = nullptr; | ||
| if (sample_rate_out) | ||
| *sample_rate_out = 0; | ||
| return sd::api::call([&] { | ||
| if (!data || !size || !frames_out || fps < 0 || fps > 1000000) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AVI frame-count arithmetic wraps at the accepted FPS limit.
Compute the frame count without wrapping. The result must equal Location:
|
||
| return sd::api::error(SD_STATUS_INVALID_ARGUMENT, nullptr, "data, size and frames_out are required, and fps must be 0 to 1000000"); | ||
| sd::dgl::ops::VideoSource source(data, size); | ||
| auto video = sd::dgl::ops::load_video(source, max_frames, fps, 1, samples_out != nullptr); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if (samples_out && video.audio.samples) { | ||
| *samples_out = sd_tensor_retain(video.audio.samples.get()); | ||
| if (sample_rate_out) | ||
| *sample_rate_out = uint32_t(video.audio.sample_rate); | ||
| } | ||
| *frames_out = sd_tensor_retain(video.frames.get()); | ||
| return SD_STATUS_OK; | ||
| }); | ||
| } | ||
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.
Apply the control-video frame limit after Wan frame alignment.
When
video_framesis omitted,control_videodecodes at most six frames (examples/common/common.cpp:2217). Wan aligns the output to nine frames. The VACE template then pads control frames pastcontrol_countwith the constant0.5. Output frames seven through nine receive no conditioning from the source video. Passing the same nine frames ascontrol_framesconditions all nine output frames.The control-video limit must cover the aligned output frame count for the selected model, or the difference must be explicitly rejected or reported. Choose the approach that keeps the default
video_framesbehavior consistent with the output length. The parser does not currently know the model version, so the fix must pass that information or move the cap to the generation step.