# Mp4Extractor

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/Mp4Extractor.java+class:androidx.media3.extractor.mp4.Mp4Extractor)

*** ** * ** ***


```
@UnstableApi
public final class Mp4Extractor implements Extractor
```

<br />

*** ** * ** ***

Extracts data from the MP4 container format.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(flag = true, value = ) public annotation https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor.Flags` Flags controlling the behavior of the extractor. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/androidx/media3/extractor/ExtractorsFactory` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FACTORY()` **This field is deprecated.** Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#newFactory(androidx.media3.extractor.text.SubtitleParser.Factory)` instead. <br /> |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_DISABLE_ARTWORK_METADATA() = 512` Flag to disable parsing of artwork metadata. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_DISABLE_HAGC_METADATA() = 1024` Flag to disable parsing of HAGC (ST 2094-50) metadata. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_EMIT_RAW_MEBX_DATA() = 4096` Flag to emit `mebx` tracks as raw `https://developer.android.com/reference/androidx/media3/common/MimeTypes#APPLICATION_MEBX()` tracks without converting `it35` keys to `https://developer.android.com/reference/androidx/media3/common/MimeTypes#APPLICATION_ITUT_T35()` or unboxing sample payloads, regardless of whether `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_DISABLE_HAGC_METADATA()` is set. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_EMIT_RAW_SUBTITLE_DATA() = 16` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_MARK_FIRST_VIDEO_TRACK_WITH_MAIN_ROLE() = 8` Flag to mark the first video track encountered as `https://developer.android.com/reference/androidx/media3/common/C#ROLE_FLAG_MAIN()` and all subsequent video tracks as `https://developer.android.com/reference/androidx/media3/common/C#ROLE_FLAG_ALTERNATE()`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_OMIT_TRACK_SAMPLE_TABLE() = 256` Flag to omit allocating and populating the large per-sample arrays (offsets, sizes, timestamps, flags) within `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_READ_AUXILIARY_TRACKS() = 64` Flag to extract the auxiliary tracks from the MP4 With Auxiliary Tracks Extension (MP4-AT) file format. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_READ_SEF_DATA() = 4` Flag to extract `https://developer.android.com/reference/androidx/media3/extractor/metadata/mp4/SlowMotionData` metadata from Samsung Extension Format (SEF) slow motion videos. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_READ_XMP_METADATA() = 2048` Flag to extract Adobe XMP metadata. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_WORKAROUND_IGNORE_EDIT_LISTS() = 1` Flag to ignore any edit lists in the stream. |

| ### Public constructors |
|---|
| `[Mp4Extractor](https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory)` instead <br /> |
| `[Mp4Extractor](https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(int))(@https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor.Flags int flags)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory,int)` instead <br /> |
| `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory)(https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory)` Creates a new extractor for unfragmented MP4 streams. |
| `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory,int)( https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory, @https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor.Flags int flags )` Creates a new extractor for unfragmented MP4 streams, using the specified flags to control the extractor's behavior. |

