mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add audio and video values from Format to TransformationResult.
PiperOrigin-RevId: 500789076
This commit is contained in:
parent
8ad26c0d8b
commit
8cac27a77c
3 changed files with 140 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.exceptio
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
@ -194,7 +195,10 @@ public class TransformationTestResult {
|
||||||
if (transformationResult.averageVideoBitrate != C.RATE_UNSET_INT) {
|
if (transformationResult.averageVideoBitrate != C.RATE_UNSET_INT) {
|
||||||
jsonObject.put("averageVideoBitrate", transformationResult.averageVideoBitrate);
|
jsonObject.put("averageVideoBitrate", transformationResult.averageVideoBitrate);
|
||||||
}
|
}
|
||||||
if (transformationResult.durationMs != C.LENGTH_UNSET) {
|
if (transformationResult.channelCount != C.LENGTH_UNSET) {
|
||||||
|
jsonObject.put("channelCount", transformationResult.channelCount);
|
||||||
|
}
|
||||||
|
if (transformationResult.durationMs != C.TIME_UNSET) {
|
||||||
jsonObject.put("durationMs", transformationResult.durationMs);
|
jsonObject.put("durationMs", transformationResult.durationMs);
|
||||||
}
|
}
|
||||||
if (elapsedTimeMs != C.TIME_UNSET) {
|
if (elapsedTimeMs != C.TIME_UNSET) {
|
||||||
|
|
@ -203,6 +207,15 @@ public class TransformationTestResult {
|
||||||
if (transformationResult.fileSizeBytes != C.LENGTH_UNSET) {
|
if (transformationResult.fileSizeBytes != C.LENGTH_UNSET) {
|
||||||
jsonObject.put("fileSizeBytes", transformationResult.fileSizeBytes);
|
jsonObject.put("fileSizeBytes", transformationResult.fileSizeBytes);
|
||||||
}
|
}
|
||||||
|
if (transformationResult.height != C.LENGTH_UNSET) {
|
||||||
|
jsonObject.put("height", transformationResult.height);
|
||||||
|
}
|
||||||
|
if (transformationResult.pcmEncoding != Format.NO_VALUE) {
|
||||||
|
jsonObject.put("pcmEncoding", transformationResult.pcmEncoding);
|
||||||
|
}
|
||||||
|
if (transformationResult.sampleRate != C.RATE_UNSET_INT) {
|
||||||
|
jsonObject.put("sampleRate", transformationResult.sampleRate);
|
||||||
|
}
|
||||||
if (ssim != TransformationTestResult.SSIM_UNSET) {
|
if (ssim != TransformationTestResult.SSIM_UNSET) {
|
||||||
jsonObject.put("ssim", ssim);
|
jsonObject.put("ssim", ssim);
|
||||||
}
|
}
|
||||||
|
|
@ -212,6 +225,9 @@ public class TransformationTestResult {
|
||||||
if (transformationResult.videoFrameCount > 0) {
|
if (transformationResult.videoFrameCount > 0) {
|
||||||
jsonObject.put("videoFrameCount", transformationResult.videoFrameCount);
|
jsonObject.put("videoFrameCount", transformationResult.videoFrameCount);
|
||||||
}
|
}
|
||||||
|
if (transformationResult.width != C.LENGTH_UNSET) {
|
||||||
|
jsonObject.put("width", transformationResult.width);
|
||||||
|
}
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,20 +19,25 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Information about the result of a transformation. */
|
/** Information about the result of a transformation. */
|
||||||
public final class TransformationResult {
|
public final class TransformationResult {
|
||||||
|
|
||||||
/** A builder for {@link TransformationResult} instances. */
|
/** A builder for {@link TransformationResult} instances. */
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private long durationMs;
|
private long durationMs;
|
||||||
private long fileSizeBytes;
|
private long fileSizeBytes;
|
||||||
private int averageAudioBitrate;
|
private int averageAudioBitrate;
|
||||||
|
private int channelCount;
|
||||||
|
private @C.PcmEncoding int pcmEncoding;
|
||||||
|
private int sampleRate;
|
||||||
@Nullable private String audioDecoderName;
|
@Nullable private String audioDecoderName;
|
||||||
@Nullable private String audioEncoderName;
|
@Nullable private String audioEncoderName;
|
||||||
private int averageVideoBitrate;
|
private int averageVideoBitrate;
|
||||||
|
private int height;
|
||||||
|
private int width;
|
||||||
private int videoFrameCount;
|
private int videoFrameCount;
|
||||||
@Nullable private String videoDecoderName;
|
@Nullable private String videoDecoderName;
|
||||||
@Nullable private String videoEncoderName;
|
@Nullable private String videoEncoderName;
|
||||||
|
|
@ -42,7 +47,12 @@ public final class TransformationResult {
|
||||||
durationMs = C.TIME_UNSET;
|
durationMs = C.TIME_UNSET;
|
||||||
fileSizeBytes = C.LENGTH_UNSET;
|
fileSizeBytes = C.LENGTH_UNSET;
|
||||||
averageAudioBitrate = C.RATE_UNSET_INT;
|
averageAudioBitrate = C.RATE_UNSET_INT;
|
||||||
|
channelCount = C.LENGTH_UNSET;
|
||||||
|
pcmEncoding = Format.NO_VALUE;
|
||||||
|
sampleRate = C.RATE_UNSET_INT;
|
||||||
averageVideoBitrate = C.RATE_UNSET_INT;
|
averageVideoBitrate = C.RATE_UNSET_INT;
|
||||||
|
height = C.LENGTH_UNSET;
|
||||||
|
width = C.LENGTH_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,6 +91,37 @@ public final class TransformationResult {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the channel count.
|
||||||
|
*
|
||||||
|
* <p>Must be positive or {@link C#LENGTH_UNSET}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setChannelCount(int channelCount) {
|
||||||
|
checkArgument(channelCount > 0 || channelCount == C.LENGTH_UNSET);
|
||||||
|
this.channelCount = channelCount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the {@link C.PcmEncoding}. */
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setPcmEncoding(@C.PcmEncoding int pcmEncoding) {
|
||||||
|
this.pcmEncoding = pcmEncoding;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the sample rate.
|
||||||
|
*
|
||||||
|
* <p>Must be positive or {@link C#RATE_UNSET_INT}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setSampleRate(int sampleRate) {
|
||||||
|
checkArgument(sampleRate > 0 || sampleRate == C.RATE_UNSET_INT);
|
||||||
|
this.sampleRate = sampleRate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the name of the audio decoder used. */
|
/** Sets the name of the audio decoder used. */
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public Builder setAudioDecoderName(@Nullable String audioDecoderName) {
|
public Builder setAudioDecoderName(@Nullable String audioDecoderName) {
|
||||||
|
|
@ -107,6 +148,30 @@ public final class TransformationResult {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the height.
|
||||||
|
*
|
||||||
|
* <p>Must be positive or {@link C#LENGTH_UNSET}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setHeight(int height) {
|
||||||
|
checkArgument(height > 0 || height == C.LENGTH_UNSET);
|
||||||
|
this.height = height;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the width.
|
||||||
|
*
|
||||||
|
* <p>Must be positive or {@link C#LENGTH_UNSET}.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setWidth(int width) {
|
||||||
|
checkArgument(width > 0 || width == C.LENGTH_UNSET);
|
||||||
|
this.width = width;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the number of video frames.
|
* Sets the number of video frames.
|
||||||
*
|
*
|
||||||
|
|
@ -146,9 +211,14 @@ public final class TransformationResult {
|
||||||
durationMs,
|
durationMs,
|
||||||
fileSizeBytes,
|
fileSizeBytes,
|
||||||
averageAudioBitrate,
|
averageAudioBitrate,
|
||||||
|
channelCount,
|
||||||
|
pcmEncoding,
|
||||||
|
sampleRate,
|
||||||
audioDecoderName,
|
audioDecoderName,
|
||||||
audioEncoderName,
|
audioEncoderName,
|
||||||
averageVideoBitrate,
|
averageVideoBitrate,
|
||||||
|
height,
|
||||||
|
width,
|
||||||
videoFrameCount,
|
videoFrameCount,
|
||||||
videoDecoderName,
|
videoDecoderName,
|
||||||
videoEncoderName,
|
videoEncoderName,
|
||||||
|
|
@ -165,6 +235,12 @@ public final class TransformationResult {
|
||||||
* The average bitrate of the audio track data, or {@link C#RATE_UNSET_INT} if unset or unknown.
|
* The average bitrate of the audio track data, or {@link C#RATE_UNSET_INT} if unset or unknown.
|
||||||
*/
|
*/
|
||||||
public final int averageAudioBitrate;
|
public final int averageAudioBitrate;
|
||||||
|
/** The channel count of the audio, or {@link C#LENGTH_UNSET} if unset or unknown. */
|
||||||
|
public final int channelCount;
|
||||||
|
/* The {@link C.PcmEncoding} of the audio, or {@link Format#NO_VALUE} if unset or unknown. */
|
||||||
|
public final @C.PcmEncoding int pcmEncoding;
|
||||||
|
/** The sample rate of the audio, or {@link C#RATE_UNSET_INT} if unset or unknown. */
|
||||||
|
public final int sampleRate;
|
||||||
/** The name of the audio decoder used, or {@code null} if none were used. */
|
/** The name of the audio decoder used, or {@code null} if none were used. */
|
||||||
@Nullable public final String audioDecoderName;
|
@Nullable public final String audioDecoderName;
|
||||||
/** The name of the audio encoder used, or {@code null} if none were used. */
|
/** The name of the audio encoder used, or {@code null} if none were used. */
|
||||||
|
|
@ -174,6 +250,10 @@ public final class TransformationResult {
|
||||||
* The average bitrate of the video track data, or {@link C#RATE_UNSET_INT} if unset or unknown.
|
* The average bitrate of the video track data, or {@link C#RATE_UNSET_INT} if unset or unknown.
|
||||||
*/
|
*/
|
||||||
public final int averageVideoBitrate;
|
public final int averageVideoBitrate;
|
||||||
|
/** The height of the video, or {@link C#LENGTH_UNSET} if unset or unknown. */
|
||||||
|
public final int height;
|
||||||
|
/** The width of the video, or {@link C#LENGTH_UNSET} if unset or unknown. */
|
||||||
|
public final int width;
|
||||||
/** The number of video frames. */
|
/** The number of video frames. */
|
||||||
public final int videoFrameCount;
|
public final int videoFrameCount;
|
||||||
/** The name of the video decoder used, or {@code null} if none were used. */
|
/** The name of the video decoder used, or {@code null} if none were used. */
|
||||||
|
|
@ -191,9 +271,14 @@ public final class TransformationResult {
|
||||||
long durationMs,
|
long durationMs,
|
||||||
long fileSizeBytes,
|
long fileSizeBytes,
|
||||||
int averageAudioBitrate,
|
int averageAudioBitrate,
|
||||||
|
int channelCount,
|
||||||
|
@C.PcmEncoding int pcmEncoding,
|
||||||
|
int sampleRate,
|
||||||
@Nullable String audioDecoderName,
|
@Nullable String audioDecoderName,
|
||||||
@Nullable String audioEncoderName,
|
@Nullable String audioEncoderName,
|
||||||
int averageVideoBitrate,
|
int averageVideoBitrate,
|
||||||
|
int height,
|
||||||
|
int width,
|
||||||
int videoFrameCount,
|
int videoFrameCount,
|
||||||
@Nullable String videoDecoderName,
|
@Nullable String videoDecoderName,
|
||||||
@Nullable String videoEncoderName,
|
@Nullable String videoEncoderName,
|
||||||
|
|
@ -201,9 +286,14 @@ public final class TransformationResult {
|
||||||
this.durationMs = durationMs;
|
this.durationMs = durationMs;
|
||||||
this.fileSizeBytes = fileSizeBytes;
|
this.fileSizeBytes = fileSizeBytes;
|
||||||
this.averageAudioBitrate = averageAudioBitrate;
|
this.averageAudioBitrate = averageAudioBitrate;
|
||||||
|
this.channelCount = channelCount;
|
||||||
|
this.pcmEncoding = pcmEncoding;
|
||||||
|
this.sampleRate = sampleRate;
|
||||||
this.audioDecoderName = audioDecoderName;
|
this.audioDecoderName = audioDecoderName;
|
||||||
this.audioEncoderName = audioEncoderName;
|
this.audioEncoderName = audioEncoderName;
|
||||||
this.averageVideoBitrate = averageVideoBitrate;
|
this.averageVideoBitrate = averageVideoBitrate;
|
||||||
|
this.height = height;
|
||||||
|
this.width = width;
|
||||||
this.videoFrameCount = videoFrameCount;
|
this.videoFrameCount = videoFrameCount;
|
||||||
this.videoDecoderName = videoDecoderName;
|
this.videoDecoderName = videoDecoderName;
|
||||||
this.videoEncoderName = videoEncoderName;
|
this.videoEncoderName = videoEncoderName;
|
||||||
|
|
@ -215,9 +305,14 @@ public final class TransformationResult {
|
||||||
.setDurationMs(durationMs)
|
.setDurationMs(durationMs)
|
||||||
.setFileSizeBytes(fileSizeBytes)
|
.setFileSizeBytes(fileSizeBytes)
|
||||||
.setAverageAudioBitrate(averageAudioBitrate)
|
.setAverageAudioBitrate(averageAudioBitrate)
|
||||||
|
.setChannelCount(channelCount)
|
||||||
|
.setPcmEncoding(pcmEncoding)
|
||||||
|
.setSampleRate(sampleRate)
|
||||||
.setAudioDecoderName(audioDecoderName)
|
.setAudioDecoderName(audioDecoderName)
|
||||||
.setAudioEncoderName(audioEncoderName)
|
.setAudioEncoderName(audioEncoderName)
|
||||||
.setAverageVideoBitrate(averageVideoBitrate)
|
.setAverageVideoBitrate(averageVideoBitrate)
|
||||||
|
.setHeight(height)
|
||||||
|
.setWidth(width)
|
||||||
.setVideoFrameCount(videoFrameCount)
|
.setVideoFrameCount(videoFrameCount)
|
||||||
.setVideoDecoderName(videoDecoderName)
|
.setVideoDecoderName(videoDecoderName)
|
||||||
.setVideoEncoderName(videoEncoderName)
|
.setVideoEncoderName(videoEncoderName)
|
||||||
|
|
@ -236,9 +331,14 @@ public final class TransformationResult {
|
||||||
return durationMs == result.durationMs
|
return durationMs == result.durationMs
|
||||||
&& fileSizeBytes == result.fileSizeBytes
|
&& fileSizeBytes == result.fileSizeBytes
|
||||||
&& averageAudioBitrate == result.averageAudioBitrate
|
&& averageAudioBitrate == result.averageAudioBitrate
|
||||||
|
&& channelCount == result.channelCount
|
||||||
|
&& pcmEncoding == result.pcmEncoding
|
||||||
|
&& sampleRate == result.sampleRate
|
||||||
&& Objects.equals(audioDecoderName, result.audioDecoderName)
|
&& Objects.equals(audioDecoderName, result.audioDecoderName)
|
||||||
&& Objects.equals(audioEncoderName, result.audioEncoderName)
|
&& Objects.equals(audioEncoderName, result.audioEncoderName)
|
||||||
&& averageVideoBitrate == result.averageVideoBitrate
|
&& averageVideoBitrate == result.averageVideoBitrate
|
||||||
|
&& height == result.height
|
||||||
|
&& width == result.width
|
||||||
&& videoFrameCount == result.videoFrameCount
|
&& videoFrameCount == result.videoFrameCount
|
||||||
&& Objects.equals(videoDecoderName, result.videoDecoderName)
|
&& Objects.equals(videoDecoderName, result.videoDecoderName)
|
||||||
&& Objects.equals(videoEncoderName, result.videoEncoderName)
|
&& Objects.equals(videoEncoderName, result.videoEncoderName)
|
||||||
|
|
@ -250,9 +350,14 @@ public final class TransformationResult {
|
||||||
int result = (int) durationMs;
|
int result = (int) durationMs;
|
||||||
result = 31 * result + (int) fileSizeBytes;
|
result = 31 * result + (int) fileSizeBytes;
|
||||||
result = 31 * result + averageAudioBitrate;
|
result = 31 * result + averageAudioBitrate;
|
||||||
|
result = 31 * result + channelCount;
|
||||||
|
result = 31 * result + pcmEncoding;
|
||||||
|
result = 31 * result + sampleRate;
|
||||||
result = 31 * result + Objects.hashCode(audioDecoderName);
|
result = 31 * result + Objects.hashCode(audioDecoderName);
|
||||||
result = 31 * result + Objects.hashCode(audioEncoderName);
|
result = 31 * result + Objects.hashCode(audioEncoderName);
|
||||||
result = 31 * result + averageVideoBitrate;
|
result = 31 * result + averageVideoBitrate;
|
||||||
|
result = 31 * result + height;
|
||||||
|
result = 31 * result + width;
|
||||||
result = 31 * result + videoFrameCount;
|
result = 31 * result + videoFrameCount;
|
||||||
result = 31 * result + Objects.hashCode(videoDecoderName);
|
result = 31 * result + Objects.hashCode(videoDecoderName);
|
||||||
result = 31 * result + Objects.hashCode(videoEncoderName);
|
result = 31 * result + Objects.hashCode(videoEncoderName);
|
||||||
|
|
|
||||||
|
|
@ -468,11 +468,25 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
public void onTrackEnded(
|
public void onTrackEnded(
|
||||||
@C.TrackType int trackType, Format format, int averageBitrate, int sampleCount) {
|
@C.TrackType int trackType, Format format, int averageBitrate, int sampleCount) {
|
||||||
if (trackType == C.TRACK_TYPE_AUDIO) {
|
if (trackType == C.TRACK_TYPE_AUDIO) {
|
||||||
transformationResultBuilder.setAverageAudioBitrate(averageBitrate);
|
transformationResultBuilder
|
||||||
|
.setAverageAudioBitrate(averageBitrate)
|
||||||
|
.setPcmEncoding(format.pcmEncoding);
|
||||||
|
if (format.channelCount != Format.NO_VALUE) {
|
||||||
|
transformationResultBuilder.setChannelCount(format.channelCount);
|
||||||
|
}
|
||||||
|
if (format.sampleRate != Format.NO_VALUE) {
|
||||||
|
transformationResultBuilder.setSampleRate(format.sampleRate);
|
||||||
|
}
|
||||||
} else if (trackType == C.TRACK_TYPE_VIDEO) {
|
} else if (trackType == C.TRACK_TYPE_VIDEO) {
|
||||||
transformationResultBuilder
|
transformationResultBuilder
|
||||||
.setVideoFrameCount(sampleCount)
|
.setAverageVideoBitrate(averageBitrate)
|
||||||
.setAverageVideoBitrate(averageBitrate);
|
.setVideoFrameCount(sampleCount);
|
||||||
|
if (format.height != Format.NO_VALUE) {
|
||||||
|
transformationResultBuilder.setHeight(format.height);
|
||||||
|
}
|
||||||
|
if (format.width != Format.NO_VALUE) {
|
||||||
|
transformationResultBuilder.setWidth(format.width);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue