Skip to content

obs-outputs: File splitting improvements for Hybrid MP4/MOV#13386

Open
derrod wants to merge 2 commits into
obsproject:masterfrom
derrod:hybrid-do-not-drop-last-sample
Open

obs-outputs: File splitting improvements for Hybrid MP4/MOV#13386
derrod wants to merge 2 commits into
obsproject:masterfrom
derrod:hybrid-do-not-drop-last-sample

Conversation

@derrod

@derrod derrod commented May 2, 2026

Copy link
Copy Markdown
Member

Description

Fixes file splitting by ensurnig the last frame of each part is not dropped, and b-frames are accounted for in the timer

Motivation and Context

Address part of #13374.

Originally, before file splitting was introduced, I made the choice to simple ignore the last frame in the packet queue of the muxer, because frame N+1 is required to properly determine the duration and I figured nobody would notice if their recording is one frame short.

However, when using frame splitting this would result in the last frame before a split being dropped. To fix this, we can simply reuse the previous sample's duration for the final sample in a file. Since OBS only does CFR, they should all be identical anyway.

Additionally I discovered while testing that the first split would always be one GOP too long (e.g. 1m2s instead of 1m) due to the fact that b-frames and negative start DTSes were not accounted for. This is also fixed in this PR.

How Has This Been Tested?

Recorded some files, looked at them frame-by-frame to confirm none are missing now.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@derrod derrod added the kind/bug Categorizes issue or PR as related to a bug. label May 2, 2026
@RytoEX RytoEX requested review from PatTheMav and RytoEX May 27, 2026 17:37
Comment on lines +2506 to +2509
const bool final_flush = mux->next_frag_pts == 0;
const size_t end_offset = final_flush ? 0 : 1;

for (size_t i = 0; i < count - end_offset; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If count is the amount of valid encoder packet entries at the memory address of track->packets, then count - 1 is the start address of the last packet.

But when iterating until count - 0 (which would be the case if mux->next_frag_pts is 0), wouldn't you end up with a out-of-bounds access by passing an index past the last element in get_pkt_at?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No because the loop is still less-than, so it will terminate at count - 1 - end_offset.

@github-project-automation github-project-automation Bot moved this to Ready For Review in 33.0 Release Tracker Jul 6, 2026
@Warchamp7 Warchamp7 added this to the OBS Studio 33.0 milestone Jul 6, 2026
@derrod derrod force-pushed the hybrid-do-not-drop-last-sample branch from a2e20e3 to fadb064 Compare July 14, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

Status: Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants