mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Take fragment duration in Ms instead of Us
PiperOrigin-RevId: 621144165
This commit is contained in:
parent
136baa148f
commit
308c4c4fbf
3 changed files with 22 additions and 21 deletions
|
|
@ -59,25 +59,26 @@ import java.nio.ByteBuffer;
|
|||
*/
|
||||
@UnstableApi
|
||||
public final class FragmentedMp4Muxer implements Muxer {
|
||||
private static final int DEFAULT_FRAGMENT_DURATION_US = 2_000_000;
|
||||
/** The default fragment duration. */
|
||||
public static final long DEFAULT_FRAGMENT_DURATION_MS = 2_000;
|
||||
|
||||
private final FragmentedMp4Writer fragmentedMp4Writer;
|
||||
private final MetadataCollector metadataCollector;
|
||||
|
||||
/** Creates an instance with default fragment duration. */
|
||||
/** Creates an instance with {@link #DEFAULT_FRAGMENT_DURATION_MS}. */
|
||||
public FragmentedMp4Muxer(FileOutputStream fileOutputStream) {
|
||||
this(fileOutputStream, DEFAULT_FRAGMENT_DURATION_US);
|
||||
this(fileOutputStream, DEFAULT_FRAGMENT_DURATION_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
*
|
||||
* @param fileOutputStream The {@link FileOutputStream} to write the media data to.
|
||||
* @param fragmentDurationUs The fragment duration (in microseconds). The muxer will attempt to
|
||||
* @param fragmentDurationMs The fragment duration (in milliseconds). The muxer will attempt to
|
||||
* create fragments of the given duration but the actual duration might be greater depending
|
||||
* upon the frequency of sync samples.
|
||||
*/
|
||||
public FragmentedMp4Muxer(FileOutputStream fileOutputStream, int fragmentDurationUs) {
|
||||
public FragmentedMp4Muxer(FileOutputStream fileOutputStream, long fragmentDurationMs) {
|
||||
checkNotNull(fileOutputStream);
|
||||
metadataCollector = new MetadataCollector();
|
||||
Mp4MoovStructure moovStructure =
|
||||
|
|
@ -85,7 +86,7 @@ public final class FragmentedMp4Muxer implements Muxer {
|
|||
metadataCollector, Mp4Muxer.LAST_FRAME_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION);
|
||||
fragmentedMp4Writer =
|
||||
new FragmentedMp4Writer(
|
||||
fileOutputStream, moovStructure, AnnexBToAvccConverter.DEFAULT, fragmentDurationUs);
|
||||
fileOutputStream, moovStructure, AnnexBToAvccConverter.DEFAULT, fragmentDurationMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
private final Mp4MoovStructure moovGenerator;
|
||||
private final AnnexBToAvccConverter annexBToAvccConverter;
|
||||
private final List<Track> tracks;
|
||||
private final int fragmentDurationUs;
|
||||
private final long fragmentDurationUs;
|
||||
|
||||
private @MonotonicNonNull Track videoTrack;
|
||||
private int currentFragmentSequenceNumber;
|
||||
|
|
@ -77,13 +77,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
FileOutputStream outputStream,
|
||||
Mp4MoovStructure moovGenerator,
|
||||
AnnexBToAvccConverter annexBToAvccConverter,
|
||||
int fragmentDurationUs) {
|
||||
long fragmentDurationMs) {
|
||||
this.outputStream = outputStream;
|
||||
this.output = outputStream.getChannel();
|
||||
this.moovGenerator = moovGenerator;
|
||||
this.annexBToAvccConverter = annexBToAvccConverter;
|
||||
tracks = new ArrayList<>();
|
||||
this.fragmentDurationUs = fragmentDurationUs;
|
||||
this.fragmentDurationUs = fragmentDurationMs * 1_000;
|
||||
minInputPresentationTimeUs = Long.MAX_VALUE;
|
||||
currentFragmentSequenceNumber = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ public final class InAppMuxer implements Muxer {
|
|||
public static final class Builder {
|
||||
private @Nullable MetadataProvider metadataProvider;
|
||||
private boolean outputFragmentedMp4;
|
||||
private int fragmentDurationUs;
|
||||
private long fragmentDurationMs;
|
||||
|
||||
/** Creates a {@link Builder} instance with default values. */
|
||||
public Builder() {
|
||||
fragmentDurationUs = C.LENGTH_UNSET;
|
||||
fragmentDurationMs = C.TIME_UNSET;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,18 +92,18 @@ public final class InAppMuxer implements Muxer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the fragment duration if the output file is {@link #setOutputFragmentedMp4(boolean)
|
||||
* fragmented}.
|
||||
* Sets the fragment duration (in milliseconds) if the output file is {@link
|
||||
* #setOutputFragmentedMp4(boolean) fragmented}.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Builder setFragmentDurationUs(int fragmentDurationUs) {
|
||||
this.fragmentDurationUs = fragmentDurationUs;
|
||||
public Builder setFragmentDurationMs(long fragmentDurationMs) {
|
||||
this.fragmentDurationMs = fragmentDurationMs;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Builds a {@link Factory} instance. */
|
||||
public Factory build() {
|
||||
return new Factory(metadataProvider, outputFragmentedMp4, fragmentDurationUs);
|
||||
return new Factory(metadataProvider, outputFragmentedMp4, fragmentDurationMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,15 +117,15 @@ public final class InAppMuxer implements Muxer {
|
|||
|
||||
private final @Nullable MetadataProvider metadataProvider;
|
||||
private final boolean outputFragmentedMp4;
|
||||
private final int fragmentDurationUs;
|
||||
private final long fragmentDurationMs;
|
||||
|
||||
private Factory(
|
||||
@Nullable MetadataProvider metadataProvider,
|
||||
boolean outputFragmentedMp4,
|
||||
int fragmentDurationUs) {
|
||||
long fragmentDurationMs) {
|
||||
this.metadataProvider = metadataProvider;
|
||||
this.outputFragmentedMp4 = outputFragmentedMp4;
|
||||
this.fragmentDurationUs = fragmentDurationUs;
|
||||
this.fragmentDurationMs = fragmentDurationMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -139,8 +139,8 @@ public final class InAppMuxer implements Muxer {
|
|||
|
||||
androidx.media3.muxer.Muxer muxer =
|
||||
outputFragmentedMp4
|
||||
? fragmentDurationUs != C.LENGTH_UNSET
|
||||
? new FragmentedMp4Muxer(outputStream, fragmentDurationUs)
|
||||
? fragmentDurationMs != C.TIME_UNSET
|
||||
? new FragmentedMp4Muxer(outputStream, fragmentDurationMs)
|
||||
: new FragmentedMp4Muxer(outputStream)
|
||||
: new Mp4Muxer.Builder(outputStream).build();
|
||||
return new InAppMuxer(muxer, metadataProvider);
|
||||
|
|
|
|||
Loading…
Reference in a new issue