# BoxParser

Artifact: [androidx.media3:media3-extractor](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/extractor/mp4/BoxParser.java+class:androidx.media3.extractor.mp4.BoxParser)

*** ** * ** ***


```
@UnstableApi
public final class BoxParser
```

<br />

*** ** * ** ***

Utility methods for parsing MP4 format box payloads according to ISO/IEC 14496-12.

## Summary

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#maybeSkipRemainingMetaBoxHeaderBytes(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray meta)` Possibly skips the version and flags fields (1+3 byte) of a full meta box. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseFullBoxFlags(int)(int fullBoxInt)` Parses the box flags out of the additional integer component of a full box. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseFullBoxVersion(int)(int fullBoxInt)` Parses the version number out of the additional integer component of a full box. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Metadata` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseMdtaFromMeta(androidx.media3.container.Mp4Box.ContainerBox)(https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox meta)` Parses a metadata meta box if it contains metadata with handler 'mdta'. |
| `static https://developer.android.com/reference/androidx/media3/container/Mp4TimestampData` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseMvhd(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray mvhd)` Parses an mvhd box (defined in ISO/IEC 14496-12). |
| `static https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseStbl(androidx.media3.extractor.mp4.Track,androidx.media3.container.Mp4Box.ContainerBox,androidx.media3.extractor.GaplessInfoHolder,boolean)( https://developer.android.com/reference/androidx/media3/extractor/mp4/Track track, https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox stblBox, https://developer.android.com/reference/androidx/media3/extractor/GaplessInfoHolder gaplessInfoHolder, boolean omitTrackSampleTable )` Parses an stbl box (defined in ISO/IEC 14496-12). |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/mp4/Track` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseTrak(androidx.media3.container.Mp4Box.ContainerBox,androidx.media3.container.Mp4Box.LeafBox,long,androidx.media3.common.DrmInitData,boolean,boolean)( https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox trak, https://developer.android.com/reference/androidx/media3/container/Mp4Box.LeafBox mvhd, long duration, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData, boolean ignoreEditLists, boolean isQuickTime )` Parses a trak box (defined in ISO/IEC 14496-12). |
| `static https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable>` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseTraks(androidx.media3.container.Mp4Box.ContainerBox,androidx.media3.extractor.GaplessInfoHolder,long,androidx.media3.common.DrmInitData,boolean,boolean,java.util.function.Function<androidx.media3.extractor.mp4.Track,androidx.media3.extractor.mp4.Track>,boolean)( https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox moov, https://developer.android.com/reference/androidx/media3/extractor/GaplessInfoHolder gaplessInfoHolder, long duration, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData, boolean ignoreEditLists, boolean isQuickTime, https://developer.android.com/reference/java/util/function/Function.html<@https://developer.android.com/reference/androidx/media3/common/util/NullableType https://developer.android.com/reference/androidx/media3/extractor/mp4/Track, @https://developer.android.com/reference/androidx/media3/common/util/NullableType https://developer.android.com/reference/androidx/media3/extractor/mp4/Track> modifyTrackFunction, boolean omitTrackSampleTable )` Parse the trak boxes in a moov box (defined in ISO/IEC 14496-12). |
| `static https://developer.android.com/reference/androidx/media3/common/Metadata` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/BoxParser#parseUdta(androidx.media3.container.Mp4Box.LeafBox,boolean)(https://developer.android.com/reference/androidx/media3/container/Mp4Box.LeafBox udtaBox, boolean ignoreArtwork)` Parses a udta box. |

## Public methods

### maybeSkipRemainingMetaBoxHeaderBytes

```
public static void maybeSkipRemainingMetaBoxHeaderBytes(ParsableByteArray meta)
```

Possibly skips the version and flags fields (1+3 byte) of a full meta box.

Boxes of type `https://developer.android.com/reference/androidx/media3/container/Mp4Box#TYPE_meta()` are defined to be full boxes which have four additional bytes for a version and a flags field (see 4.2 'Object Structure' in ISO/IEC 14496-12:2005). QuickTime do not have such a full box structure. Since some of these files are encoded wrongly, we can't rely on the file type though. Instead we must check the 8 bytes after the common header bytes ourselves.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray meta` | The 8 or more bytes following the meta box size and type. |

### parseFullBoxFlags

```
public static int parseFullBoxFlags(int fullBoxInt)
```

Parses the box flags out of the additional integer component of a full box.

### parseFullBoxVersion

```
public static int parseFullBoxVersion(int fullBoxInt)
```

Parses the version number out of the additional integer component of a full box.

### parseMdtaFromMeta

```
public static @Nullable Metadata parseMdtaFromMeta(Mp4Box.ContainerBox meta)
```

Parses a metadata meta box if it contains metadata with handler 'mdta'.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox meta` | The metadata box to decode. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Metadata` | Parsed metadata, or null. |

### parseMvhd

```
public static Mp4TimestampData parseMvhd(ParsableByteArray mvhd)
```

Parses an mvhd box (defined in ISO/IEC 14496-12).

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray mvhd` | Contents of the mvhd box to be parsed. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/container/Mp4TimestampData` | An object containing the parsed data. |

### parseStbl

```
public static TrackSampleTable parseStbl(
    Track track,
    Mp4Box.ContainerBox stblBox,
    GaplessInfoHolder gaplessInfoHolder,
    boolean omitTrackSampleTable
)
```

Parses an stbl box (defined in ISO/IEC 14496-12).

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/mp4/Track track` | Track to which this sample table corresponds. |
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox stblBox` | stbl (sample table) box to decode. |
| `https://developer.android.com/reference/androidx/media3/extractor/GaplessInfoHolder gaplessInfoHolder` | Holder to populate with gapless playback information. |
| `boolean omitTrackSampleTable` | Whether to optimize for metadata retrieval by skipping allocation and population of per-sample arrays in the `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable` | Sample table described by the stbl box. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | Thrown if the stbl box can't be parsed. |

### parseTrak

```
public static @Nullable Track parseTrak(
    Mp4Box.ContainerBox trak,
    Mp4Box.LeafBox mvhd,
    long duration,
    @Nullable DrmInitData drmInitData,
    boolean ignoreEditLists,
    boolean isQuickTime
)
```

Parses a trak box (defined in ISO/IEC 14496-12).

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox trak` | Box to decode. |
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.LeafBox mvhd` | Movie header box, used to get the timescale. |
| `long duration` | The duration in units of the timescale declared in the mvhd box, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the duration should be parsed from the tkhd box. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData` | `https://developer.android.com/reference/androidx/media3/common/DrmInitData` to be included in the format, or `null`. |
| `boolean ignoreEditLists` | Whether to ignore any edit lists in the trak box. |
| `boolean isQuickTime` | True for QuickTime media. False otherwise. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/mp4/Track` | A `https://developer.android.com/reference/androidx/media3/extractor/mp4/Track` instance, or `null` if the track's type isn't supported. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | Thrown if the trak box can't be parsed. |

### parseTraks

```
public static List<TrackSampleTable> parseTraks(
    Mp4Box.ContainerBox moov,
    GaplessInfoHolder gaplessInfoHolder,
    long duration,
    @Nullable DrmInitData drmInitData,
    boolean ignoreEditLists,
    boolean isQuickTime,
    Function<@NullableType Track, @NullableType Track> modifyTrackFunction,
    boolean omitTrackSampleTable
)
```

Parse the trak boxes in a moov box (defined in ISO/IEC 14496-12).

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.ContainerBox moov` | Moov box to decode. |
| `https://developer.android.com/reference/androidx/media3/extractor/GaplessInfoHolder gaplessInfoHolder` | Holder to populate with gapless playback information. |
| `long duration` | The duration in units of the timescale declared in the mvhd box, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the duration should be parsed from the tkhd box. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData` | `https://developer.android.com/reference/androidx/media3/common/DrmInitData` to be included in the format, or `null`. |
| `boolean ignoreEditLists` | Whether to ignore any edit lists in the trak boxes. |
| `boolean isQuickTime` | True for QuickTime media. False otherwise. |
| `https://developer.android.com/reference/java/util/function/Function.html<@https://developer.android.com/reference/androidx/media3/common/util/NullableType https://developer.android.com/reference/androidx/media3/extractor/mp4/Track, @https://developer.android.com/reference/androidx/media3/common/util/NullableType https://developer.android.com/reference/androidx/media3/extractor/mp4/Track> modifyTrackFunction` | A function to apply to the `https://developer.android.com/reference/androidx/media3/extractor/mp4/Track` in the result. |
| `boolean omitTrackSampleTable` | Whether to optimize for metadata retrieval by skipping allocation and population of per-sample arrays in the `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable>` | A list of `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable` instances. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | Thrown if the trak boxes can't be parsed. |

### parseUdta

```
public static Metadata parseUdta(Mp4Box.LeafBox udtaBox, boolean ignoreArtwork)
```

Parses a udta box.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/container/Mp4Box.LeafBox udtaBox` | The udta (user data) box to decode. |
| `boolean ignoreArtwork` | Whether to ignore artwork metadata. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Metadata` | Parsed metadata. |