Add file size to TransformationResult at the end of a Transformation.
Tested: * Manually using both path and file descriptor. PiperOrigin-RevId: 475860978
This commit is contained in:
parent
f00e43cf81
commit
9ec4e1340a
@ -66,6 +66,7 @@ import androidx.media3.extractor.DefaultExtractorsFactory;
|
|||||||
import androidx.media3.extractor.mp4.Mp4Extractor;
|
import androidx.media3.extractor.mp4.Mp4Extractor;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
@ -593,6 +594,8 @@ public final class Transformer {
|
|||||||
|
|
||||||
@Nullable private MuxerWrapper muxerWrapper;
|
@Nullable private MuxerWrapper muxerWrapper;
|
||||||
@Nullable private ExoPlayer player;
|
@Nullable private ExoPlayer player;
|
||||||
|
@Nullable private String outputPath;
|
||||||
|
@Nullable private ParcelFileDescriptor outputParcelFileDescriptor;
|
||||||
private @ProgressState int progressState;
|
private @ProgressState int progressState;
|
||||||
private boolean isCancelling;
|
private boolean isCancelling;
|
||||||
|
|
||||||
@ -705,6 +708,8 @@ public final class Transformer {
|
|||||||
throw new UnsupportedEncodingException(
|
throw new UnsupportedEncodingException(
|
||||||
"Clipping is not supported when slow motion flattening is requested");
|
"Clipping is not supported when slow motion flattening is requested");
|
||||||
}
|
}
|
||||||
|
this.outputPath = path;
|
||||||
|
this.outputParcelFileDescriptor = null;
|
||||||
startTransformation(mediaItem, muxerFactory.create(path, containerMimeType));
|
startTransformation(mediaItem, muxerFactory.create(path, containerMimeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,6 +738,8 @@ public final class Transformer {
|
|||||||
@RequiresApi(26)
|
@RequiresApi(26)
|
||||||
public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
|
public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
this.outputParcelFileDescriptor = parcelFileDescriptor;
|
||||||
|
this.outputPath = null;
|
||||||
startTransformation(mediaItem, muxerFactory.create(parcelFileDescriptor, containerMimeType));
|
startTransformation(mediaItem, muxerFactory.create(parcelFileDescriptor, containerMimeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -876,6 +883,26 @@ public final class Transformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current size in bytes of the current/latest output file, or {@link C#LENGTH_UNSET}
|
||||||
|
* if unavailable.
|
||||||
|
*/
|
||||||
|
private long getCurrentOutputFileCurrentSizeBytes() {
|
||||||
|
long fileSize = C.LENGTH_UNSET;
|
||||||
|
|
||||||
|
if (outputPath != null) {
|
||||||
|
fileSize = new File(outputPath).length();
|
||||||
|
} else if (outputParcelFileDescriptor != null) {
|
||||||
|
fileSize = outputParcelFileDescriptor.getStatSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileSize <= 0) {
|
||||||
|
fileSize = C.LENGTH_UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
private static final class TransformerRenderersFactory implements RenderersFactory {
|
private static final class TransformerRenderersFactory implements RenderersFactory {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@ -1064,6 +1091,7 @@ public final class Transformer {
|
|||||||
.setAverageAudioBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_AUDIO))
|
.setAverageAudioBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_AUDIO))
|
||||||
.setAverageVideoBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_VIDEO))
|
.setAverageVideoBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_VIDEO))
|
||||||
.setVideoFrameCount(muxerWrapper.getTrackSampleCount(C.TRACK_TYPE_VIDEO))
|
.setVideoFrameCount(muxerWrapper.getTrackSampleCount(C.TRACK_TYPE_VIDEO))
|
||||||
|
.setFileSizeBytes(getCurrentOutputFileCurrentSizeBytes())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
listeners.queueEvent(
|
listeners.queueEvent(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user