mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add EditablevideoParameter class
The parameter class will allow addition of more parameters (link shouldInterleaveSamples), which are specific to editable video file format. PiperOrigin-RevId: 662923844
This commit is contained in:
parent
74cfd2ad79
commit
dbc9f5e0d1
@ -105,6 +105,8 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final class Mp4Muxer implements Muxer {
|
public final class Mp4Muxer implements Muxer {
|
||||||
|
/** Parameters for {@link #FILE_FORMAT_EDITABLE_VIDEO}. */
|
||||||
|
public static final class EditableVideoParameters {
|
||||||
/** Provides temporary cache files to be used by the muxer. */
|
/** Provides temporary cache files to be used by the muxer. */
|
||||||
public interface CacheFileProvider {
|
public interface CacheFileProvider {
|
||||||
|
|
||||||
@ -119,6 +121,18 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
String getCacheFilePath();
|
String getCacheFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final CacheFileProvider cacheFileProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param cacheFileProvider A {@link CacheFileProvider}.
|
||||||
|
*/
|
||||||
|
public EditableVideoParameters(CacheFileProvider cacheFileProvider) {
|
||||||
|
this.cacheFileProvider = cacheFileProvider;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Behavior for the last sample duration. */
|
/** Behavior for the last sample duration. */
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@ -167,7 +181,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
private boolean sampleCopyEnabled;
|
private boolean sampleCopyEnabled;
|
||||||
private boolean attemptStreamableOutputEnabled;
|
private boolean attemptStreamableOutputEnabled;
|
||||||
private @FileFormat int outputFileFormat;
|
private @FileFormat int outputFileFormat;
|
||||||
@Nullable private CacheFileProvider cacheFileProvider;
|
@Nullable private EditableVideoParameters editableVideoParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Builder} instance with default values.
|
* Creates a {@link Builder} instance with default values.
|
||||||
@ -243,8 +257,8 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
*
|
*
|
||||||
* <p>The default value is {@link #FILE_FORMAT_DEFAULT}.
|
* <p>The default value is {@link #FILE_FORMAT_DEFAULT}.
|
||||||
*
|
*
|
||||||
* <p>For {@link #FILE_FORMAT_EDITABLE_VIDEO}, a {@link CacheFileProvider} must also be
|
* <p>For {@link #FILE_FORMAT_EDITABLE_VIDEO}, {@link EditableVideoParameters} must also be
|
||||||
* {@linkplain #setCacheFileProvider(CacheFileProvider) set}.
|
* {@linkplain #setEditableVideoParameters(EditableVideoParameters)} set}.
|
||||||
*/
|
*/
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Mp4Muxer.Builder setOutputFileFormat(@FileFormat int fileFormat) {
|
public Mp4Muxer.Builder setOutputFileFormat(@FileFormat int fileFormat) {
|
||||||
@ -252,18 +266,21 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the {@link CacheFileProvider}. */
|
/** Sets the {@link EditableVideoParameters}. */
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Mp4Muxer.Builder setCacheFileProvider(CacheFileProvider cacheFileProvider) {
|
public Mp4Muxer.Builder setEditableVideoParameters(
|
||||||
this.cacheFileProvider = cacheFileProvider;
|
EditableVideoParameters editableVideoParameters) {
|
||||||
|
this.editableVideoParameters = editableVideoParameters;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builds an {@link Mp4Muxer} instance. */
|
/** Builds an {@link Mp4Muxer} instance. */
|
||||||
public Mp4Muxer build() {
|
public Mp4Muxer build() {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
outputFileFormat != FILE_FORMAT_EDITABLE_VIDEO || cacheFileProvider != null,
|
outputFileFormat == FILE_FORMAT_EDITABLE_VIDEO
|
||||||
"A CacheFileProvider must be set for FILE_FORMAT_EDITABLE_VIDEO");
|
? editableVideoParameters != null
|
||||||
|
: editableVideoParameters == null,
|
||||||
|
"EditablevideoParameters must be set for FILE_FORMAT_EDITABLE_VIDEO");
|
||||||
return new Mp4Muxer(
|
return new Mp4Muxer(
|
||||||
outputStream,
|
outputStream,
|
||||||
lastFrameDurationBehavior,
|
lastFrameDurationBehavior,
|
||||||
@ -271,7 +288,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
sampleCopyEnabled,
|
sampleCopyEnabled,
|
||||||
attemptStreamableOutputEnabled,
|
attemptStreamableOutputEnabled,
|
||||||
outputFileFormat,
|
outputFileFormat,
|
||||||
cacheFileProvider);
|
editableVideoParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +301,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
private final boolean sampleCopyEnabled;
|
private final boolean sampleCopyEnabled;
|
||||||
private final boolean attemptStreamableOutputEnabled;
|
private final boolean attemptStreamableOutputEnabled;
|
||||||
private final @FileFormat int outputFileFormat;
|
private final @FileFormat int outputFileFormat;
|
||||||
@Nullable private final CacheFileProvider cacheFileProvider;
|
@Nullable private final EditableVideoParameters editableVideoParameters;
|
||||||
private final MetadataCollector metadataCollector;
|
private final MetadataCollector metadataCollector;
|
||||||
private final Mp4Writer mp4Writer;
|
private final Mp4Writer mp4Writer;
|
||||||
private final List<Track> editableVideoTracks;
|
private final List<Track> editableVideoTracks;
|
||||||
@ -301,7 +318,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
boolean sampleCopyEnabled,
|
boolean sampleCopyEnabled,
|
||||||
boolean attemptStreamableOutputEnabled,
|
boolean attemptStreamableOutputEnabled,
|
||||||
@FileFormat int outputFileFormat,
|
@FileFormat int outputFileFormat,
|
||||||
@Nullable CacheFileProvider cacheFileProvider) {
|
@Nullable EditableVideoParameters editableVideoParameters) {
|
||||||
this.outputStream = outputStream;
|
this.outputStream = outputStream;
|
||||||
outputChannel = outputStream.getChannel();
|
outputChannel = outputStream.getChannel();
|
||||||
this.lastFrameDurationBehavior = lastFrameDurationBehavior;
|
this.lastFrameDurationBehavior = lastFrameDurationBehavior;
|
||||||
@ -309,7 +326,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
this.sampleCopyEnabled = sampleCopyEnabled;
|
this.sampleCopyEnabled = sampleCopyEnabled;
|
||||||
this.attemptStreamableOutputEnabled = attemptStreamableOutputEnabled;
|
this.attemptStreamableOutputEnabled = attemptStreamableOutputEnabled;
|
||||||
this.outputFileFormat = outputFileFormat;
|
this.outputFileFormat = outputFileFormat;
|
||||||
this.cacheFileProvider = cacheFileProvider;
|
this.editableVideoParameters = editableVideoParameters;
|
||||||
metadataCollector = new MetadataCollector();
|
metadataCollector = new MetadataCollector();
|
||||||
mp4Writer =
|
mp4Writer =
|
||||||
new Mp4Writer(
|
new Mp4Writer(
|
||||||
@ -467,7 +484,7 @@ public final class Mp4Muxer implements Muxer {
|
|||||||
@EnsuresNonNull({"editableVideoMp4Writer"})
|
@EnsuresNonNull({"editableVideoMp4Writer"})
|
||||||
private void ensureSetupForEditableVideoTracks() throws FileNotFoundException {
|
private void ensureSetupForEditableVideoTracks() throws FileNotFoundException {
|
||||||
if (editableVideoMp4Writer == null) {
|
if (editableVideoMp4Writer == null) {
|
||||||
cacheFilePath = checkNotNull(cacheFileProvider).getCacheFilePath();
|
cacheFilePath = checkNotNull(editableVideoParameters).cacheFileProvider.getCacheFilePath();
|
||||||
cacheFileOutputStream = new FileOutputStream(cacheFilePath);
|
cacheFileOutputStream = new FileOutputStream(cacheFilePath);
|
||||||
editableVideoMetadataCollector = new MetadataCollector();
|
editableVideoMetadataCollector = new MetadataCollector();
|
||||||
editableVideoMp4Writer =
|
editableVideoMp4Writer =
|
||||||
|
@ -387,7 +387,7 @@ public class Mp4MuxerEndToEndTest {
|
|||||||
Mp4Muxer muxer =
|
Mp4Muxer muxer =
|
||||||
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
||||||
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
||||||
.setCacheFileProvider(() -> cacheFilePath)
|
.setEditableVideoParameters(new Mp4Muxer.EditableVideoParameters(() -> cacheFilePath))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -430,11 +430,7 @@ public class Mp4MuxerEndToEndTest {
|
|||||||
public void writeMp4File_withFileFormatDefaultAndEditableVideoTracks_doesNotWriteEdvdBox()
|
public void writeMp4File_withFileFormatDefaultAndEditableVideoTracks_doesNotWriteEdvdBox()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
String outputFilePath = temporaryFolder.newFile().getPath();
|
String outputFilePath = temporaryFolder.newFile().getPath();
|
||||||
String cacheFilePath = temporaryFolder.newFile().getPath();
|
Mp4Muxer muxer = new Mp4Muxer.Builder(new FileOutputStream(outputFilePath)).build();
|
||||||
Mp4Muxer muxer =
|
|
||||||
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
|
||||||
.setCacheFileProvider(() -> cacheFilePath)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
muxer.addMetadataEntry(
|
muxer.addMetadataEntry(
|
||||||
@ -481,7 +477,7 @@ public class Mp4MuxerEndToEndTest {
|
|||||||
Mp4Muxer muxer =
|
Mp4Muxer muxer =
|
||||||
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
||||||
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
||||||
.setCacheFileProvider(() -> cacheFilePath)
|
.setEditableVideoParameters(new Mp4Muxer.EditableVideoParameters(() -> cacheFilePath))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -530,7 +526,7 @@ public class Mp4MuxerEndToEndTest {
|
|||||||
Mp4Muxer muxer =
|
Mp4Muxer muxer =
|
||||||
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
new Mp4Muxer.Builder(new FileOutputStream(outputFilePath))
|
||||||
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
.setOutputFileFormat(Mp4Muxer.FILE_FORMAT_EDITABLE_VIDEO)
|
||||||
.setCacheFileProvider(() -> cacheFilePath)
|
.setEditableVideoParameters(new Mp4Muxer.EditableVideoParameters(() -> cacheFilePath))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user