Skip to content

Support variable length sgpd boxes in fMPEG#3178

Closed
dimitry-unified-streaming wants to merge 0 commit into
androidx:releasefrom
dimitry-unified-streaming:fix-variable-length-sgpd-1
Closed

Support variable length sgpd boxes in fMPEG#3178
dimitry-unified-streaming wants to merge 0 commit into
androidx:releasefrom
dimitry-unified-streaming:fix-variable-length-sgpd-1

Conversation

@dimitry-unified-streaming
Copy link
Copy Markdown

For sgpd boxes with version >= 1, the default_length field is zero if the length of the following sample group entries is variable.

Since the FragmentedMp4Extractor only supports one entry, skip the description_length field if applicable (e.g. when version >= 1 and default_length == 0), instead of throwing an error.

For parsing the following CencSampleEncryptionInformationGroupEntry, this should make no difference.

Issue: #3177

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@microkatz
Copy link
Copy Markdown
Contributor

@dimitry-unified-streaming

Thank you for creating a PR for this feature! Would you please write some unit tests providing content with variable length sgpd boxes?

@google-oss-bot
Copy link
Copy Markdown
Collaborator

Hey @dimitry-unified-streaming. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@dimitry-unified-streaming
Copy link
Copy Markdown
Author

I've been trying to add a test, but I'm running into an error that I don't fully understand:

deduplicateConsecutiveFormats=false so TrackOutput must receive at least one sampleMetadata() call between format() calls.
java.lang.IllegalStateException: deduplicateConsecutiveFormats=false so TrackOutput must receive at least one sampleMetadata() call between format() calls.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:513)
	at androidx.media3.test.utils.FakeTrackOutput.format(FakeTrackOutput.java:90)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor$TrackBundle.updateDrmInitData(FragmentedMp4Extractor.java:2341)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor.onMoofContainerAtomRead(FragmentedMp4Extractor.java:913)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor.onContainerAtomRead(FragmentedMp4Extractor.java:784)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor.processAtomEnded(FragmentedMp4Extractor.java:753)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor.readAtomPayload(FragmentedMp4Extractor.java:748)
	at androidx.media3.extractor.mp4.FragmentedMp4Extractor.read(FragmentedMp4Extractor.java:581)
	at androidx.media3.test.utils.TestUtil.extractAllSamplesFromByteArray(TestUtil.java:611)
	at androidx.media3.test.utils.TestUtil.extractAllSamplesFromFile(TestUtil.java:574)
	at androidx.media3.extractor.mp4.FragmentedMp4ExtractorNonParameterizedTest.extract_h264WithVariableLengthSgpdBox(FragmentedMp4ExtractorNonParameterizedTest.java:134)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:524)
	at org.robolectric.internal.SandboxTestRunner.executeInSandbox(SandboxTestRunner.java:494)
	at org.robolectric.internal.SandboxTestRunner.access$900(SandboxTestRunner.java:67)
	at org.robolectric.internal.SandboxTestRunner$7.evaluate(SandboxTestRunner.java:442)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.robolectric.internal.SandboxTestRunner.access$600(SandboxTestRunner.java:67)
	at org.robolectric.internal.SandboxTestRunner$6.evaluate(SandboxTestRunner.java:333)
	at org.robolectric.internal.SandboxTestRunner$3.evaluate(SandboxTestRunner.java:233)
	at org.robolectric.internal.SandboxTestRunner$5.lambda$evaluate$0(SandboxTestRunner.java:317)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:101)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Anybody have an idea what I can do to work around this? The test I'm adding looks like:

  @Test
  public void extract_h264WithVariableLengthSgpdBox() throws Exception {
    FragmentedMp4Extractor extractor =
        new FragmentedMp4Extractor(SubtitleParser.Factory.UNSUPPORTED);
    FakeExtractorOutput output =
        TestUtil.extractAllSamplesFromFile(
            extractor,
            ApplicationProvider.getApplicationContext(),
            "media/mp4/sample_fragmented_variable_length_sgpd.mp4");

    DumpFileAsserts.assertOutput(
        ApplicationProvider.getApplicationContext(),
        output,
        "extractordumps/mp4/fragmented_variable_length_sgpd.mp4");
  }

@dimitry-unified-streaming dimitry-unified-streaming force-pushed the fix-variable-length-sgpd-1 branch 2 times, most recently from cb7fb46 to 2c0a948 Compare May 19, 2026 09:25
@dimitry-unified-streaming
Copy link
Copy Markdown
Author

@microkatz let me know if anything else is needed. Do you require the commits to be squashed?

@google-oss-bot
Copy link
Copy Markdown
Collaborator

Since there haven't been any recent updates here, I am going to close this issue.

@dimitry-unified-streaming if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@dimitry-unified-streaming
Copy link
Copy Markdown
Author

Hum, the bot closed the issue as if there haven't been any updates, but there were? :)

@icbaker
Copy link
Copy Markdown
Collaborator

icbaker commented May 27, 2026

Please can you re-target this PR against the main branch.

@dimitry-unified-streaming
Copy link
Copy Markdown
Author

Hm, GitHub doesn't seem to have figured out that I rebased against main? Not sure how I can fix this broken PR, maybe I should submit a new fresh one?

@dimitry-unified-streaming
Copy link
Copy Markdown
Author

I can't edit or retarget this pull request, I will open a new one instead.

@dimitry-unified-streaming
Copy link
Copy Markdown
Author

Submitted #3243 as a replacement, @icbaker

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.

4 participants