Skip to content

Expose track_in_movie and track_in_preview flags on Tkhd#146

Open
iameli wants to merge 1 commit intokixelated:mainfrom
streamplace:fix/tkhd-track-in-movie
Open

Expose track_in_movie and track_in_preview flags on Tkhd#146
iameli wants to merge 1 commit intokixelated:mainfrom
streamplace:fix/tkhd-track-in-movie

Conversation

@iameli
Copy link

@iameli iameli commented Mar 16, 2026

Ran into this while working on the MUXL spec; I think having track_in_movie set is probably a sensible default. Now we can do that!

From Claude:

The tkhd box has three flag bits: track_enabled (bit 0), track_in_movie (bit 1), and track_in_preview (bit 2). Previously only track_enabled was exposed as a public field. The other two were decoded but discarded, and always written as false on encode.

Add in_movie and in_preview fields to Tkhd so callers can read and write all three flags. Update all test expectations to match the actual flag values in their respective fixtures.

The tkhd box has three flag bits: track_enabled (bit 0),
track_in_movie (bit 1), and track_in_preview (bit 2). Previously
only track_enabled was exposed as a public field. The other two
were decoded but discarded, and always written as false on encode.

Add `in_movie` and `in_preview` fields to Tkhd so callers can
read and write all three flags. Update all test expectations to
match the actual flag values in their respective fixtures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Walkthrough

Two new public boolean fields, in_movie and in_preview, were added to the Tkhd struct. The Tkhd struct definition was extended in src/moov/trak/tkhd.rs with serialization and deserialization logic to populate these fields from the TkhdExt structure during encode and decode operations. All test files that construct Tkhd instances were updated to initialize these new fields with corresponding values, maintaining consistency across test expectations in modules such as av1, bbb, esds, flac, h264, hevc, libavif_anim, uncompressed, and vp9.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: exposing two previously hidden flag fields (track_in_movie and track_in_preview) on the Tkhd struct.
Description check ✅ Passed The description provides clear context about the change, explaining what flags were previously hidden and why exposing them is useful (MUXL spec work and sensible defaults).
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can validate your CodeRabbit configuration file in your editor.

If your editor has YAML language server, you can enable auto-completion and validation by adding # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json at the top of your CodeRabbit configuration file.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/moov/trak/tkhd.rs (1)

198-199: Consider adding a direct serialized-flags assertion in unit tests.

Current tests are round-trip based; adding one direct assertion on the version+flags word would make bit-position regressions easier to catch.

Suggested test hardening
 #[test]
 fn test_tkhd32() {
     let expected = Tkhd {
         creation_time: 100,
         modification_time: 200,
         track_id: 1,
         duration: 634634,
         layer: 0,
         alternate_group: 0,
         volume: 1.into(),
         matrix: Matrix::default(),
         width: 512.into(),
         height: 288.into(),
         enabled: true,
         in_movie: true,
         in_preview: false,
     };
     let mut buf = Vec::new();
     expected.encode(&mut buf).unwrap();
+    // size(4) + kind(4) + version/flags(4)
+    assert_eq!(&buf[8..12], &[0x01, 0x00, 0x00, 0x03]);

     let mut buf = buf.as_ref();
     let decoded = Tkhd::decode(&mut buf).unwrap();
     assert_eq!(decoded, expected);
 }

Also applies to: 223-224

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/moov/trak/tkhd.rs` around lines 198 - 199, Tests currently only
round-trip the TrackHeaderBox; add a direct assertion that the packed
version+flags 32-bit word matches the expected literal to catch bit-position
regressions. In the unit test for TrackHeaderBox (the case that sets in_movie:
true and in_preview: false) call the serializer used (e.g.,
TrackHeaderBox::to_bytes / write_box / serialize) and extract the first 4 bytes
(version+flags) or use the helper that builds the version_and_flags word, then
assert equality against the expected u32 constant (computed from version and the
flag bits). Reference the fields in_movie and in_preview and the TrackHeaderBox
serialization path so the test fails if flag bit positions change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/moov/trak/tkhd.rs`:
- Around line 198-199: Tests currently only round-trip the TrackHeaderBox; add a
direct assertion that the packed version+flags 32-bit word matches the expected
literal to catch bit-position regressions. In the unit test for TrackHeaderBox
(the case that sets in_movie: true and in_preview: false) call the serializer
used (e.g., TrackHeaderBox::to_bytes / write_box / serialize) and extract the
first 4 bytes (version+flags) or use the helper that builds the
version_and_flags word, then assert equality against the expected u32 constant
(computed from version and the flag bits). Reference the fields in_movie and
in_preview and the TrackHeaderBox serialization path so the test fails if flag
bit positions change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 790684be-dab9-4ba2-ac19-d75021888af0

📥 Commits

Reviewing files that changed from the base of the PR and between 3073b3e and 622ca7d.

📒 Files selected for processing (11)
  • src/moov/mod.rs
  • src/moov/trak/tkhd.rs
  • src/test/av1.rs
  • src/test/bbb.rs
  • src/test/esds.rs
  • src/test/flac.rs
  • src/test/h264.rs
  • src/test/hevc.rs
  • src/test/libavif_anim.rs
  • src/test/uncompressed.rs
  • src/test/vp9.rs

Copy link
Collaborator

@bradh bradh left a comment

Choose a reason for hiding this comment

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

LGTM.

A round-trip test would be nice, but I can try to find some time for that later.

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