| ### Public methods |
|---|---|
| `long[]` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#getSampleTimestampsUs(int)(int trackId)` Returns the list of sample timestamps of a `trackId`, in microseconds. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/extractor/SniffFailure>` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#getSniffFailureDetails()()` Returns additional details about the last call to `https://developer.android.com/reference/androidx/media3/extractor/Extractor#sniff(androidx.media3.extractor.ExtractorInput)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#init(androidx.media3.extractor.ExtractorOutput)(https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput output)` Initializes the extractor with an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput`. |
| `static https://developer.android.com/reference/androidx/media3/extractor/ExtractorsFactory` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#newFactory(androidx.media3.extractor.text.SubtitleParser.Factory)(https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory)` Creates a factory for `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor` instances with the provided `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory`. |
| `int` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)(https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, https://developer.android.com/reference/androidx/media3/extractor/PositionHolder seekPosition)` Extracts data read from a provided `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#release()()` Releases all kept resources. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#seek(long,long)(long position, long timeUs)` Notifies the extractor that a seek has occurred. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#sniff(androidx.media3.extractor.ExtractorInput)(https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input)` Returns whether this extractor can extract samples from the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`, which must provide data from the start of the stream. |

### Inherited Constants

From [androidx.media3.extractor.Extractor](https://developer.android.com/reference/androidx/media3/extractor/Extractor) `static final int` `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_CONTINUE() = 0`

Returned by `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` if the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` passed to the next `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` is required to provide data continuing from the position in the stream reached by the returning call.
`static final int` `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_END_OF_INPUT() = -1`

Returned by `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` if the end of the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` was reached.
`static final int` `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_SEEK() = 1`

Returned by `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` if the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` passed to the next `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` is required to provide data starting from a specified position in the stream.

### Inherited methods

From [androidx.media3.extractor.Extractor](https://developer.android.com/reference/androidx/media3/extractor/Extractor) `https://developer.android.com/reference/androidx/media3/extractor/Extractor` `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/SideEffectFree.html
https://developer.android.com/reference/androidx/media3/extractor/Extractor#getUnderlyingImplementation()()`

Returns the 'real' `Extractor` implementation if this is a delegating instance, or `
this` if this instance does the extraction directly without delegating (the default behaviour).

## Constants

### FACTORY

```
public static final ExtractorsFactory FACTORY
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#newFactory(androidx.media3.extractor.text.SubtitleParser.Factory)` instead.

### FLAG_DISABLE_ARTWORK_METADATA

```
public static final int FLAG_DISABLE_ARTWORK_METADATA = 512
```

Flag to disable parsing of artwork metadata.

### FLAG_DISABLE_HAGC_METADATA

```
public static final int FLAG_DISABLE_HAGC_METADATA = 1024
```

Flag to disable parsing of HAGC (ST 2094-50) metadata.

### FLAG_EMIT_RAW_MEBX_DATA

```
public static final int FLAG_EMIT_RAW_MEBX_DATA = 4096
```

Flag to emit `mebx` tracks as raw `https://developer.android.com/reference/androidx/media3/common/MimeTypes#APPLICATION_MEBX()` tracks without converting `it35` keys to `https://developer.android.com/reference/androidx/media3/common/MimeTypes#APPLICATION_ITUT_T35()` or unboxing sample payloads, regardless of whether `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#FLAG_DISABLE_HAGC_METADATA()` is set.

### FLAG_EMIT_RAW_SUBTITLE_DATA

```
public static final int FLAG_EMIT_RAW_SUBTITLE_DATA = 16
```

### FLAG_MARK_FIRST_VIDEO_TRACK_WITH_MAIN_ROLE

```
public static final int FLAG_MARK_FIRST_VIDEO_TRACK_WITH_MAIN_ROLE = 8
```

Flag to mark the first video track encountered as `https://developer.android.com/reference/androidx/media3/common/C#ROLE_FLAG_MAIN()` and all subsequent video tracks as `https://developer.android.com/reference/androidx/media3/common/C#ROLE_FLAG_ALTERNATE()`.

### FLAG_OMIT_TRACK_SAMPLE_TABLE

```
public static final int FLAG_OMIT_TRACK_SAMPLE_TABLE = 256
```

Flag to omit allocating and populating the large per-sample arrays (offsets, sizes, timestamps, flags) within `https://developer.android.com/reference/androidx/media3/extractor/mp4/TrackSampleTable`. This is used to reduce memory consumption in metadata retrieval scenarios where individual sample data is not required.

### FLAG_READ_AUXILIARY_TRACKS

```
public static final int FLAG_READ_AUXILIARY_TRACKS = 64
```

Flag to extract the auxiliary tracks from the MP4 With Auxiliary Tracks Extension (MP4-AT) file format.

Either primary video tracks or auxiliary tracks (but not both) will be extracted based on the flag.

If the flag is set but the auxiliary tracks are not present, then it fallbacks to extract primary tracks instead.

See the file format at https://developer.android.com/media/platform/mp4-at-file-format.

### FLAG_READ_SEF_DATA

```
public static final int FLAG_READ_SEF_DATA = 4
```

Flag to extract `https://developer.android.com/reference/androidx/media3/extractor/metadata/mp4/SlowMotionData` metadata from Samsung Extension Format (SEF) slow motion videos.

### FLAG_READ_XMP_METADATA

```
public static final int FLAG_READ_XMP_METADATA = 2048
```

Flag to extract Adobe XMP metadata.

If set, the extractor will peek for a top-level uuid box containing XMP metadata immediately following the moov box, and expose it inside `https://developer.android.com/reference/androidx/media3/common/Format#metadata()` for all tracks.

### FLAG_WORKAROUND_IGNORE_EDIT_LISTS

```
public static final int FLAG_WORKAROUND_IGNORE_EDIT_LISTS = 1
```

Flag to ignore any edit lists in the stream.

## Public constructors

### Mp4Extractor

```
public [Mp4Extractor](https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory)` instead

### Mp4Extractor

```
public [Mp4Extractor](https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(int))(@Mp4Extractor.Flags int flags)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor#Mp4Extractor(androidx.media3.extractor.text.SubtitleParser.Factory,int)` instead

### Mp4Extractor

```
public Mp4Extractor(SubtitleParser.Factory subtitleParserFactory)
```

Creates a new extractor for unfragmented MP4 streams.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory` | The `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` for parsing subtitles during extraction. |

### Mp4Extractor

```
public Mp4Extractor(
    SubtitleParser.Factory subtitleParserFactory,
    @Mp4Extractor.Flags int flags
)
```

Creates a new extractor for unfragmented MP4 streams, using the specified flags to control the extractor's behavior.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory` | The `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` for parsing subtitles during extraction. |
| `@https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor.Flags int flags` | Flags that control the extractor's behavior. |

## Public methods

### getSampleTimestampsUs

```
public long[] getSampleTimestampsUs(int trackId)
```

Returns the list of sample timestamps of a `trackId`, in microseconds.

| Parameters |
|---|---|
| `int trackId` | The id of the track to get the sample timestamps. |

| Returns |
|---|---|
| `long[]` | The corresponding sample timestmaps of the track. |

### getSniffFailureDetails

```
public ImmutableList<SniffFailure> getSniffFailureDetails()
```

Returns additional details about the last call to `https://developer.android.com/reference/androidx/media3/extractor/Extractor#sniff(androidx.media3.extractor.ExtractorInput)`. The returned list may be empty if no additional details are available, or the last `https://developer.android.com/reference/androidx/media3/extractor/Extractor#sniff(androidx.media3.extractor.ExtractorInput)` call returned `
true`.

This only contains details that were discovered before `https://developer.android.com/reference/androidx/media3/extractor/Extractor#sniff(androidx.media3.extractor.ExtractorInput)` returned `
false`, it is not an exhaustive list of issues which, if resolved, would cause the file to be successfully sniffed.

### init

```
public void init(ExtractorOutput output)
```

Initializes the extractor with an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput`. Called at most once.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput output` | An `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput` to receive extracted data. |

### newFactory

```
public static ExtractorsFactory newFactory(SubtitleParser.Factory subtitleParserFactory)
```

Creates a factory for `https://developer.android.com/reference/androidx/media3/extractor/mp4/Mp4Extractor` instances with the provided `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory`.

### read

```
public int read(ExtractorInput input, PositionHolder seekPosition)
```

Extracts data read from a provided `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`. Must not be called before `https://developer.android.com/reference/androidx/media3/extractor/Extractor#init(androidx.media3.extractor.ExtractorOutput)`.

A single call to this method will block until some progress has been made, but will not block for longer than this. Hence each call will consume only a small amount of input data.

In the common case, `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_CONTINUE()` is returned to indicate that the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` passed to the next read is required to provide data continuing from the position in the stream reached by the returning call. If the extractor requires data to be provided from a different position, then that position is set in `seekPosition` and `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_SEEK()` is returned. If the extractor reached the end of the data provided by the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`, then `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_END_OF_INPUT()` is returned.

When this method throws an `https://developer.android.com/reference/java/io/IOException.html`, extraction may continue by providing an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` with an unchanged `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput#getPosition()` to a subsequent call to this method.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | The `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` from which data should be read. |
| `https://developer.android.com/reference/androidx/media3/extractor/PositionHolder seekPosition` | If `https://developer.android.com/reference/androidx/media3/extractor/Extractor#RESULT_SEEK()` is returned, this holder is updated to hold the position of the required data. |

| Returns |
|---|---|
| `int` | One of the `RESULT_` values defined in this interface. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from or parsing the input. |

### release

```
public void release()
```

Releases all kept resources.

### seek

```
public void seek(long position, long timeUs)
```

Notifies the extractor that a seek has occurred.

Following a call to this method, the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` passed to the next invocation of `https://developer.android.com/reference/androidx/media3/extractor/Extractor#read(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.PositionHolder)` is required to provide data starting from `
position` in the stream. Valid random access positions are the start of the stream and positions that can be obtained from any `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` passed to the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorOutput`.

| Parameters |
|---|---|
| `long position` | The byte offset in the stream from which data will be provided. |
| `long timeUs` | The seek time in microseconds. |

### sniff

```
public boolean sniff(ExtractorInput input)
```

Returns whether this extractor can extract samples from the `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput`, which must provide data from the start of the stream.

If `true` is returned, the `input`'s reading position may have been modified. Otherwise, only its peek position may have been modified.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | The `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` from which data should be peeked/read. |

| Returns |
|---|---|
| `boolean` | Whether this extractor can read the provided input. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input. |