Skip to content

feat: implement soft threshold for video fragmentation#58

Merged
gkozlenko merged 1 commit intomasterfrom
soft-threshold-fragmentation
Feb 19, 2026
Merged

feat: implement soft threshold for video fragmentation#58
gkozlenko merged 1 commit intomasterfrom
soft-threshold-fragmentation

Conversation

@gkozlenko
Copy link
Owner

Add a 10% tolerance (0.9 threshold) when cutting video fragments to prevent excessive chunk durations. Previously, the splitter strictly waited for a keyframe after exceeding the target duration, often causing significant overshoots.

By allowing cuts slightly before the target duration is reached, resulting chunk sizes align much closer to the requested target. Audio-only streams remain unaffected (1.0 threshold) and are cut strictly at the target due to their high sample granularity.

@gemini-code-assist
Copy link

Summary of Changes

Hello @gkozlenko, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant improvement to video fragmentation by implementing a soft threshold mechanism. This change allows for more precise control over video chunk durations, mitigating the problem of fragments exceeding their target length due to strict keyframe alignment. The modification ensures better adherence to desired fragment sizes for video while maintaining strict adherence for audio, leading to more predictable and efficient media processing.

Highlights

  • Soft Threshold for Video Fragmentation: Implemented a 10% tolerance (0.9 threshold) for cutting video fragments, allowing cuts slightly before the target duration to prevent excessive chunk lengths.
  • Audio Fragmentation Unchanged: Audio-only streams retain a strict 1.0 threshold, ensuring they are cut precisely at the target duration due to their high sample granularity.
  • Improved Chunk Duration Alignment: The new approach ensures that resulting video chunk sizes align much closer to the requested target duration, addressing previous issues of significant overshoots.
  • New Test Coverage: Added a new comprehensive test file for FragmentListBuilder to validate the new fragmentation logic for both video and audio tracks.
Changelog
  • lib/fragment-list-builder.js
    • Added VIDEO_DURATION_THRESHOLD and AUDIO_DURATION_THRESHOLD constants to control fragmentation tolerance.
    • Modified fragment duration calculation to apply a track-specific threshold, allowing video fragments to be cut slightly earlier.
  • test/fragment-list-builder.js
    • Added a new test file to thoroughly test the FragmentListBuilder class.
    • Included test cases for scenarios with no tracks, no samples, and correct splitting for both audio/video and audio-only tracks, verifying the new threshold logic.
  • test/tests.js
    • Included the new fragment-list-builder test file in the main test suite.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

Test Coverage Summary Statistics

  • Lines: 94.96%
  • Statements: 94.98%
  • Functions: 93.35%
  • Branches: 79.14%

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a soft threshold for video fragmentation, which is a nice improvement to get chunk durations closer to the target. The implementation is straightforward and the logic is sound. New constants are introduced for thresholds, which is good practice. I appreciate the addition of comprehensive tests for the new functionality, which cover both video and audio-only scenarios. I have one minor suggestion to improve the test code by reducing duplication.

Add a 10% tolerance (0.9 threshold) when cutting video fragments to
prevent excessive chunk durations. Previously, the splitter strictly
waited for a keyframe after exceeding the target duration, often
causing significant overshoots.

By allowing cuts slightly before the target duration is reached,
resulting chunk sizes align much closer to the requested target.
Audio-only streams remain unaffected (1.0 threshold) and are cut
strictly at the target due to their high sample granularity.
@gkozlenko gkozlenko force-pushed the soft-threshold-fragmentation branch from a710003 to bab88df Compare February 19, 2026 20:23
@gkozlenko gkozlenko merged commit 55d6f86 into master Feb 19, 2026
4 checks passed
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.

1 participant